2 #include "../core/GLFilter.h" 3 #include "../core/GLImage.h" 4 #include "../core/ImageAllocator.h" 6 #include "caffe2/core/operator.h" 7 #include "caffe2/core/timer.h" 20 std::vector<binding*>({BINDING(outputSize), BINDING(inputData[0]), BINDING(inputData[1])}),
30 static const char* fragment_shader;
35 const char* GLSub::fragment_shader = R
"GLSL(#version 300 es 37 precision mediump float; 38 precision mediump int; 40 in highp vec2 v_texCoord; 42 uniform ivec2 outputSize; 44 TEXTURE_INPUT(inputData[2]); 45 TEXTURE_OUTPUT(0, outputData); 48 ivec2 texelCoord = ivec2(v_texCoord * vec2(outputSize)); 49 vec4 A = TEXTURE_LOAD(inputData[0], texelCoord); 50 vec4 B = TEXTURE_LOAD(inputData[1], texelCoord); 52 outputData = TEXTURE_STORE(value);} 60 const int num_images = input_images0.size();
61 for (
int i = 0; i < num_images; i++) {
64 int input_slices = input_image0->slices;
66 int output_slices = output_image->slices;
68 for (
int is = 0; is < input_slices; is++) {
69 std::vector<texture_attachment> input_attachments;
70 input_attachments.push_back({input_image0->textures[is], inputData[0]});
71 input_attachments.push_back({input_image1->textures[is], inputData[1]});
73 run(input_attachments,
74 {output_image->textures.begin() + is, output_image->textures.begin() + is + 1},
75 [&]() { glUniform2i(outputSize->location, output_image->width, output_image->height); },
77 output_image->height);
88 OPERATOR_NEEDS_FEATURE(OperatorBase::HasArgument(
"broadcast") ==
false,
"OpenGLSub does not support broadcast");
90 OPERATOR_NEEDS_FEATURE(OperatorBase::HasArgument(
"axis") ==
false,
"OpenGLSub does not support axis");
93 bool RunOnDevice()
override {
94 const GLImageVector<T>& input0 = Inputs()[0]->template Get<GLImageVector<T>>();
95 const GLImageVector<T>& input1 = Inputs()[1]->template Get<GLImageVector<T>>();
97 CAFFE_ENFORCE_EQ(input0.size(), input1.size());
99 const int num_images = input0.size();
100 const int input_channels = input0.channels();
101 const int input_width = input0.width();
102 const int input_height = input0.height();
103 CAFFE_ENFORCE_EQ(input1.channels(), input_channels);
104 CAFFE_ENFORCE_EQ(input1.width(), input_width);
105 CAFFE_ENFORCE_EQ(input1.height(), input_height);
107 const int output_channels = input_channels;
108 const int output_width = input_width;
109 const int output_height = input_height;
111 int is_last = OperatorBase::GetSingleArgument<int>(
"is_last", 0);
114 num_images, output_width, output_height, output_channels, is_last);
117 _sub.reset(
new GLSub());
120 _sub->sub(input0, input1, *output);
122 Outputs()[0]->Reset(output);
128 std::unique_ptr<GLSub> _sub;
132 OPERATOR_SCHEMA(OpenGLSub).NumInputs(2).NumOutputs(1);
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...