提交 12847919 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!4770 [MS][LITE][Develop] fix codex for opencl depthwise

Merge pull request !4770 from wandongdong/master
#define divide_no_check(a, b) (a/b)
__constant sampler_t smp_none = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST;
__kernel void ElementAdd(__read_only image2d_t input_a, __read_only image2d_t input_b, __write_only image2d_t output,
......@@ -49,10 +50,7 @@ __kernel void ElementDiv(__read_only image2d_t input_a, __read_only image2d_t in
float4 a = read_imagef(input_a, smp_none, (int2)(X, Y));
float4 b = read_imagef(input_b, smp_none, (int2)(X, Y));
if (b == 0) {
return;
}
write_imagef(output, (int2)(X, Y), a / b);
write_imagef(output, (int2)(X, Y), divide_no_check(a, b));
}
__kernel void BoardcastArith(__read_only image2d_t input_a, float weight, float bias, __write_only image2d_t output,
......
......@@ -102,7 +102,6 @@ int DepthwiseConv2dOpenCLKernel::InitBuffer() {
allocator->UnmapBuffer(packed_weight_);
// init bias
if (in_tensors_.size() == kInputSize2) {
bias_data_ = reinterpret_cast<FLOAT_t *>(allocator->Malloc(C4NUM * CO4 * sizeof(FLOAT_t)));
bias_data_ = reinterpret_cast<FLOAT_t *>(allocator->MapBuffer(bias_data_, CL_MAP_WRITE, nullptr, true));
......
......@@ -15,7 +15,6 @@
*/
#include "src/runtime/kernel/opencl/subgraph_opencl_kernel.h"
#include <set>
#include "src/runtime/opencl/opencl_executor.h"
#include "src/runtime/opencl/opencl_runtime.h"
#include "src/runtime/kernel/opencl/utils.h"
......@@ -92,6 +91,8 @@ int SubGraphOpenCLKernel::GenToFormatOp(const std::vector<lite::tensor::Tensor *
MS_ASSERT(parameter);
if (parameter == nullptr) {
MS_LOG(ERROR) << "SubGraphOpenCLKernel new parameter failed!";
delete new_tensor;
new_tensor = nullptr;
return RET_ERROR;
}
parameter->src_format = src_format;
......@@ -109,6 +110,10 @@ int SubGraphOpenCLKernel::GenToFormatOp(const std::vector<lite::tensor::Tensor *
MS_ASSERT(in_convert_op);
if (in_convert_op == nullptr) {
MS_LOG(ERROR) << "SubGraphOpenCLKernel create op failed!";
delete new_tensor;
new_tensor = nullptr;
delete parameter;
parameter = nullptr;
return RET_ERROR;
}
auto in_opencl_op = reinterpret_cast<OpenCLKernel *>(in_convert_op);
......@@ -272,16 +277,16 @@ int SubGraphOpenCLKernel::UnInit() {
delete tensor;
}
}
for (const auto parameter : in_parameters_) {
if (parameter != nullptr) {
delete parameter;
}
}
for (const auto op : in_convert_ops_) {
if (op != nullptr) {
delete op;
}
}
for (const auto parameter : in_parameters_) {
if (parameter != nullptr) {
delete parameter;
}
}
return RET_OK;
}
......@@ -290,18 +295,15 @@ int SubGraphOpenCLKernel::InferShape() { return RET_OK; }
int SubGraphOpenCLKernel::ReSize() { return RET_OK; }
int SubGraphOpenCLKernel::Run() {
auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance();
for (auto &tensor : in_tensors_) {
allocator_->UnmapBuffer(tensor->Data());
}
lite::opencl::OpenCLExecutor executor;
executor.Run(in_tensors_, out_tensors_, nodes_, allocator_);
ocl_runtime->SyncCommandQueue();
for (auto &tensor : out_tensors_) {
void *data = allocator_->MapBuffer(tensor->Data(), CL_MAP_READ, nullptr, true);
tensor->SetData(data);
}
return RET_OK;
}
} // namespace mindspore::kernel
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册