diff --git a/mindspore/lite/java/native/runtime/ms_tensor.cpp b/mindspore/lite/java/native/runtime/ms_tensor.cpp index a213035ed3..1c32245b0c 100644 --- a/mindspore/lite/java/native/runtime/ms_tensor.cpp +++ b/mindspore/lite/java/native/runtime/ms_tensor.cpp @@ -65,9 +65,9 @@ extern "C" JNIEXPORT jbyteArray JNICALL Java_com_mindspore_lite_MSTensor_getByte return env->NewByteArray(0); } - auto local_element_num = ms_tensor_ptr->ElementsNum(); - auto ret = env->NewByteArray(local_element_num); - env->SetByteArrayRegion(ret, 0, local_element_num, local_data); + auto local_size = ms_tensor_ptr->Size(); + auto ret = env->NewByteArray(local_size); + env->SetByteArrayRegion(ret, 0, local_size, local_data); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/concat.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/concat.cl index 5efff4a7bf..78c0577fb2 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/concat.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/concat.cl @@ -11,7 +11,7 @@ __constant sampler_t smp_none = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | if (X >= output_shape.x * output_shape.y || Y >= output_shape.z || Z >= output_shape.w) { \ return; \ } \ - TYPE4 result; + DTYPE4 result; // axis = 1 #define DOConcat2inputaxis1_NHWC4 \ @@ -248,12 +248,12 @@ CONCAT2(2input, axis3, _NHWC4) int Align_OutShape = output_shape.w; \ int index_output = (IN * output_shape.y + IH) * stride_w + IW * Align_OutShape * C4NUM; -int doconcat(__read_only image2d_t input, __global TYPE *output, int Align_Shape, int4 input_shape, int IN, int IH, +int doconcat(__read_only image2d_t input, __global DTYPE *output, int Align_Shape, int4 input_shape, int IN, int IH, int Y, int index_output) { int Remainder = input_shape.w % C4NUM; for (int i = 0; i < Align_Shape; ++i) { - TYPE4 result = READ_IMAGE(input, smp_none, (int2)((Y * Align_Shape + i), (IN * input_shape.y + IH))); - TYPE result_temp[4] = {result.x, result.y, result.z, result.w}; + DTYPE4 result = READ_IMAGE(input, smp_none, (int2)((Y * Align_Shape + i), (IN * input_shape.y + IH))); + DTYPE result_temp[4] = {result.x, result.y, result.z, result.w}; if ((i + 1) * C4NUM <= input_shape.w) { for (int j = 0; j < C4NUM; ++j) { output[index_output++] = result_temp[j]; @@ -268,7 +268,7 @@ int doconcat(__read_only image2d_t input, __global TYPE *output, int Align_Shape } __kernel void ConcatInput2UnAlign_NHWC4(__read_only image2d_t input0, __read_only image2d_t input1, - __global TYPE *output, int4 input_shape0, int4 input_shape1, int stride_w, + __global DTYPE *output, int4 input_shape0, int4 input_shape1, int stride_w, int4 output_shape) { CHECK_IDX_UNALIGN; index_output = doconcat(input0, output, Align_Shape0, input_shape0, IN, IH, Y, index_output); @@ -276,7 +276,7 @@ __kernel void ConcatInput2UnAlign_NHWC4(__read_only image2d_t input0, __read_onl } __kernel void ConcatInput3UnAlign_NHWC4(__read_only image2d_t input0, __read_only image2d_t input1, - __read_only image2d_t input2, __global TYPE *output, int4 input_shape0, + __read_only image2d_t input2, __global DTYPE *output, int4 input_shape0, int4 input_shape1, int4 input_shape2, int stride_w, int4 output_shape) { CHECK_IDX_UNALIGN; int Align_Shape2 = UP_DIV(input_shape2.w, C4NUM); @@ -287,7 +287,7 @@ __kernel void ConcatInput3UnAlign_NHWC4(__read_only image2d_t input0, __read_onl __kernel void ConcatInput4UnAlign_NHWC4(__read_only image2d_t input0, __read_only image2d_t input1, __read_only image2d_t input2, __read_only image2d_t input3, - __global TYPE *output, int4 input_shape0, int4 input_shape1, int4 input_shape2, + __global DTYPE *output, int4 input_shape0, int4 input_shape1, int4 input_shape2, int4 input_shape3, int stride_w, int4 output_shape) { CHECK_IDX_UNALIGN; int Align_Shape2 = UP_DIV(input_shape2.w, C4NUM), Align_Shape3 = UP_DIV(input_shape3.w, C4NUM); @@ -299,7 +299,7 @@ __kernel void ConcatInput4UnAlign_NHWC4(__read_only image2d_t input0, __read_onl __kernel void ConcatInput5UnAlign_NHWC4(__read_only image2d_t input0, __read_only image2d_t input1, __read_only image2d_t input2, __read_only image2d_t input3, - __read_only image2d_t input4, __global TYPE *output, int4 input_shape0, + __read_only image2d_t input4, __global DTYPE *output, int4 input_shape0, int4 input_shape1, int4 input_shape2, int4 input_shape3, int4 input_shape4, int stride_w, int4 output_shape) { CHECK_IDX_UNALIGN; @@ -315,7 +315,7 @@ __kernel void ConcatInput5UnAlign_NHWC4(__read_only image2d_t input0, __read_onl __kernel void ConcatInput6UnAlign_NHWC4(__read_only image2d_t input0, __read_only image2d_t input1, __read_only image2d_t input2, __read_only image2d_t input3, __read_only image2d_t input4, __read_only image2d_t input5, - __global TYPE *output, int4 input_shape0, int4 input_shape1, int4 input_shape2, + __global DTYPE *output, int4 input_shape0, int4 input_shape1, int4 input_shape2, int4 input_shape3, int4 input_shape4, int4 input_shape5, int stride_w, int4 output_shape) { CHECK_IDX_UNALIGN; diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/gather.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/gather.cl index fab23758b6..85213e9223 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/gather.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/gather.cl @@ -9,7 +9,7 @@ __kernel void gather(__write_only image2d_t dst_data, __read_only image2d_t src_ if (X >= dst_size.x || Y >= dst_size.y * dst_size.w || Z >= dst_size.z || dst_size.y == 0) { return; } - TYPE4 res_data = (TYPE4)(0.0f, 0.0f, 0.0f, 0.0f); + DTYPE4 res_data = (DTYPE4)(0.0f, 0.0f, 0.0f, 0.0f); int batch = Y / dst_size.y; int height = Y % dst_size.y; if (axis == 0) { @@ -20,10 +20,10 @@ __kernel void gather(__write_only image2d_t dst_data, __read_only image2d_t src_ res_data = READ_IMAGE(src_data, smp_zero, (int2)(indices[X] * src_size.z + Z, batch * src_size.y + height)); } else if (axis == 3) { int offset[4] = {indices[Z * 4] / 4, indices[Z * 4 + 1] / 4, indices[Z * 4 + 2] / 4, indices[Z * 4 + 3] / 4}; - TYPE tmp[4]; - TYPE res_tmp[4]; + DTYPE tmp[4]; + DTYPE res_tmp[4]; for (int i = 0; i < indices_num; ++i) { - TYPE4 rd_data = (TYPE4)(0.0f, 0.0f, 0.0f, 0.0f); + DTYPE4 rd_data = (DTYPE4)(0.0f, 0.0f, 0.0f, 0.0f); rd_data = READ_IMAGE(src_data, smp_zero, (int2)(X * src_size.z + offset[i], batch * src_size.y + height)); if (i >= 1 && offset[i] != offset[i - 1]) { rd_data = READ_IMAGE(src_data, smp_zero, (int2)(X * src_size.z + offset[i], batch * src_size.y + height)); diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/reshape.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/reshape.cl index 7be0cfdcf1..4543fda15f 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/reshape.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/reshape.cl @@ -16,9 +16,9 @@ __kernel void reshape_NHWC4(__read_only image2d_t src_data, __write_only image2d int CI4_rem = src_size.x % C4NUM; CI4_rem = (CI4_rem == 0) ? C4NUM : CI4_rem; int in_img_x = CI4 * src_size.y; - TYPE4 res = (TYPE4)(0.0f); - TYPE tmp[4]; - TYPE res_tmp[4]; + DTYPE4 res = (DTYPE4)(0.0f); + DTYPE tmp[4]; + DTYPE res_tmp[4]; int gcnt = 0; if (CO4_rem == 0 && ((CI4_rem & 0x3) == 0)) { gcnt = X + dst_size.x * Y; diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/sparse_to_dense.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/sparse_to_dense.cl index 07af10c86c..1eafdf5b31 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/sparse_to_dense.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/sparse_to_dense.cl @@ -2,14 +2,14 @@ #define C4NUM 4 __constant sampler_t smp_zero = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; -__kernel void SparseToDenseScalar(__read_only image2d_t input, __global float *output, float weight, int2 inputshape, +__kernel void SparseToDenseScalar(__read_only image2d_t input, __global DTYPE *output, float weight, int2 inputshape, int4 outputshape, float default_value, int stride_w, int inshapeindex1_dim) { int X = get_global_id(0); int Y = get_global_id(1); if (X >= inputshape.x || Y >= inputshape.y) { return; } - FLT4 index_input = READ_IMAGE(input, smp_zero, (int2)(Y, X)); + int4 index_input = read_imagei(input, smp_zero, (int2)(Y, X)); int4 index_input_int = *((int4 *)&index_input); int index = 0; if (inshapeindex1_dim == 1) { @@ -25,7 +25,7 @@ __kernel void SparseToDenseScalar(__read_only image2d_t input, __global float *o output[index] = weight; } -__kernel void SparseToDenseVector(__read_only image2d_t input, __global float *output, __global float *weight_vector, +__kernel void SparseToDenseVector(__read_only image2d_t input, __global DTYPE *output, __global float *weight_vector, int2 inputshape, int4 outputshape, float default_value, int stride_w, int inshapeindex1_dim) { int X = get_global_id(0); @@ -33,7 +33,7 @@ __kernel void SparseToDenseVector(__read_only image2d_t input, __global float *o if (X >= inputshape.x || Y >= inputshape.y) { return; } - FLT4 index_input = READ_IMAGE(input, smp_zero, (int2)(Y, X)); + int4 index_input = read_imagei(input, smp_zero, (int2)(Y, X)); int4 index_input_int = *((int4 *)&index_input); int index = 0; if (inshapeindex1_dim == 1) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc index cebdee3c54..7b047e5ed5 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc @@ -73,14 +73,7 @@ int ActivationOpenCLKernel::Prepare() { std::string program_name = "Activation"; ocl_runtime_->LoadSource(program_name, source); std::string kernel_name = GetActTypeString(type_); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeInt32) { - build_options_ext = {" -DTYPE=int -DTYPE4=int4 -DWRITE_IMAGE=write_imagei -DREAD_IMAGE=read_imagei "}; - } else if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DTYPE=float -DTYPE4=float4 -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DTYPE=half -DTYPE4=half4 -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); SetConstArgs(); SetGlobalLocal(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/argminmax.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/argminmax.cc index d54a027def..13783838a7 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/argminmax.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/argminmax.cc @@ -149,14 +149,7 @@ int ArgMinMaxOpenCLKernel::Prepare() { std::string source = argminmax_source; std::string program_name = "argminmax"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeInt32) { - build_options_ext = {" -DTYPE=int -DTYPE4=int4 -DWRITE_IMAGE=write_imagei -DREAD_IMAGE=read_imagei "}; - } else if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DTYPE=float -DTYPE4=float4 -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DTYPE=half -DTYPE4=half4 -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc index 3bc47793a3..ae6e604b37 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc @@ -191,14 +191,7 @@ int ArithmeticOpenCLKernel::Prepare() { std::string program_name = "Arithmetic"; std::string source = arithmetic_source; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeInt32) { - build_options_ext = {" -DTYPE=int -DTYPE4=int4 -DWRITE_IMAGE=write_imagei -DREAD_IMAGE=read_imagei "}; - } else if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DTYPE=float -DTYPE4=float4 -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DTYPE=half -DTYPE4=half4 -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); int error_code = ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name_, build_options_ext); #endif if (error_code != RET_OK) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc index fc0f649690..6dba34062b 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic_self.cc @@ -89,14 +89,7 @@ int ArithmeticSelfOpenCLKernel::Prepare() { MS_LOG(DEBUG) << "execute kernel name : " << kernel_name; std::string program_name = "ArithmeticSelf"; ocl_runtime_->LoadSource(program_name, arithmeticself_source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeInt32) { - build_options_ext = {" -DTYPE=int -DTYPE4=int4 -DWRITE_IMAGE=write_imagei -DREAD_IMAGE=read_imagei "}; - } else if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DTYPE=float -DTYPE4=float4 -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DTYPE=half -DTYPE4=half4 -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); SetGlobalLocal(); SetConstArgs(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc index c1aa40cebc..d91d4b63d1 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/batch_to_space_nd.cc @@ -94,12 +94,7 @@ int BatchToSpaceNDOpenCLKernel::Prepare() { std::string source = batch_to_space_nd_source; std::string program_name = "batch_to_space_nd"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc index 0590789a96..8b847cd420 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/batchnorm.cc @@ -168,12 +168,7 @@ int BatchNormOpenCLKernel::Prepare() { std::string source = batchnorm_source; std::string program_name = "Batch_normalization"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); MS_LOG(DEBUG) << kernel_name << " Init Done!"; int ret = Initweight(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc index 777b282c56..c20e5f6110 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc @@ -224,14 +224,7 @@ int ConcatOpenCLKernel::Prepare() { std::string source = concat_source; std::string program_name = "Concat"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeInt32) { - build_options_ext = {" -DTYPE=int -DTYPE4=int4 -DWRITE_IMAGE=write_imagei -DREAD_IMAGE=read_imagei "}; - } else if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DTYPE=float -DTYPE4=float4 -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DTYPE=half -DTYPE4=half4 -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); MS_LOG(DEBUG) << kernel_name << " Init Done!"; SetConstArgs(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d.cc index a7e33afed0..78270c3a09 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d.cc @@ -144,12 +144,7 @@ void Conv2DOpenCLKernel::BuildKernel() { kernel_name << "_Img"; } ocl_runtime_->LoadSource(program_name, GetActDefines() + conv2d_source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name.str(), build_options_ext); } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc index 5cd279da16..ab1c55658f 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc @@ -65,12 +65,7 @@ int Conv2dTransposeOpenCLKernel::Prepare() { std::string source = GetActDefines() + conv2d_transpose_source; std::string program_name = "conv2d_transpose"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif auto ret = InitWeights(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc index 3d5ca89a12..936abed116 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc @@ -85,12 +85,7 @@ int DepthwiseConv2dOpenCLKernel::Prepare() { std::string program_name = "DepthwiseConv2d"; std::string source = depthwise_conv2d_source; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif auto ret = InitWeights(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc index a4f80e0605..bd6ff8f9a2 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc @@ -105,12 +105,7 @@ int FullConnectionOpenCLKernel::Prepare() { std::string source = fullconnection_source; std::string program_name = "FullConnection"; ocl_runtime_->LoadSource(program_name, GetActDefines() + source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif auto ret = InitWeights(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc index 664e1a7901..0bb1908677 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/gather.cc @@ -114,14 +114,7 @@ int GatherOpenCLKernel::Prepare() { #else std::string program_name = "gather"; ocl_runtime_->LoadSource(program_name, gather_source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeInt32) { - build_options_ext = {" -DTYPE=int -DTYPE4=int4 -DWRITE_IMAGE=write_imagei -DREAD_IMAGE=read_imagei "}; - } else if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DTYPE=float -DTYPE4=float4 -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DTYPE=half -DTYPE4=half4 -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif if (in_tensors_.at(1)->IsConst()) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/layer_norm.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/layer_norm.cc index 4a3f991258..067efa228d 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/layer_norm.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/layer_norm.cc @@ -171,12 +171,7 @@ int LayerNormOpenCLKernel::Prepare() { std::string source = layer_norm_source; std::string program_name = "LayerNormalization"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); kernel_name_mean_var += "Axis" + std::to_string(normalized_axis_) + "NHWC4"; ocl_runtime_->BuildKernel(kernel_mean_var_, program_name, kernel_name_mean_var, build_options_ext); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc index b6576745d2..b6fdb6007f 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc @@ -92,12 +92,7 @@ int MatMulOpenCLKernel::Prepare() { std::string source = matmul_source; std::string program_name = "MatMul"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/pad.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/pad.cc index fc698cc9c5..fd7489cee0 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/pad.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/pad.cc @@ -74,12 +74,7 @@ int PadOpenCLKernel::Prepare() { const std::string source = pad_source; const std::string program_name = "Pad"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, "Pad", build_options_ext); SetConstArgs(); return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc index cb7f6cc907..bae0a22604 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc @@ -82,12 +82,7 @@ int PoolingOpenCLKernel::Prepare() { std::string source = pooling2d_source; std::string program_name = "Pooling2d"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif SetConstArgs(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/power.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/power.cc index 6ded9d93ad..1be4345162 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/power.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/power.cc @@ -118,12 +118,7 @@ int PowerOpenCLKernel::Prepare() { scale_ = param->scale_; shift_ = param->shift_; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); MS_LOG(DEBUG) << kernel_name << " Init Done!"; SetGlobalLocal(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc index 533c2e5ce0..41e16ee89b 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/prelu.cc @@ -130,12 +130,7 @@ int PReluOpenCLKernel::Prepare() { std::string program_name = "PRelu"; std::string kernel_name = "PRelu_" + std::string(weight_is_scalar ? "scalar" : "vector"); ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); InitWeights(); MS_LOG(DEBUG) << program_name << " init Done!"; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc index 7e5ee9de50..b7e8589ed7 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/reduce.cc @@ -186,12 +186,7 @@ int ReduceOpenCLKernel::Prepare() { std::string source = reduce_source; std::string program_name = "Reduce"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); auto ret = ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); if (ret != RET_OK) { return ret; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc index deed162f5b..b4214741b0 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc @@ -78,14 +78,7 @@ int ReshapeOpenCLKernel::Prepare() { #else std::string source = reshape_source; std::string program_name = "reshape"; - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeInt32) { - build_options_ext = {" -DTYPE=int -DTYPE4=int4 -DWRITE_IMAGE=write_imagei -DREAD_IMAGE=read_imagei "}; - } else if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DTYPE=float -DTYPE4=float4 -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DTYPE=half -DTYPE4=half4 -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->LoadSource(program_name, source); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/resize.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/resize.cc index 551f479d66..de6514c544 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/resize.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/resize.cc @@ -70,12 +70,7 @@ int ResizeOpenCLKernel::Prepare() { std::string source = resize_source; std::string program_name = "Resize"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif SetConstArgs(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc index 26b725da49..b9be99f3e1 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/scale.cc @@ -166,12 +166,7 @@ int ScaleOpenCLKernel::Prepare() { std::string program_name = "Scale"; std::string source = GetActDefines() + scale_source; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); error_code = ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif if (error_code != RET_OK) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc index 7ace8d03c3..eb2281997e 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_batch_nd.cc @@ -100,12 +100,7 @@ int SpaceToBatchNDOpenCLKernel::Prepare() { std::string source = space_to_batch_nd_source; std::string program_name = "space_to_batch_nd"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_depth.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_depth.cc index 1d6f297b87..b762ad4e7a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_depth.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/space_to_depth.cc @@ -58,12 +58,7 @@ int SpaceToDepthOpenCLKernel::Prepare() { std::string source = space_to_depth_source; std::string program_name = "SpaceToDepth"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif SetConstArgs(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/sparse_to_dense.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/sparse_to_dense.cc index 471b1ca6be..b2cbab435d 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/sparse_to_dense.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/sparse_to_dense.cc @@ -141,6 +141,7 @@ void SparseToDenseOpenCLKernel::SetGlobalLocal() { } int SparseToDenseOpenCLKernel::Prepare() { + enable_fp16_ = ocl_runtime_->GetFp16Enable(); input_dim_ = in_tensors_[0]->shape().size(); inshapeindex1_dim = in_tensors_[0]->shape()[1]; weight_scalar_ = in_tensors_[2]->IsScalar(); @@ -149,10 +150,10 @@ int SparseToDenseOpenCLKernel::Prepare() { std::string program_name = "SparseToDense"; ocl_runtime_->LoadSource(program_name, source); std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; + if (enable_fp16_) { + build_options_ext = {" -DDTYPE=half "}; + } else { + build_options_ext = {" -DDTYPE=float "}; } ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); @@ -216,6 +217,5 @@ int SparseToDenseOpenCLKernel::Run() { return RET_OK; } -REG_KERNEL(kGPU, kNumberTypeFloat32, PrimitiveType_SparseToDense, OpenCLKernelCreator); -REG_KERNEL(kGPU, kNumberTypeFloat16, PrimitiveType_SparseToDense, OpenCLKernelCreator); +REG_KERNEL(kGPU, kNumberTypeInt32, PrimitiveType_SparseToDense, OpenCLKernelCreator); } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/split.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/split.cc index ca5d87f8e6..7caac78c0a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/split.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/split.cc @@ -136,12 +136,7 @@ int SplitOpenCLKernel::Prepare() { std::string source = split_source; std::string program_name = "split"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); MS_LOG(DEBUG) << kernel_name << " Init Done!"; SetConstArgs(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/stack.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/stack.cc index a64ba3786f..92d5aa2ba3 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/stack.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/stack.cc @@ -165,12 +165,7 @@ int StackOpenCLKernel::Prepare() { std::string source = stack_source; std::string program_name = "stack"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); SetConstArgs(); SetGlobalLocal(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/strassen.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/strassen.cc index aa00b9a019..7321450c62 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/strassen.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/strassen.cc @@ -32,12 +32,7 @@ int StrassenOpenCLKernel::Prepare() { std::string source = strassen_source; std::string program_name = "MatMul"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); ocl_runtime_->BuildKernel(kernel_IMG_add_sub_2, program_name, "MatMul_IMG_Add_Sub_2", build_options_ext); ocl_runtime_->BuildKernel(kernel_BUF_add_sub_2, program_name, "MatMul_BUF_Add_Sub_2", build_options_ext); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/strided_slice.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/strided_slice.cc index 0578f7eae3..8319a4bde6 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/strided_slice.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/strided_slice.cc @@ -89,12 +89,7 @@ int StridedSliceOpenCLKernel::CheckSpecs() { int StridedSliceOpenCLKernel::Prepare() { std::string program_name = "strided_slice"; ocl_runtime_->LoadSource(program_name, strided_slice_source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, "strided_slice", build_options_ext); SetConstArgs(); SetGlobalLocal(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc index 940645fb8c..3399937420 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc @@ -110,12 +110,7 @@ int TransposeOpenCLKernel::Prepare() { std::string source = transpose_source; std::string program_name = "transpose"; ocl_runtime_->LoadSource(program_name, source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options_ext); #endif SetConstArgs(); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/winograd.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/winograd.cc index 138aefe9cf..7973c27822 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/winograd.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/winograd.cc @@ -82,12 +82,7 @@ std::vector GenerateWinogradFilter(void *src, TypeId dtype, size_t CO, si void WinogradOpenCLKernel::BuildKernel() { std::string program_name = "winograd"; ocl_runtime_->LoadSource(program_name, GetActDefines() + winograd_source); - std::vector build_options_ext; - if (desc_.data_type == kNumberTypeFloat32) { - build_options_ext = {" -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; - } else if (desc_.data_type == kNumberTypeFloat16) { - build_options_ext = {" -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; - } + auto build_options_ext = CreateBuildOptionsExtByDType(desc_.data_type); ocl_runtime_->BuildKernel(kernel_4x4to36_, program_name, "Winograd4x4To36", build_options_ext); ocl_runtime_->BuildKernel(kernel_, program_name, filter_type_ == MemType::IMG ? "WinogradConv2D_Img" : "WinogradConv2D", build_options_ext); diff --git a/mindspore/lite/src/runtime/kernel/opencl/utils.cc b/mindspore/lite/src/runtime/kernel/opencl/utils.cc index 31c3842456..20c1d065b8 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/utils.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/utils.cc @@ -327,4 +327,15 @@ void FreeTmpWeight(lite::Tensor *tensor) { } } +std::vector CreateBuildOptionsExtByDType(TypeId type_id) { + std::vector build_options_ext; + if (type_id == kNumberTypeInt32) { + build_options_ext = {" -DDTYPE=int -DDTYPE4=int4 -DWRITE_IMAGE=write_imagei -DREAD_IMAGE=read_imagei "}; + } else if (type_id == kNumberTypeFloat32) { + build_options_ext = {" -DDTYPE=float -DDTYPE4=float4 -DWRITE_IMAGE=write_imagef -DREAD_IMAGE=read_imagef "}; + } else if (type_id == kNumberTypeFloat16) { + build_options_ext = {" -DDTYPE=half -DDTYPE4=half4 -DWRITE_IMAGE=write_imageh -DREAD_IMAGE=read_imageh "}; + } + return build_options_ext; +} } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/opencl/utils.h b/mindspore/lite/src/runtime/kernel/opencl/utils.h index 254a61a7de..b4d64e8645 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/utils.h +++ b/mindspore/lite/src/runtime/kernel/opencl/utils.h @@ -67,6 +67,8 @@ int CheckParamLikeTensor(const std::string &kernel_name, const std::string &tens void StoreTmpWeight(lite::Tensor *tensor); void FreeTmpWeight(lite::Tensor *tensor); +std::vector CreateBuildOptionsExtByDType(TypeId type_id); + template void PackNCHWToNC4HW4(void *src, void *dst, int batch, int plane_in, int plane_out, int channel, const std::function &to_dtype) { diff --git a/mindspore/lite/test/models_gpu_fp32.cfg b/mindspore/lite/test/models_gpu_fp32.cfg index 2382d6091c..3a9b8070f0 100644 --- a/mindspore/lite/test/models_gpu_fp32.cfg +++ b/mindspore/lite/test/models_gpu_fp32.cfg @@ -99,3 +99,54 @@ Q_crnn_ori_75w_slim_norm.pb Q_crnn_ori_v2_405001_notrans_nopre.pb bolt_segment.pb ml_location_lane_counter.onnx;2 +gts_detect_5k_tf115.tflite +smartreply.tflite +ml_text_correction.tflite +ml_ocr_jk_pb2tflite.tflite +scan_hms_angle_pb2tflite.tflite +scan_hms_detect_pb2tflite.tflite +ml_face_openclose_tflite.tflite +unet_mbv2_05_104pts.tflite +hiai_AADB_HADB_MBV2_model_f16.tflite +hiai_AADB_HADB_MBV2_model_fp32.tflite +hiai_detect_curve_model_float32.tflite +hiai_detectmodel_06_23_960_480_1180700.tflite +lite-model_aiy_vision_classifier_food_V1_1.tflite +lite-model_disease-classification_1.tflite +lite-model_models_mushroom-identification_v1_1.tflite +smartreply_1_default_1.tflite +text_classification.tflite +Q_detect_fpn_add_inception-1448650.tflite +Q_hand_0812_pb2tflite.tflite +bloom_landmark.tflite +Q888_face_dress_mv3y.tflite +Q888_HADB_AADB_MBV2_model_fp32.tflite +Q888_landmark.tflite +Q888_pose.tflite +Q888_lapa158_unet_0924.tflite +Q888_isface.tflite +Q888_new_detect.tflite +Q888_model_normalize_object_scene_ps_20200826_f32_no_softmax.tflite +Q888_face_emo_dress_mv3_orderd.tflite +hdc_age_medium +hdc_contour_pose_128 +hdc_emotion +hdc_fivembnet +hdc_isface +hdc_mobilenetface +hdc_retinaface +hdc_resnet +mtk_model_normalize_object_scene_ps_20200519_f32.tflite +hiai_cpu_face_emotion.pb +hiai_cpu_face_gazing.pb +hiai_cpu_face_headpose.pb +hiai_ctpn_feature_map.pb +hiai_cv_focusShootOCRModel_02.pb +hiai_cv_focusShootOCRModel_08.pb +hiai_cv_poseEstimation.pb +hiai_detectmodel_06_23_960_480_1180700.pb +hiai_face_model_npu.pb +hiai_iMaxDN_RGB.pb +hiai_iMaxSR_RGB.pb +hiai_lm_inference_graph.pb +hiai_PoseEstimation_Pcm.pb