|
16 | 16 | using namespace cldnn;
|
17 | 17 | using namespace ::tests;
|
18 | 18 |
|
| 19 | +namespace cldnn { |
| 20 | +namespace { |
| 21 | + |
19 | 22 | TEST(shape_of_gpu, bfyx) {
|
20 | 23 | auto& engine = get_test_engine();
|
21 | 24 |
|
@@ -243,3 +246,83 @@ TEST(shape_of_gpu, shape_infer_optimization_dynamic) {
|
243 | 246 | }
|
244 | 247 | }
|
245 | 248 | }
|
| 249 | + |
| 250 | +struct shape_of_test_params { |
| 251 | + std::vector<std::vector<int64_t>> data; |
| 252 | + |
| 253 | + shape_of_test_params(std::initializer_list<std::vector<int64_t>> init) : data(init) {} |
| 254 | +}; |
| 255 | + |
| 256 | +std::ostream& operator<<(std::ostream& ost, const shape_of_test_params& params) { |
| 257 | + ost << "[" << params.data.size() << "] {"; |
| 258 | + for (auto& in_vec : params.data) { |
| 259 | + ost << "{"; |
| 260 | + for (auto& in : in_vec) { |
| 261 | + ost << std::to_string(in) << ","; |
| 262 | + } |
| 263 | + ost << "},"; |
| 264 | + } |
| 265 | + ost << "}"; |
| 266 | + return ost; |
| 267 | +} |
| 268 | + |
| 269 | +struct smoke_shape_of_test : testing::TestWithParam<shape_of_test_params> {}; |
| 270 | +TEST_P(smoke_shape_of_test, basic) { |
| 271 | + auto params = GetParam(); |
| 272 | + auto& engine = get_test_engine(); |
| 273 | + |
| 274 | + auto inputs = params.data; |
| 275 | + auto& first_input = inputs.front(); |
| 276 | + auto dims_size = first_input.size(); |
| 277 | + auto test_format = format::bfyx; |
| 278 | + if (dims_size == 5) { |
| 279 | + test_format = format::bzyxf; |
| 280 | + } else if (dims_size == 6) { |
| 281 | + test_format = format::bfwzyx; |
| 282 | + } else if (dims_size == 7) { |
| 283 | + test_format = format::bfuwzyx; |
| 284 | + } |
| 285 | + |
| 286 | + layout in_layout = {ov::PartialShape::dynamic(dims_size), data_types::f32, test_format}; |
| 287 | + |
| 288 | + cldnn::topology topology; |
| 289 | + topology.add(input_layout("input", in_layout)); |
| 290 | + topology.add(shape_of("shape_of", input_info("input"), data_types::i32)); |
| 291 | + |
| 292 | + ExecutionConfig config = get_test_default_config(engine); |
| 293 | + config.set_property(ov::intel_gpu::allow_new_shape_infer(true)); |
| 294 | + network network(engine, topology, config); |
| 295 | + |
| 296 | + auto inst = network.get_primitive("shape_of"); |
| 297 | + auto impl = inst->get_impl(); |
| 298 | + ASSERT_TRUE(impl != nullptr); |
| 299 | + ASSERT_TRUE(impl->is_dynamic()); |
| 300 | + |
| 301 | + for (const auto& input : inputs) { |
| 302 | + layout in_mem_layout = {input, data_types::f32, test_format}; |
| 303 | + auto input_mem = engine.allocate_memory(in_mem_layout); |
| 304 | + network.set_input_data("input", input_mem); |
| 305 | + |
| 306 | + auto outputs = network.execute(); |
| 307 | + |
| 308 | + auto output = outputs.at("shape_of").get_memory(); |
| 309 | + cldnn::mem_lock<int32_t> output_ptr(output, get_test_stream()); |
| 310 | + |
| 311 | + for (size_t i = 0; i < input.size(); ++i) { |
| 312 | + ASSERT_EQ(input[i], output_ptr[i]); |
| 313 | + } |
| 314 | + } |
| 315 | +} |
| 316 | + |
| 317 | + |
| 318 | +INSTANTIATE_TEST_SUITE_P(shape_of_gpu, |
| 319 | + smoke_shape_of_test, |
| 320 | + testing::Values( |
| 321 | + shape_of_test_params({{1,2,3,4}, {3,2,4,1}, {5,8,2,1}, {4,6,2,1}}), |
| 322 | + shape_of_test_params({{5,4,3,2,1}, {2,3,6,3,1}, {8,2,1,1,3}, {9,4,3,7,8}}), |
| 323 | + shape_of_test_params({{8,1,3,4,5,2}, {9,2,4,3,6,8}, {2,5,3,7,8,1}, {9,4,7,2,8,1}}), |
| 324 | + shape_of_test_params({{4,2,5,6,7,3,8}, {1,9,8,2,3,4,6}, {9,2,4,6,8,7,1}, {9,1,8,2,3,6,7}}) |
| 325 | + )); |
| 326 | + |
| 327 | +} // namespace |
| 328 | +} // namespace cldnn |
0 commit comments