forked from alibaba/MNN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGLConverter.cpp
More file actions
65 lines (53 loc) · 1.81 KB
/
Copy pathGLConverter.cpp
File metadata and controls
65 lines (53 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// GLConverter.cpp
// MNN
//
// Created by MNN on 2019/01/31.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include "GLConverter.hpp"
#include "AllShader.hpp"
#include "GLBackend.hpp"
#include "Macro.h"
#include "TensorUtils.hpp"
namespace MNN {
namespace OpenGL {
GLConverter::GLConverter(const std::vector<Tensor *> &inputs, const Op *op, Backend *bn) : Execution(bn) {
}
GLConverter::~GLConverter() {
}
ErrorCode GLConverter::onResize(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) {
std::vector<std::string> prefix;
setLocalSize(prefix, mLocalSize, 8, 8, 1);
mProgram = ((GLBackend *)backend())->getProgram("convert", glsl_converter_glsl, prefix);
return NO_ERROR;
}
ErrorCode GLConverter::onExecute(const std::vector<Tensor *> &inputs, const std::vector<Tensor *> &outputs) {
auto input = inputs[0];
auto output = outputs[0];
std::vector<int> inputShape = tensorShapeFormat(input);
int ib = inputShape.at(0);
int ih = inputShape.at(1);
int iw = inputShape.at(2);
int ic = inputShape.at(3);
int ic_4 = UP_DIV(ic, 4);
mProgram->useProgram();
glBindImageTexture(0, output->deviceId(), 0, GL_TRUE, 0, GL_WRITE_ONLY, TEXTURE_FORMAT);
OPENGL_CHECK_ERROR;
{
int texId = 0;
glActiveTexture(GL_TEXTURE0 + texId);
glUniform1i(1, texId);
glBindTexture(GL_TEXTURE_3D, input->deviceId());
OPENGL_CHECK_ERROR;
}
glUniform1i(2, iw);
glUniform1i(3, ih);
glUniform1i(4, ic_4);
((GLBackend *)backend())->compute(UP_DIV(iw, mLocalSize[0]), UP_DIV(ih, mLocalSize[1]),
UP_DIV(ic_4, mLocalSize[2]));
return NO_ERROR;
}
GLCreatorRegister<TypedCreator<GLConverter>> __converter_op(OpType_ConvertTensor);
} // namespace OpenGL
} // namespace MNN