2 #include "caffe2/core/common.h" 3 #include "caffe2/core/operator.h" 4 #include "caffe2/core/timer.h" 6 #include "../core/DataTransfer.h" 7 #include "../core/GLContext.h" 8 #include "../core/GLImage.h" 9 #include "../core/GLPlainTexture.h" 10 #include "../core/ImageAllocator.h" 21 bool RunOnDevice()
override {
24 const int num_images = X.
dim32(0);
25 const int input_channels = X.
dim32(1);
26 const int input_width = X.
dim32(3);
27 const int input_height = X.
dim32(2);
28 const int input_size = input_width * input_height;
31 GLContext::getGLContext()->set_context();
33 const float* input = X.template data<float>();
35 int tile_x = GetSingleArgument<int>(
"tile_x", 1);
36 int tile_y = GetSingleArgument<int>(
"tile_y", 1);
51 if (output_image->tile_x() > 1 || output_image->tile_y() > 1) {
52 LOG(INFO) <<
"CopyToOpenGLOp tiling: " << output_image->tile_x() <<
":" 53 << output_image->tile_y();
56 Outputs()[0]->Reset(output_image);
58 for (
int i = 0; i < num_images; i++) {
59 const auto textures = (*output_image)[i]->textures;
60 for (
int slice = 0; slice < textures.size(); slice++) {
63 textures[slice]->map_load([&](
void* buffer,
69 for (
int y = 0; y < tile_y; y++) {
70 for (
int x = 0; x < tile_x; x++) {
71 const int tiles = slice * tile_x * tile_y + y * tile_x + x;
72 const int slice_channels = std::min(4, input_channels - 4 * tiles);
74 (float16_t*)buffer + 4 * (y * input_height * stride + x * input_width),
75 &input[i * input_channels * input_size + 4 * tiles * input_size],
92 OPERATOR_SCHEMA(CopyToOpenGL).NumInputs(1).NumOutputs(1).AllowInplace({{0, 0}});
100 bool RunOnDevice()
override {
103 const int num_images = X.size();
104 const int input_channels = X.channels();
105 const int input_width = X.width();
106 const int input_height = X.height();
109 Y->
Resize(num_images, input_channels, input_height, input_width);
110 const int output_width = input_width;
111 const int output_height = input_height;
112 const int output_size = input_width * input_height;
116 const int tile_x = X.tile_x();
117 const int tile_y = X.tile_y();
118 for (
int i = 0; i < num_images; i++) {
119 for (
int slice = 0; slice < X[i]->slices; slice++) {
121 const GLTexture* texture = X[i]->textures[slice];
123 texture->map_read([&](
const void* buffer,
147 "calling deInterleaveSlice width: %d, height: %d, stride: %d, channels: %d\n",
153 for (
int y = 0; y < tile_y; y++) {
154 for (
int x = 0; x < tile_x; x++) {
155 const int tiles = slice * tile_x * tile_y + y * tile_x + x;
156 const int slice_channels = std::min(4, input_channels - 4 * tiles);
158 output + i * input_channels * output_size + 4 * tiles * output_size,
159 (float16_t*)buffer + 4 * (y * input_height * stride + x * input_width),
175 OPERATOR_SCHEMA(CopyFromOpenGL).NumInputs(1).NumOutputs(1).AllowInplace({{0, 0}});
void Start()
Starts a timer.
int dim32(const int i) const
Returns the i-th dimension of the tensor in int.
T * mutable_data()
Returns a typed pointer of the underlying storage.
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
void Resize(Ts...dim_source)
Resizes a tensor.
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
A simple timer object for measuring time.