|
|
|
@@ -29,33 +29,23 @@ class TestReshapeOpenCL : public mindspore::CommonTest { |
|
|
|
TestReshapeOpenCL() {} |
|
|
|
}; |
|
|
|
|
|
|
|
void RunTestCaseReshape(const std::vector<int> &shape, void *input_data, void *output_data, bool enable_fp16, |
|
|
|
bool is_output_2d) { |
|
|
|
void RunTestCaseReshape(const std::vector<int> &shape_in, const std::vector<int> &shape_out, void *input_data, |
|
|
|
void *output_data, bool enable_fp16) { |
|
|
|
auto ocl_runtime = lite::opencl::OpenCLRuntimeWrapper().GetInstance(); |
|
|
|
ocl_runtime->Init(); |
|
|
|
size_t dtype_size = enable_fp16 ? sizeof(float16_t) : sizeof(float); |
|
|
|
ocl_runtime->SetFp16Enable(enable_fp16); |
|
|
|
auto allocator = ocl_runtime->GetAllocator(); |
|
|
|
int n = shape[0]; |
|
|
|
int h = shape[1]; |
|
|
|
int w = shape[2]; |
|
|
|
int c = shape[3]; |
|
|
|
int oh = shape[4]; |
|
|
|
int ow = shape[5]; |
|
|
|
std::vector<int> input_shape = {n, h, w, c}; |
|
|
|
auto tensor_x_ptr = std::make_unique<lite::Tensor>(TypeId(enable_fp16 ? kNumberTypeFloat16 : kNumberTypeFloat32), |
|
|
|
input_shape, schema::Format_NHWC); |
|
|
|
shape_in, schema::Format_NHWC); |
|
|
|
auto tensor_x = tensor_x_ptr.get(); |
|
|
|
if (tensor_x == nullptr) { |
|
|
|
MS_LOG(ERROR) << "tensor_x create error."; |
|
|
|
return; |
|
|
|
} |
|
|
|
std::vector<int> out_shape = {n, oh, ow, c}; |
|
|
|
if (is_output_2d) { |
|
|
|
out_shape = {n, h * w * c}; |
|
|
|
} |
|
|
|
bool is_output_2d = shape_out.size() == 2; |
|
|
|
auto tensor_out_ptr = |
|
|
|
std::make_unique<lite::Tensor>(TypeId(enable_fp16 ? kNumberTypeFloat16 : kNumberTypeFloat32), out_shape, |
|
|
|
std::make_unique<lite::Tensor>(TypeId(enable_fp16 ? kNumberTypeFloat16 : kNumberTypeFloat32), shape_out, |
|
|
|
is_output_2d ? schema::Format_NC : schema::Format_NHWC); |
|
|
|
auto tensor_out = tensor_out_ptr.get(); |
|
|
|
if (tensor_out == nullptr) { |
|
|
|
@@ -102,74 +92,108 @@ void RunTestCaseReshape(const std::vector<int> &shape, void *input_data, void *o |
|
|
|
} |
|
|
|
|
|
|
|
TEST_F(TestReshapeOpenCL, ReshapeFp32) { |
|
|
|
int n = 1; |
|
|
|
int h = 1; |
|
|
|
int w = 1; |
|
|
|
int c = 7; |
|
|
|
int oh = 1; |
|
|
|
int ow = 1; |
|
|
|
std::vector<int> shape = {n, h, w, c, oh, ow}; |
|
|
|
std::vector<int> shape_in = {1, 1, 1, 7}; |
|
|
|
std::vector<int> shape_out = {1, 7}; |
|
|
|
std::vector<float> input_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; |
|
|
|
std::vector<float> output_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape, input_data.data(), output_data.data(), false, true); |
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), false); |
|
|
|
} |
|
|
|
|
|
|
|
TEST_F(TestReshapeOpenCL, ReshapeFp16) { |
|
|
|
int n = 1; |
|
|
|
int h = 1; |
|
|
|
int w = 1; |
|
|
|
int c = 7; |
|
|
|
int oh = 1; |
|
|
|
int ow = 1; |
|
|
|
std::vector<int> shape = {n, h, w, c, oh, ow}; |
|
|
|
std::vector<int> shape_in = {1, 1, 1, 7}; |
|
|
|
std::vector<int> shape_out = {1, 7}; |
|
|
|
std::vector<float16_t> input_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; |
|
|
|
std::vector<float16_t> output_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape, input_data.data(), output_data.data(), true, true); |
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), true); |
|
|
|
} |
|
|
|
|
|
|
|
TEST_F(TestReshapeOpenCL, Reshape4DFp32) { |
|
|
|
int n = 1; |
|
|
|
int h = 2; |
|
|
|
int w = 2; |
|
|
|
int c = 3; |
|
|
|
int oh = 1; |
|
|
|
int ow = 4; |
|
|
|
std::vector<int> shape = {n, h, w, c, oh, ow}; |
|
|
|
std::vector<int> shape_in = {1, 2, 2, 3}; |
|
|
|
std::vector<int> shape_out = {1, 1, 4, 3}; |
|
|
|
std::vector<float> input_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f}; |
|
|
|
std::vector<float> output_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape, input_data.data(), output_data.data(), false, false); |
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), false); |
|
|
|
} |
|
|
|
|
|
|
|
TEST_F(TestReshapeOpenCL, Reshape4DFp16) { |
|
|
|
int n = 1; |
|
|
|
int h = 2; |
|
|
|
int w = 2; |
|
|
|
int c = 3; |
|
|
|
int oh = 1; |
|
|
|
int ow = 4; |
|
|
|
std::vector<int> shape = {n, h, w, c, oh, ow}; |
|
|
|
std::vector<int> shape_in = {1, 2, 2, 3}; |
|
|
|
std::vector<int> shape_out = {1, 1, 4, 3}; |
|
|
|
std::vector<float16_t> input_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f}; |
|
|
|
std::vector<float16_t> output_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape, input_data.data(), output_data.data(), true, false); |
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), true); |
|
|
|
} |
|
|
|
|
|
|
|
TEST_F(TestReshapeOpenCL, Reshape4D2DFp32) { |
|
|
|
int n = 1; |
|
|
|
int h = 2; |
|
|
|
int w = 2; |
|
|
|
int c = 4; |
|
|
|
int oh = 2; |
|
|
|
int ow = 2; |
|
|
|
std::vector<int> shape = {n, h, w, c, oh, ow}; |
|
|
|
std::vector<int> shape_in = {1, 2, 2, 4}; |
|
|
|
std::vector<int> shape_out = {4, 4}; |
|
|
|
std::vector<float> input_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, |
|
|
|
8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; |
|
|
|
std::vector<float> output_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, |
|
|
|
8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape, input_data.data(), output_data.data(), false, true); |
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), false); |
|
|
|
} |
|
|
|
TEST_F(TestReshapeOpenCL, Reshape4DFp32Rem10) { |
|
|
|
std::vector<int> shape_in = {1, 3, 2, 4}; |
|
|
|
std::vector<int> shape_out = {1, 4, 2, 3}; |
|
|
|
std::vector<float> input_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, |
|
|
|
12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f}; |
|
|
|
std::vector<float> output_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, |
|
|
|
12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), false); |
|
|
|
} |
|
|
|
TEST_F(TestReshapeOpenCL, Reshape4DFp32Rem01Test0) { |
|
|
|
std::vector<int> shape_in = {1, 4, 2, 3}; |
|
|
|
std::vector<int> shape_out = {1, 3, 2, 4}; |
|
|
|
std::vector<float> input_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, |
|
|
|
12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f}; |
|
|
|
std::vector<float> output_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, |
|
|
|
12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), false); |
|
|
|
} |
|
|
|
TEST_F(TestReshapeOpenCL, Reshape4DFp32Rem01Test1) { |
|
|
|
std::vector<int> shape_in = {1, 2, 2, 5}; |
|
|
|
std::vector<int> shape_out = {1, 1, 5, 4}; |
|
|
|
std::vector<float> input_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, |
|
|
|
10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f}; |
|
|
|
std::vector<float> output_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, |
|
|
|
10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), false); |
|
|
|
} |
|
|
|
TEST_F(TestReshapeOpenCL, Reshape4DFp32Rem01Test2) { |
|
|
|
std::vector<int> shape_in = {1, 4, 2, 5}; |
|
|
|
std::vector<int> shape_out = {1, 2, 5, 4}; |
|
|
|
std::vector<float> input_data = { |
|
|
|
0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, |
|
|
|
14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, |
|
|
|
28.0f, 29.0f, 30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f, |
|
|
|
}; |
|
|
|
std::vector<float> output_data = { |
|
|
|
0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, |
|
|
|
14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, |
|
|
|
28.0f, 29.0f, 30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f, |
|
|
|
}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), false); |
|
|
|
} |
|
|
|
TEST_F(TestReshapeOpenCL, Reshape4DFp32Rem11) { |
|
|
|
std::vector<int> shape_in = {1, 3, 2, 5}; |
|
|
|
std::vector<int> shape_out = {1, 5, 2, 3}; |
|
|
|
std::vector<float> input_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, |
|
|
|
10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, |
|
|
|
20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f}; |
|
|
|
std::vector<float> output_data = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, |
|
|
|
10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, |
|
|
|
20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f}; |
|
|
|
|
|
|
|
RunTestCaseReshape(shape_in, shape_out, input_data.data(), output_data.data(), false); |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace mindspore |