Caffe2 - C++ API
A deep learning, cross platform ML framework
GLImageAllocator.cc
1 
2 #include "GLImageAllocator.h"
3 #include "arm_neon_support.h"
4 
5 template <class T>
7  int num_images, int width, int height, int channels, int tile_x, int tile_y, bool is_output) {
8  GLImageVector<T>* images =
9  new GLImageVector<T>(num_images, width, height, channels, tile_x, tile_y);
10  for (int i = 0; i < num_images; i++) {
11  images->push_back(
12  new GLImage<T>(width, height, channels, tile_x, tile_y, [&](int slice) -> const GLTexture* {
13  bool usePadding = is_output;
14  return new GLPlainTexture(type, nullptr, width * tile_x, height * tile_y, usePadding);
15  }));
16  }
17  return images;
18 }
19 
20 template <class T>
22  int num_images,
23  int width,
24  int height,
25  int channels,
26  int tile_x,
27  int tile_y,
28  std::function<const GLTexture*(const int width, const int height)> textureAllocator) {
29  GLImageVector<T>* images =
30  new GLImageVector<T>(num_images, width, height, channels, tile_x, tile_y);
31  for (int i = 0; i < num_images; i++) {
32  images->push_back(
33  new GLImage<T>(width, height, channels, tile_x, tile_y, [&](int slice) -> const GLTexture* {
34  return textureAllocator(width, height);
35  }));
36  }
37  return images;
38 }
39 
40 template <class T>
42  int num_images,
43  int width,
44  int height,
45  int channels,
46  int tile_x,
47  int tile_y) {
48  GLImageVector<T>* images =
49  new GLImageVector<T>(num_images, width, height, channels, tile_x, tile_y);
50  for (int i = 0; i < num_images; i++) {
51  images->push_back(
52  new GLImage<T>(width, height, channels, tile_x, tile_y, [&](int slice) -> const GLTexture* {
53  return new GLPlainTexture(
54  GLImageAllocator<T>::type, textureID, width * tile_x, height * tile_y);
55  }));
56  }
57  return images;
58 }
59 
60 template <>
61 const GLTexture::Type& GLImageAllocator<float16_t>::type = GLTexture::FP16;
62 template <>
63 const GLTexture::Type& GLImageAllocator<uint8_t>::type = GLTexture::UI8;
64 
65 template class GLImageAllocator<float16_t>;
66 template class GLImageAllocator<uint8_t>;