未验证 提交 9bf15fef 编写于 作者: X xiebaiyuan 提交者: GitHub

[OPENCL][BACKEND] Avoid memory copy for MallocImage when host_ptr specified (#4153)

* [OPENCL] if specify addr , do not need to modify. avoid mem copy

* test=develop
上级 1ebbfd97
...@@ -64,16 +64,16 @@ void *TargetWrapperCL::MallocImage<float>(const size_t cl_image2d_width, ...@@ -64,16 +64,16 @@ void *TargetWrapperCL::MallocImage<float>(const size_t cl_image2d_width,
void *host_ptr) { void *host_ptr) {
cl::ImageFormat img_format(CL_RGBA, GetCLChannelType(PRECISION(kFloat))); cl::ImageFormat img_format(CL_RGBA, GetCLChannelType(PRECISION(kFloat)));
cl_int status; cl_int status;
cl::Image2D *cl_image = cl::Image2D *cl_image = new cl::Image2D(
new cl::Image2D(CLRuntime::Global()->context(), CLRuntime::Global()->context(),
CL_MEM_READ_WRITE | (host_ptr ? CL_MEM_COPY_HOST_PTR (host_ptr ? CL_MEM_READ_ONLY : CL_MEM_READ_WRITE) |
: CL_MEM_ALLOC_HOST_PTR), (host_ptr ? CL_MEM_COPY_HOST_PTR : CL_MEM_ALLOC_HOST_PTR),
img_format, img_format,
cl_image2d_width, cl_image2d_width,
cl_image2d_height, cl_image2d_height,
0, 0,
host_ptr, host_ptr,
&status); &status);
if (status != CL_SUCCESS) { if (status != CL_SUCCESS) {
delete cl_image; delete cl_image;
cl_image = nullptr; cl_image = nullptr;
...@@ -88,16 +88,16 @@ void *TargetWrapperCL::MallocImage<uint16_t>(const size_t cl_image2d_width, ...@@ -88,16 +88,16 @@ void *TargetWrapperCL::MallocImage<uint16_t>(const size_t cl_image2d_width,
void *host_ptr) { void *host_ptr) {
cl::ImageFormat img_format(CL_RGBA, GetCLChannelType(PRECISION(kFP16))); cl::ImageFormat img_format(CL_RGBA, GetCLChannelType(PRECISION(kFP16)));
cl_int status; cl_int status;
cl::Image2D *cl_image = cl::Image2D *cl_image = new cl::Image2D(
new cl::Image2D(CLRuntime::Global()->context(), CLRuntime::Global()->context(),
CL_MEM_READ_WRITE | (host_ptr ? CL_MEM_COPY_HOST_PTR (host_ptr ? CL_MEM_READ_ONLY : CL_MEM_READ_WRITE) |
: CL_MEM_ALLOC_HOST_PTR), (host_ptr ? CL_MEM_COPY_HOST_PTR : CL_MEM_ALLOC_HOST_PTR),
img_format, img_format,
cl_image2d_width, cl_image2d_width,
cl_image2d_height, cl_image2d_height,
0, 0,
host_ptr, host_ptr,
&status); &status);
if (status != CL_SUCCESS) { if (status != CL_SUCCESS) {
delete cl_image; delete cl_image;
cl_image = nullptr; cl_image = nullptr;
...@@ -112,16 +112,16 @@ void *TargetWrapperCL::MallocImage<int32_t>(const size_t cl_image2d_width, ...@@ -112,16 +112,16 @@ void *TargetWrapperCL::MallocImage<int32_t>(const size_t cl_image2d_width,
void *host_ptr) { void *host_ptr) {
cl::ImageFormat img_format(CL_RGBA, GetCLChannelType(PRECISION(kInt32))); cl::ImageFormat img_format(CL_RGBA, GetCLChannelType(PRECISION(kInt32)));
cl_int status; cl_int status;
cl::Image2D *cl_image = cl::Image2D *cl_image = new cl::Image2D(
new cl::Image2D(CLRuntime::Global()->context(), CLRuntime::Global()->context(),
CL_MEM_READ_WRITE | (host_ptr ? CL_MEM_COPY_HOST_PTR (host_ptr ? CL_MEM_READ_ONLY : CL_MEM_READ_WRITE) |
: CL_MEM_ALLOC_HOST_PTR), (host_ptr ? CL_MEM_COPY_HOST_PTR : CL_MEM_ALLOC_HOST_PTR),
img_format, img_format,
cl_image2d_width, cl_image2d_width,
cl_image2d_height, cl_image2d_height,
0, 0,
host_ptr, host_ptr,
&status); &status);
if (status != CL_SUCCESS) { if (status != CL_SUCCESS) {
delete cl_image; delete cl_image;
cl_image = nullptr; cl_image = nullptr;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册