|
| 1 | + |
| 2 | +// Copyright (C) 2024 Intel Corporation |
| 3 | +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See LICENSE.TXT |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | + |
| 7 | +#include <uur/fixtures.h> |
| 8 | +#include <uur/raii.h> |
| 9 | + |
| 10 | +using urMultiDeviceProgramTest = uur::urMultiDeviceProgramTest; |
| 11 | + |
| 12 | +// Test binary sizes and binaries obtained from urProgramGetInfo when program is built for a subset of devices in the context. |
| 13 | +TEST_F(urMultiDeviceProgramTest, urMultiDeviceProgramGetInfo) { |
| 14 | + // Run test only for level zero backend which supports urProgramBuildExp. |
| 15 | + ur_platform_backend_t backend; |
| 16 | + ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND, |
| 17 | + sizeof(backend), &backend, nullptr)); |
| 18 | + if (backend != UR_PLATFORM_BACKEND_LEVEL_ZERO) { |
| 19 | + GTEST_SKIP(); |
| 20 | + } |
| 21 | + |
| 22 | + std::vector<ur_device_handle_t> associated_devices(devices.size()); |
| 23 | + ASSERT_SUCCESS( |
| 24 | + urProgramGetInfo(program, UR_PROGRAM_INFO_DEVICES, |
| 25 | + associated_devices.size() * sizeof(ur_device_handle_t), |
| 26 | + associated_devices.data(), nullptr)); |
| 27 | + |
| 28 | + // Build program for the first half of devices. |
| 29 | + auto subset = std::vector<ur_device_handle_t>( |
| 30 | + associated_devices.begin(), |
| 31 | + associated_devices.begin() + associated_devices.size() / 2); |
| 32 | + ASSERT_SUCCESS( |
| 33 | + urProgramBuildExp(program, subset.size(), subset.data(), nullptr)); |
| 34 | + |
| 35 | + std::vector<size_t> binary_sizes(associated_devices.size()); |
| 36 | + ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_BINARY_SIZES, |
| 37 | + binary_sizes.size() * sizeof(size_t), |
| 38 | + binary_sizes.data(), nullptr)); |
| 39 | + |
| 40 | + std::vector<std::vector<char>> binaries(associated_devices.size()); |
| 41 | + std::vector<char *> pointers(associated_devices.size()); |
| 42 | + for (size_t i = 0; i < associated_devices.size() / 2; i++) { |
| 43 | + ASSERT_NE(binary_sizes[i], 0); |
| 44 | + binaries[i].resize(binary_sizes[i]); |
| 45 | + pointers[i] = binaries[i].data(); |
| 46 | + } |
| 47 | + for (size_t i = associated_devices.size() / 2; |
| 48 | + i < associated_devices.size(); i++) { |
| 49 | + ASSERT_EQ(binary_sizes[i], 0); |
| 50 | + pointers[i] = binaries[i].data(); |
| 51 | + } |
| 52 | + |
| 53 | + ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_BINARIES, |
| 54 | + sizeof(uint8_t *) * pointers.size(), |
| 55 | + pointers.data(), nullptr)); |
| 56 | + for (size_t i = 0; i < associated_devices.size() / 2; i++) { |
| 57 | + ASSERT_NE(binaries[i].size(), 0); |
| 58 | + } |
| 59 | + for (size_t i = associated_devices.size() / 2; |
| 60 | + i < associated_devices.size(); i++) { |
| 61 | + ASSERT_EQ(binaries[i].size(), 0); |
| 62 | + } |
| 63 | +} |
0 commit comments