|
| 1 | +//==-------------------------- KernelInfoShortcuts.cpp -------------------==// |
| 2 | +// |
| 3 | +// Unit test to ensure get_kernel_info for a device queries/uses kernel bundle |
| 4 | +// for that specific device only and doesn't trigger builds for all devices. |
| 5 | +// |
| 6 | + |
| 7 | +#include <helpers/MockDeviceImage.hpp> |
| 8 | +#include <helpers/MockKernelInfo.hpp> |
| 9 | +#include <helpers/ScopedEnvVar.hpp> |
| 10 | +#include <helpers/UrMock.hpp> |
| 11 | +#include <sycl/sycl.hpp> |
| 12 | + |
| 13 | +#include <gtest/gtest.h> |
| 14 | + |
| 15 | +using namespace sycl; |
| 16 | +using namespace sycl::unittest; |
| 17 | + |
| 18 | +class ShortcutKernelInfoTestKernel; |
| 19 | +MOCK_INTEGRATION_HEADER(ShortcutKernelInfoTestKernel) |
| 20 | + |
| 21 | +static int ProgramBuildCounter = 0; |
| 22 | +static ur_result_t redefinedurProgramBuild(void *pParams) { |
| 23 | + ++ProgramBuildCounter; |
| 24 | + return UR_RESULT_SUCCESS; |
| 25 | +} |
| 26 | + |
| 27 | +static ur_result_t redefinedDeviceGet(void *pParams) { |
| 28 | + auto params = *static_cast<ur_device_get_params_t *>(pParams); |
| 29 | + if (*params.ppNumDevices) { |
| 30 | + **params.ppNumDevices = 2; // two devices total |
| 31 | + return UR_RESULT_SUCCESS; |
| 32 | + } |
| 33 | + if (*params.pphDevices) { |
| 34 | + // provide two mock device handles |
| 35 | + (*params.pphDevices)[0] = reinterpret_cast<ur_device_handle_t>(0x1); |
| 36 | + (*params.pphDevices)[1] = reinterpret_cast<ur_device_handle_t>(0x2); |
| 37 | + } |
| 38 | + return UR_RESULT_SUCCESS; |
| 39 | +} |
| 40 | + |
| 41 | +ur_result_t redefinedurKernelGetGroupInfo(void *pParams) { |
| 42 | + return UR_RESULT_SUCCESS; |
| 43 | +} |
| 44 | + |
| 45 | +TEST(ShortcutKernelInfo, QueryInfoForSingleDevice) { |
| 46 | + unittest::UrMock<> Mock; |
| 47 | + static sycl::unittest::MockDeviceImage DevImage = |
| 48 | + sycl::unittest::generateDefaultImage({"ShortcutKernelInfoTestKernel"}); |
| 49 | + static sycl::unittest::MockDeviceImageArray<1> DevImageArray = {&DevImage}; |
| 50 | + |
| 51 | + mock::getCallbacks().set_replace_callback("urDeviceGet", &redefinedDeviceGet); |
| 52 | + mock::getCallbacks().set_replace_callback("urProgramBuildExp", |
| 53 | + &redefinedurProgramBuild); |
| 54 | + mock::getCallbacks().set_replace_callback("urKernelGetGroupInfo", |
| 55 | + &redefinedurKernelGetGroupInfo); |
| 56 | + |
| 57 | + platform Plt = platform(); |
| 58 | + std::vector<device> Devs = Plt.get_devices(); |
| 59 | + ASSERT_GE(Devs.size(), 2u) << "Test requires at least 2 devices"; |
| 60 | + context Ctx = context(Devs); |
| 61 | + queue Queue = queue(Ctx, Devs[0]); |
| 62 | + |
| 63 | + // Query kernel info for the first device only |
| 64 | + ProgramBuildCounter = 0; |
| 65 | + sycl::ext::oneapi::get_kernel_info< |
| 66 | + ShortcutKernelInfoTestKernel, |
| 67 | + sycl::info::kernel_device_specific::work_group_size>(Ctx, Devs[0]); |
| 68 | + sycl::ext::oneapi::get_kernel_info< |
| 69 | + ShortcutKernelInfoTestKernel, |
| 70 | + sycl::info::kernel_device_specific::work_group_size>(Queue); |
| 71 | + |
| 72 | + EXPECT_EQ(ProgramBuildCounter, 1); |
| 73 | +} |
0 commit comments