!27305 opengl bugfix

Merge pull request !27305 from Greatpan/master
This commit is contained in:
i-robot 2021-12-07 07:46:47 +00:00 committed by Gitee
commit ed1c99a831
6 changed files with 43 additions and 17 deletions

View File

@ -267,6 +267,16 @@ class MS_API GPUDeviceInfo : public DeviceInfoContext {
/// \return Whether enable float16 inference.
bool GetEnableFP16() const;
/// \brief Set enables to sharing mem with OpenGL
///
/// \param[in] is_enable_sharing_mem_with_gl Enable sharing OpenCL Memory with OpenGL or not.
void SetEnableGLTexture(bool is_enable_gl_texture);
/// \brief Get enables to sharing mem with OpenGL
///
/// \return Whether enable sharing mem with OpenGL.
bool GetEnableGLTexture() const;
private:
void SetPrecisionMode(const std::vector<char> &precision_mode);
std::vector<char> GetPrecisionModeChar() const;

View File

@ -181,6 +181,16 @@ class MS_API Model {
/// \return The vector of output MSTensor.
inline std::vector<MSTensor> GetOutputsByNodeName(const std::string &node_name);
/// \brief Bind GLTexture2D object to cl Memory.
///
/// \param[in] inputGlTexture The input GLTexture id for Model.
/// \param[in] outputGLTexture The output GLTexture id for Model.
///
/// \return Status of operation.
Status BindGLTexture2DMemory(const std::map<std::string, unsigned int> &inputGLTexture,
std::map<std::string, unsigned int> *outputGLTexture);
/// \brief Inference model.
///
/// \param[in] device_type Device typeoptions are kGPU, kAscend910, etc.
@ -254,9 +264,7 @@ std::vector<MSTensor> Model::GetOutputsByNodeName(const std::string &node_name)
return GetOutputsByNodeName(StringToChar(node_name));
}
Status Model::LoadConfig(const std::string &config_path) {
return LoadConfig(StringToChar(config_path));
}
Status Model::LoadConfig(const std::string &config_path) { return LoadConfig(StringToChar(config_path)); }
Status Model::UpdateConfig(const std::string &section, const std::pair<std::string, std::string> &config) {
std::pair<std::vector<char>, std::vector<char>> config_pair = {StringToChar(config.first),

View File

@ -30,6 +30,8 @@
#include "include/lite_types.h"
#ifdef ENABLE_OPENGL_TEXTURE
#include "EGL/egl.h"
#include "GLES3/gl3.h"
#include "GLES3/gl32.h"
#endif
namespace mindspore {

View File

@ -100,7 +100,7 @@ int Benchmark::GenerateGLTexture(std::map<std::string, GLuint> *input_gl_texture
std::map<std::string, GLuint> *output_gl_texture) {
for (auto tensor : ms_inputs_) {
MS_ASSERT(tensor != nullptr);
float *input_data = malloc(tensor->Size());
float *input_data = reinterpret_cast<float *>(malloc(tensor->Size()));
if (input_data == nullptr) {
MS_LOG(ERROR) << "new input_data failed";
return RET_ERROR;
@ -134,8 +134,8 @@ int Benchmark::GenerateGLTexture(std::map<std::string, GLuint> *input_gl_texture
int Benchmark::FillGLTextureToTensor(std::map<std::string, GLuint> *gl_texture, mindspore::tensor::MSTensor *tensor,
std::string name, float *data) {
if (data == nullptr) {
data = malloc(tensor->Size());
if (data = nullpter) {
data = reinterpret_cast<float *>(malloc(tensor->Size()));
if (data == nullptr) {
MS_LOG(ERROR) << "new output_data failed";
return RET_ERROR;
}
@ -211,7 +211,7 @@ int Benchmark::ReadGLTextureFile(std::map<std::string, GLuint> *input_gl_texture
delete[] bin_buf;
return RET_ERROR;
}
float *input_data = malloc(tensor->Size());
float *input_data = reinterpret_cast<float *>(malloc(tensor->Size()));
if (input_data == nullptr) {
MS_LOG(ERROR) << "new input_data failed";
return RET_ERROR;

View File

@ -377,19 +377,19 @@ bool OpenGLRuntime::CopyDeviceTextureToSSBO(GLuint textureID, GLuint ssboBufferI
glUseProgram(computeProgram);
// bind the src image texture
glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_READ_ONLY, GL_RGBA32F);
glBindImageTexture(BIND_INDEX_0, textureID, 0, GL_TRUE, 0, GL_READ_ONLY, GL_RGBA32F);
// bind the dest output data
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ssboBufferID);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BIND_INDEX_1, ssboBufferID);
// set uniform values
int width = m_texture_pool_[textureID].first[0];
int height = m_texture_pool_[textureID].first[1];
int channel = m_texture_pool_[textureID].first[2];
glUniform1i(kNHWC_H, width);
glUniform1i(kNHWC_W, height);
glUniform1i(kNHWC_C, channel);
glUniform1i(BIND_INDEX_2, width);
glUniform1i(BIND_INDEX_3, height);
glUniform1i(BIND_INDEX_4, channel);
int c_4 = UP_DIV(channel, 4);
int gLocalSize[3] = {4, 4, 1};
@ -415,19 +415,19 @@ bool OpenGLRuntime::CopyDeviceSSBOToTexture(GLuint ssboBufferID, GLuint textureI
glUseProgram(computeProgram);
// bind the src image texture
glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_WRITE_ONLY, GL_RGBA32F);
glBindImageTexture(BIND_INDEX_0, textureID, 0, GL_TRUE, 0, GL_WRITE_ONLY, GL_RGBA32F);
// bind the dest output data
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ssboBufferID);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, BIND_INDEX_1, ssboBufferID);
// set uniform values
int width = m_texture_pool_[textureID].first[0];
int height = m_texture_pool_[textureID].first[1];
int channel = m_texture_pool_[textureID].first[2];
glUniform1i(kNHWC_H, width);
glUniform1i(kNHWC_W, height);
glUniform1i(kNHWC_C, channel);
glUniform1i(BIND_INDEX_2, width);
glUniform1i(BIND_INDEX_3, height);
glUniform1i(BIND_INDEX_4, channel);
int c_4 = UP_DIV(channel, 4);
int gLocalSize[3] = {4, 4, 1};

View File

@ -46,6 +46,12 @@
namespace mindspore {
namespace OpenGL {
#define BIND_INDEX_0 0
#define BIND_INDEX_1 1
#define BIND_INDEX_2 2
#define BIND_INDEX_3 3
#define BIND_INDEX_4 4
class OpenGLRuntime {
public:
OpenGLRuntime();