|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
| 9 | +#include <detail/device_impl.hpp> |
9 | 10 | #include <detail/kernel_bundle_impl.hpp>
|
10 | 11 | #include <sycl/sycl.hpp>
|
11 | 12 |
|
@@ -459,3 +460,80 @@ TEST(KernelBundle, EmptyDevicesKernelBundleLinkException) {
|
459 | 460 | FAIL() << "Unexpected exception was thrown in sycl::link.";
|
460 | 461 | }
|
461 | 462 | }
|
| 463 | + |
| 464 | +pi_device ParentDevice = nullptr; |
| 465 | +pi_platform PiPlatform = nullptr; |
| 466 | + |
| 467 | +pi_result redefinedDeviceGetInfoAfter(pi_device device, |
| 468 | + pi_device_info param_name, |
| 469 | + size_t param_value_size, |
| 470 | + void *param_value, |
| 471 | + size_t *param_value_size_ret) { |
| 472 | + if (param_name == PI_DEVICE_INFO_PARTITION_PROPERTIES) { |
| 473 | + if (param_value) { |
| 474 | + auto *Result = |
| 475 | + reinterpret_cast<pi_device_partition_property *>(param_value); |
| 476 | + *Result = PI_DEVICE_PARTITION_EQUALLY; |
| 477 | + } |
| 478 | + if (param_value_size_ret) |
| 479 | + *param_value_size_ret = sizeof(pi_device_partition_property); |
| 480 | + } else if (param_name == PI_DEVICE_INFO_MAX_COMPUTE_UNITS) { |
| 481 | + auto *Result = reinterpret_cast<pi_uint32 *>(param_value); |
| 482 | + *Result = 2; |
| 483 | + } else if (param_name == PI_DEVICE_INFO_PARENT_DEVICE) { |
| 484 | + auto *Result = reinterpret_cast<pi_device *>(param_value); |
| 485 | + *Result = (device == ParentDevice) ? nullptr : ParentDevice; |
| 486 | + } else if (param_name == PI_DEVICE_INFO_PLATFORM) { |
| 487 | + auto *Result = reinterpret_cast<pi_platform *>(param_value); |
| 488 | + *Result = PiPlatform; |
| 489 | + } |
| 490 | + return PI_SUCCESS; |
| 491 | +} |
| 492 | + |
| 493 | +pi_result redefinedDevicePartitionAfter( |
| 494 | + pi_device device, const pi_device_partition_property *properties, |
| 495 | + pi_uint32 num_devices, pi_device *out_devices, pi_uint32 *out_num_devices) { |
| 496 | + if (out_devices) { |
| 497 | + for (size_t I = 0; I < num_devices; ++I) { |
| 498 | + out_devices[I] = reinterpret_cast<pi_device>(1000 + I); |
| 499 | + } |
| 500 | + } |
| 501 | + if (out_num_devices) |
| 502 | + *out_num_devices = num_devices; |
| 503 | + return PI_SUCCESS; |
| 504 | +} |
| 505 | + |
| 506 | +TEST(KernelBundle, DescendentDevice) { |
| 507 | + // Mock a non-OpenCL plugin since use of descendent devices of context members |
| 508 | + // is not supported there yet. |
| 509 | + sycl::unittest::PiMock Mock(sycl::backend::level_zero); |
| 510 | + |
| 511 | + sycl::platform Plt = Mock.getPlatform(); |
| 512 | + |
| 513 | + PiPlatform = sycl::detail::getSyclObjImpl(Plt)->getHandleRef(); |
| 514 | + |
| 515 | + Mock.redefineAfter<sycl::detail::PiApiKind::piDeviceGetInfo>( |
| 516 | + redefinedDeviceGetInfoAfter); |
| 517 | + Mock.redefineAfter<sycl::detail::PiApiKind::piDevicePartition>( |
| 518 | + redefinedDevicePartitionAfter); |
| 519 | + |
| 520 | + const sycl::device Dev = Mock.getPlatform().get_devices()[0]; |
| 521 | + ParentDevice = sycl::detail::getSyclObjImpl(Dev)->getHandleRef(); |
| 522 | + sycl::context Ctx{Dev}; |
| 523 | + sycl::device Subdev = |
| 524 | + Dev.create_sub_devices<sycl::info::partition_property::partition_equally>( |
| 525 | + 2)[0]; |
| 526 | + |
| 527 | + sycl::queue Queue{Ctx, Subdev}; |
| 528 | + |
| 529 | + sycl::kernel_bundle<sycl::bundle_state::executable> KernelBundle = |
| 530 | + sycl::get_kernel_bundle<sycl::bundle_state::executable>(Ctx, {Subdev}); |
| 531 | + |
| 532 | + sycl::kernel Kernel = |
| 533 | + KernelBundle.get_kernel(sycl::get_kernel_id<TestKernel>()); |
| 534 | + |
| 535 | + sycl::kernel_bundle<sycl::bundle_state::executable> RetKernelBundle = |
| 536 | + Kernel.get_kernel_bundle(); |
| 537 | + |
| 538 | + EXPECT_EQ(KernelBundle, RetKernelBundle); |
| 539 | +} |
0 commit comments