5 #include "caffe2/core/logging.h" 20 const int texture_width;
21 const int texture_height;
24 const std::vector<const GLTexture*> textures;
26 constexpr
static int slice_channels = 4;
28 static constexpr
int channels_to_slices(
int channels,
int tile_x,
int tile_y) {
29 return ((channels + slice_channels - 1) / slice_channels + tile_x * tile_y - 1) /
33 static const std::vector<const GLTexture*> allocate_textures(
34 int slices, std::function<
const GLTexture*(
int slice)> texture_loader) {
35 std::vector<const GLTexture*> textures;
36 for (
int i = 0; i < slices; i++) {
37 textures.push_back(texture_loader(i));
47 std::function<
const GLTexture*(
int slice)> texture_loader)
54 texture_width(_width * _tile_x),
55 texture_height(_height * _tile_y),
56 slices(channels_to_slices(_channels, _tile_x, _tile_y)),
57 textures(allocate_textures(slices, texture_loader)) {
59 slices, ((channels + 3) / 4 + tile_x * tile_y - 1) / (tile_x * tile_y));
68 std::function<
const GLTexture*(
int slice)> texture_loader)
75 texture_width(_width * _tile_x),
76 texture_height(_height * _tile_y),
77 slices(channels_to_slices(_channels, _tile_x, _tile_y)),
78 textures(allocate_textures(slices, texture_loader)) {
79 CAFFE_ENFORCE_EQ(slices * tile_x * tile_y, (channels + 3) / 4);
94 gl_log(GL_VERBOSE,
"deleting GLImage\n");
95 for (
auto&& texture : textures) {
101 template <
typename T>
104 std::vector<GLImage<T>*> images_;
114 CAFFE_ENFORCE_LT(index, num_images_,
"Out of bounds when accessing GLImageVector");
115 return images_[index];
119 CAFFE_ENFORCE_EQ(image->channels, channels_);
120 CAFFE_ENFORCE_EQ(image->width, width_);
121 CAFFE_ENFORCE_EQ(image->height, height_);
122 CAFFE_ENFORCE_EQ(image->tile_x, tile_x_);
123 CAFFE_ENFORCE_EQ(image->tile_y, tile_y_);
124 images_.push_back(image);
125 CAFFE_ENFORCE_LE(images_.size(), num_images_);
128 int size()
const {
return images_.size(); }
129 int channels()
const {
return channels_; }
130 int width()
const {
return width_; }
131 int height()
const {
return height_; }
132 int tile_x()
const {
return tile_x_; }
133 int tile_y()
const {
return tile_y_; }
134 int slices()
const {
return size() > 0 ? images_[0]->slices : 0; }
136 GLImageVector(
int num_images,
int width,
int height,
int channels,
int tile_x = 1,
int tile_y = 1)
137 : num_images_(num_images),
147 for (
int i = 0; i < images_.size(); i++) {