diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc index 5701ab1da5..3c918395dc 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/activation.cc @@ -43,6 +43,10 @@ using mindspore::schema::PrimitiveType_Activation; namespace mindspore::kernel { int ActivationOpenClKernel::Init() { + if (in_tensors_.size() != 1 || out_tensors_.size() != 1) { + MS_LOG(ERROR) << "Invalid input size: " << in_tensors_.size() << ", output size: " << out_tensors_.size(); + return RET_ERROR; + } std::map kernel_names{ {ActivationType_LEAKY_RELU, "LeakyRelu"}, {ActivationType_RELU, "Relu"}, {ActivationType_SIGMOID, "Sigmoid"}, {ActivationType_RELU6, "Relu6"}, {ActivationType_TANH, "Tanh"}, {ActivationType_SWISH, "Swish"}, diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc index af5d891475..31d1df4ecc 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc @@ -165,6 +165,10 @@ int ArithmeticOpenCLKernel::SetArgs() { } int ArithmeticOpenCLKernel::Init() { + if (in_tensors_.size() != 2 || out_tensors_.size() != 1) { + MS_LOG(ERROR) << "Invalid input size: " << in_tensors_.size() << ", output size: " << out_tensors_.size(); + return RET_ERROR; + } std::string kernel_name; auto *arithmetic_parameter = reinterpret_cast(op_parameter_); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc index 8ce376a204..9fe95ed2ab 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc @@ -39,6 +39,10 @@ constexpr size_t CI_TILE = C4NUM; constexpr size_t CO_TILE = C4NUM; int ConvolutionOpenCLKernel::Init() { + if ((in_tensors_.size() != 2 && in_tensors_.size() != 3) || out_tensors_.size() != 1) { + MS_LOG(ERROR) << "Invalid input size: " << in_tensors_.size() << ", output size: " << out_tensors_.size(); + return RET_ERROR; + } use_fp16_ = ocl_runtime_->GetFp16Enable(); sizeof_FLT_ = use_fp16_ ? sizeof(float16_t) : sizeof(float); 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 9cc826f945..14bb24fecc 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc @@ -42,6 +42,10 @@ using mindspore::schema::PrimitiveType_DepthwiseConv2D; namespace mindspore::kernel { int DepthwiseConv2dOpenCLKernel::Init() { + if ((in_tensors_.size() != 2 && in_tensors_.size() != 3) || out_tensors_.size() != 1) { + MS_LOG(ERROR) << "Invalid input size: " << in_tensors_.size() << ", output size: " << out_tensors_.size(); + return RET_ERROR; + } std::string kernel_name = "DepthwiseConv2d"; if (out_mem_type_ == OpenCLMemType::BUF) { kernel_name += "_BUF"; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc index a881860277..64466daf45 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/fullconnection.cc @@ -34,6 +34,10 @@ using mindspore::schema::PrimitiveType_FullConnection; namespace mindspore::kernel { int FullConnectionOpenCLKernel::Init() { + if ((in_tensors_.size() != 2 && in_tensors_.size() != 3) || out_tensors_.size() != 1) { + MS_LOG(ERROR) << "Invalid input size: " << in_tensors_.size() << ", output size: " << out_tensors_.size(); + return RET_ERROR; + } std::string kernel_name = "FullConnection_NHWC4"; auto param = reinterpret_cast(op_parameter_); transposeA = param->a_transpose_; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc index 254b4c6df7..ec5a751bdf 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc @@ -37,6 +37,10 @@ using mindspore::schema::PrimitiveType_Pooling; namespace mindspore { namespace kernel { int PoolingOpenCLKernel::Init() { + if (in_tensors_.size() != 1 || out_tensors_.size() != 1) { + MS_LOG(ERROR) << "Invalid input size: " << in_tensors_.size() << ", output size: " << out_tensors_.size(); + return RET_ERROR; + } std::string kernel_name; #ifndef PROGRAM_WITH_IL std::string source; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc index 9da40a502d..f386ec1d12 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/reshape.cc @@ -31,6 +31,10 @@ using mindspore::schema::PrimitiveType_Squeeze; namespace mindspore::kernel { int ReshapeOpenCLKernel::Init() { + if ((in_tensors_.size() != 1 && in_tensors_.size() != 2) || out_tensors_.size() != 1) { + MS_LOG(ERROR) << "Invalid input size: " << in_tensors_.size() << ", output size: " << out_tensors_.size(); + return RET_ERROR; + } std::string kernel_name = "reshape_NHWC4"; if (out_tensors_[0]->shape().size() != 2 && out_tensors_[0]->shape().size() != 4) { MS_LOG(ERROR) << "Reshape output size should in 2,4"; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc index 4147602d7a..f04caa5149 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc @@ -78,6 +78,10 @@ int SoftmaxOpenCLKernel::SetWorkGroupSize1x1() { } int SoftmaxOpenCLKernel::Init() { + if (in_tensors_.size() != 1 || out_tensors_.size() != 1) { + MS_LOG(ERROR) << "Invalid input size: " << in_tensors_.size() << ", output size: " << out_tensors_.size(); + return RET_ERROR; + } std::string kernel_name = "SoftMax"; std::string program_name = "SoftMax"; auto softmax_param = reinterpret_cast(op_parameter_); diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc index e744da8e13..fd7f0e87bc 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc @@ -34,6 +34,10 @@ using mindspore::schema::PrimitiveType_Transpose; namespace mindspore::kernel { int TransposeOpenCLKernel::Init() { + if ((in_tensors_.size() != 1 && in_tensors_.size() != 2) || out_tensors_.size() != 1) { + MS_LOG(ERROR) << "Invalid input size: " << in_tensors_.size() << ", output size: " << out_tensors_.size(); + return RET_ERROR; + } std::string kernel_name = "transpose"; enable_fp16_ = ocl_runtime_->GetFp16Enable(); auto param = reinterpret_cast(op_parameter_);