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" 19 std::vector<binding*>({BINDING(outputSize), BINDING(inputData), BINDING(B)}),
27 static const char* fragment_shader;
32 const char* GLMul::fragment_shader = R
"GLSL(#version 300 es 34 precision mediump float; 35 precision mediump int; 37 in highp vec2 v_texCoord; 39 uniform ivec2 outputSize; 42 TEXTURE_INPUT(inputData); 43 TEXTURE_OUTPUT(0, outputData); 46 ivec2 texelCoord = ivec2(v_texCoord * vec2(outputSize)); 47 vec4 A = TEXTURE_LOAD(inputData, texelCoord); 48 outputData = TEXTURE_STORE(A * B); 57 for (
int i = 0; i < input_images.size(); i++) {
58 auto input_image = input_images[i];
59 auto output_image = output_images[i];
60 int input_slices = input_image->slices;
61 int output_slices = output_image->slices;
63 for (
int is = 0; is < input_slices; is++) {
64 run(std::vector<texture_attachment>({{input_image->textures[is], inputData}}),
65 {output_image->textures.begin() + is, output_image->textures.begin() + is + 1},
67 glUniform2i(outputSize->location, output_image->width, output_image->height);
68 glUniform4f(B->location, b, b, b, b);
71 output_image->height);
82 OPERATOR_NEEDS_FEATURE(OperatorBase::GetSingleArgument<int>(
"broadcast", 0) == 1,
83 "OpenGLMul only supports broadcast");
85 OPERATOR_NEEDS_FEATURE(OperatorBase::HasArgument(
"axis") ==
false,
86 "OpenGLMul does not support axis");
89 bool RunOnDevice()
override {
90 const GLImageVector<T>& input = Inputs()[0]->template Get<GLImageVector<T>>();
91 const auto& B = Input(1);
92 CAFFE_ENFORCE_EQ(B.size(), 1);
94 const int num_images = input.size();
95 const auto output_height = input.height();
96 const auto output_width = input.width();
97 const int output_channels = input.channels();
99 int is_last = OperatorBase::GetSingleArgument<int>(
"is_last", 0);
102 num_images, output_width, output_height, output_channels, is_last);
105 _mult.reset(
new GLMul());
108 _mult->mul(input, *output, B.template data<float>()[0]);
110 Outputs()[0]->Reset(output);
116 std::unique_ptr<GLMul> _mult;
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 ...