Skip to content

Commit

Permalink
[SYCL][NFC] Detach unit-tests naming from UR (#14815)
Browse files Browse the repository at this point in the history
This is a follow-up from #14145. Our unit tests have mock classes
corresponding to device images and other entries our compiler generates.
They are all named using `Ur` prefix, but they have nothing to do with
Unified Runtime, they are part of our compiler interface.

This patch renames associated files and classes so they do not refer to
`Ur` anymore.
This is a mechanical find-and-replace change.
  • Loading branch information
AlexeySachkov authored Nov 5, 2024
1 parent 4a274fc commit eded703
Show file tree
Hide file tree
Showing 24 changed files with 337 additions and 322 deletions.
32 changes: 16 additions & 16 deletions sycl/unittests/Extensions/DeviceGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "detail/context_impl.hpp"
#include "detail/kernel_program_cache.hpp"

#include <helpers/MockDeviceImage.hpp>
#include <helpers/MockKernelInfo.hpp>
#include <helpers/UrImage.hpp>
#include <helpers/UrMock.hpp>

#include <gtest/gtest.h>
Expand Down Expand Up @@ -53,29 +53,29 @@ struct KernelInfo<DeviceGlobalImgScopeTestKernel>
} // namespace _V1
} // namespace sycl

static sycl::unittest::UrImage generateDeviceGlobalImage() {
static sycl::unittest::MockDeviceImage generateDeviceGlobalImage() {
using namespace sycl::unittest;

// Call device global map initializer explicitly to mimic the integration
// header.
sycl::detail::device_global_map::add(&DeviceGlobal, DeviceGlobalName);

// Insert remaining device global info into the binary.
UrPropertySet PropSet;
UrProperty DevGlobInfo =
MockPropertySet PropSet;
MockProperty DevGlobInfo =
makeDeviceGlobalInfo(DeviceGlobalName, sizeof(int) * 2, 0);
PropSet.insert(__SYCL_PROPERTY_SET_SYCL_DEVICE_GLOBALS,
std::vector<UrProperty>{std::move(DevGlobInfo)});
std::vector<MockProperty>{std::move(DevGlobInfo)});

std::vector<UrOffloadEntry> Entries =
std::vector<MockOffloadEntry> Entries =
makeEmptyKernels({DeviceGlobalTestKernelName});

UrImage Img(std::move(Entries), std::move(PropSet));
MockDeviceImage Img(std::move(Entries), std::move(PropSet));

return Img;
}

static sycl::unittest::UrImage generateDeviceGlobalImgScopeImage() {
static sycl::unittest::MockDeviceImage generateDeviceGlobalImgScopeImage() {
using namespace sycl::unittest;

// Call device global map initializer explicitly to mimic the integration
Expand All @@ -84,24 +84,24 @@ static sycl::unittest::UrImage generateDeviceGlobalImgScopeImage() {
DeviceGlobalImgScopeName);

// Insert remaining device global info into the binary.
UrPropertySet PropSet;
UrProperty DevGlobInfo =
MockPropertySet PropSet;
MockProperty DevGlobInfo =
makeDeviceGlobalInfo(DeviceGlobalImgScopeName, sizeof(int) * 2, 1);
PropSet.insert(__SYCL_PROPERTY_SET_SYCL_DEVICE_GLOBALS,
std::vector<UrProperty>{std::move(DevGlobInfo)});
std::vector<MockProperty>{std::move(DevGlobInfo)});

std::vector<UrOffloadEntry> Entries =
std::vector<MockOffloadEntry> Entries =
makeEmptyKernels({DeviceGlobalImgScopeTestKernelName});

UrImage Img(std::move(Entries), std::move(PropSet));
MockDeviceImage Img(std::move(Entries), std::move(PropSet));

return Img;
}

namespace {
sycl::unittest::UrImage Imgs[] = {generateDeviceGlobalImage(),
generateDeviceGlobalImgScopeImage()};
sycl::unittest::UrImageArray<2> ImgArray{Imgs};
sycl::unittest::MockDeviceImage Imgs[] = {generateDeviceGlobalImage(),
generateDeviceGlobalImgScopeImage()};
sycl::unittest::MockDeviceImageArray<2> ImgArray{Imgs};

// Trackers.
thread_local DeviceGlobalElemType MockDeviceGlobalMem;
Expand Down
6 changes: 3 additions & 3 deletions sycl/unittests/Extensions/USMMemcpy2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include <detail/queue_impl.hpp>

#include <helpers/MockDeviceImage.hpp>
#include <helpers/MockKernelInfo.hpp>
#include <helpers/UrImage.hpp>
#include <helpers/UrMock.hpp>

#include <gtest/gtest.h>
Expand Down Expand Up @@ -126,10 +126,10 @@ struct KernelInfo<class __usmmemcpy2d<unsigned char>>
} // namespace sycl

namespace {
sycl::unittest::UrImage Imgs[] = {sycl::unittest::generateDefaultImage(
sycl::unittest::MockDeviceImage Imgs[] = {sycl::unittest::generateDefaultImage(
{USMFillHelperKernelNameLong, USMFillHelperKernelNameChar,
USMMemcpyHelperKernelNameLong, USMMemcpyHelperKernelNameChar})};
sycl::unittest::UrImageArray<1> ImgArray{Imgs};
sycl::unittest::MockDeviceImageArray<1> ImgArray{Imgs};

ur_context_info_t LastMemopsQuery = UR_CONTEXT_INFO_NUM_DEVICES;

Expand Down
20 changes: 10 additions & 10 deletions sycl/unittests/Extensions/VirtualFunctions/RuntimeLinking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include "ur_mock_helpers.hpp"
#include <sycl/sycl.hpp>

#include <helpers/MockDeviceImage.hpp>
#include <helpers/MockKernelInfo.hpp>
#include <helpers/RuntimeLinkingCommon.hpp>
#include <helpers/UrImage.hpp>
#include <helpers/UrMock.hpp>

#include <gtest/gtest.h>
Expand Down Expand Up @@ -46,11 +46,11 @@ KERNEL_INFO(KernelG)
} // namespace _V1
} // namespace sycl

static sycl::unittest::UrImage
static sycl::unittest::MockDeviceImage
generateImage(std::initializer_list<std::string> KernelNames,
const std::string &VFSets, bool UsesVFSets, unsigned char Magic) {
sycl::unittest::UrPropertySet PropSet;
std::vector<sycl::unittest::UrProperty> Props;
sycl::unittest::MockPropertySet PropSet;
std::vector<sycl::unittest::MockProperty> Props;
uint64_t PropSize = VFSets.size();
std::vector<char> Storage(/* bytes for size */ 8 + PropSize +
/* null terminator */ 1);
Expand All @@ -61,18 +61,18 @@ generateImage(std::initializer_list<std::string> KernelNames,
Storage.back() = '\0';
const std::string PropName =
UsesVFSets ? "uses-virtual-functions-set" : "virtual-functions-set";
sycl::unittest::UrProperty Prop(PropName, Storage,
SYCL_PROPERTY_TYPE_BYTE_ARRAY);
sycl::unittest::MockProperty Prop(PropName, Storage,
SYCL_PROPERTY_TYPE_BYTE_ARRAY);

Props.push_back(Prop);
PropSet.insert(__SYCL_PROPERTY_SET_SYCL_VIRTUAL_FUNCTIONS, std::move(Props));

std::vector<unsigned char> Bin{Magic};

std::vector<sycl::unittest::UrOffloadEntry> Entries =
std::vector<sycl::unittest::MockOffloadEntry> Entries =
sycl::unittest::makeEmptyKernels(KernelNames);

sycl::unittest::UrImage Img{
sycl::unittest::MockDeviceImage Img{
SYCL_DEVICE_BINARY_TYPE_SPIRV, // Format
__SYCL_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec
"", // Compile options
Expand Down Expand Up @@ -103,7 +103,7 @@ static constexpr unsigned PROGRAM_F1 = 53;
// Device images with no entires are ignored by SYCL RT during registration.
// Therefore, we have to provide some kernel names to make the test work, even
// if we don't really have them/use them.
static sycl::unittest::UrImage Imgs[] = {
static sycl::unittest::MockDeviceImage Imgs[] = {
generateImage({"KernelA"}, "set-a", /* uses vf set */ true, PROGRAM_A),
generateImage({"DummyKernel0"}, "set-a", /* provides vf set */ false,
PROGRAM_A0),
Expand Down Expand Up @@ -131,7 +131,7 @@ static sycl::unittest::UrImage Imgs[] = {
generateImage({"KernelG"}, "set-f", /* uses vf set */ true, PROGRAM_F1)};

// Registers mock devices images in the SYCL RT
static sycl::unittest::UrImageArray<15> ImgArray{Imgs};
static sycl::unittest::MockDeviceImageArray<15> ImgArray{Imgs};

TEST(VirtualFunctions, SingleKernelUsesSingleVFSet) {
sycl::unittest::UrMock<> Mock;
Expand Down
6 changes: 3 additions & 3 deletions sycl/unittests/Extensions/WorkGroupMemoryBackendArgument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#include <gtest/gtest.h>
#include <helpers/UrImage.hpp>
#include <helpers/MockDeviceImage.hpp>
#include <helpers/UrMock.hpp>
#include <sycl/sycl.hpp>

Expand Down Expand Up @@ -38,9 +38,9 @@ template <> struct KernelInfo<WorkGroupMemoryKernel> {
} // namespace _V1
} // namespace sycl

static sycl::unittest::UrImage Img =
static sycl::unittest::MockDeviceImage Img =
sycl::unittest::generateDefaultImage({"WorkGroupMemoryKernel"});
static sycl::unittest::UrImageArray<1> ImgArray{&Img};
static sycl::unittest::MockDeviceImageArray<1> ImgArray{&Img};

static int urKernelSetArgLocalCalls = 0;
inline ur_result_t redefined_urKernelSetArgLocal(void *) {
Expand Down
14 changes: 7 additions & 7 deletions sycl/unittests/SYCL2020/IsCompatible.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <sycl/sycl.hpp>

#include <helpers/MockDeviceImage.hpp>
#include <helpers/MockKernelInfo.hpp>
#include <helpers/UrImage.hpp>
#include <helpers/UrMock.hpp>

#include <gtest/gtest.h>
Expand All @@ -22,22 +22,22 @@ MOCK_INTEGRATION_HEADER(TestKernelCPUValidReqdWGSize3D)
MOCK_INTEGRATION_HEADER(TestKernelGPU)
MOCK_INTEGRATION_HEADER(TestKernelACC)

static sycl::unittest::UrImage
static sycl::unittest::MockDeviceImage
generateDefaultImage(std::initializer_list<std::string> KernelNames,
const std::vector<sycl::aspect> &Aspects,
const std::vector<int> &ReqdWGSize = {}) {
using namespace sycl::unittest;

UrPropertySet PropSet;
MockPropertySet PropSet;
addDeviceRequirementsProps(PropSet, Aspects, ReqdWGSize);
std::vector<UrOffloadEntry> Entries = makeEmptyKernels(KernelNames);
std::vector<MockOffloadEntry> Entries = makeEmptyKernels(KernelNames);

UrImage Img(std::move(Entries), std::move(PropSet));
MockDeviceImage Img(std::move(Entries), std::move(PropSet));

return Img;
}

static sycl::unittest::UrImage Imgs[7] = {
static sycl::unittest::MockDeviceImage Imgs[7] = {
// Images for validating checks based on max_work_group_size + aspects
generateDefaultImage({"TestKernelCPU"}, {sycl::aspect::cpu},
{32}), // 32 <= 256 (OK)
Expand All @@ -56,7 +56,7 @@ static sycl::unittest::UrImage Imgs[7] = {
generateDefaultImage({"TestKernelGPU"}, {sycl::aspect::gpu}),
generateDefaultImage({"TestKernelACC"}, {sycl::aspect::accelerator})};

static sycl::unittest::UrImageArray<7> ImgArray{Imgs};
static sycl::unittest::MockDeviceImageArray<7> ImgArray{Imgs};

static ur_result_t redefinedDeviceGetInfoCPU(void *pParams) {
auto params = *static_cast<ur_device_get_info_params_t *>(pParams);
Expand Down
26 changes: 13 additions & 13 deletions sycl/unittests/SYCL2020/KernelBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <detail/kernel_bundle_impl.hpp>
#include <sycl/sycl.hpp>

#include <helpers/MockDeviceImage.hpp>
#include <helpers/MockKernelInfo.hpp>
#include <helpers/UrImage.hpp>
#include <helpers/UrMock.hpp>

#include <gtest/gtest.h>
Expand All @@ -24,33 +24,33 @@ MOCK_INTEGRATION_HEADER(TestKernel)
MOCK_INTEGRATION_HEADER(TestKernelExeOnly)
MOCK_INTEGRATION_HEADER(TestKernelWithAspects)

static sycl::unittest::UrImage
static sycl::unittest::MockDeviceImage
generateDefaultImage(std::initializer_list<std::string> KernelNames,
sycl_device_binary_type BinaryType,
const char *DeviceTargetSpec,
const std::vector<sycl::aspect> &Aspects = {}) {
using namespace sycl::unittest;

UrPropertySet PropSet;
MockPropertySet PropSet;
if (!Aspects.empty())
addDeviceRequirementsProps(PropSet, Aspects);

std::vector<unsigned char> Bin{0, 1, 2, 3, 4, 5}; // Random data

std::vector<UrOffloadEntry> Entries = makeEmptyKernels(KernelNames);
std::vector<MockOffloadEntry> Entries = makeEmptyKernels(KernelNames);

UrImage Img{BinaryType, // Format
DeviceTargetSpec,
"", // Compile options
"", // Link options
std::move(Bin),
std::move(Entries),
std::move(PropSet)};
MockDeviceImage Img{BinaryType, // Format
DeviceTargetSpec,
"", // Compile options
"", // Link options
std::move(Bin),
std::move(Entries),
std::move(PropSet)};

return Img;
}

static sycl::unittest::UrImage Imgs[] = {
static sycl::unittest::MockDeviceImage Imgs[] = {
generateDefaultImage({"TestKernel"}, SYCL_DEVICE_BINARY_TYPE_SPIRV,
__SYCL_DEVICE_BINARY_TARGET_SPIRV64),
generateDefaultImage({"TestKernelExeOnly"}, SYCL_DEVICE_BINARY_TYPE_NATIVE,
Expand All @@ -61,7 +61,7 @@ static sycl::unittest::UrImage Imgs[] = {
generateDefaultImage(
{"TestKernelWithAspects"}, SYCL_DEVICE_BINARY_TYPE_NATIVE,
__SYCL_DEVICE_BINARY_TARGET_SPIRV64, {sycl::aspect::gpu})};
static sycl::unittest::UrImageArray<std::size(Imgs)> ImgArray{Imgs};
static sycl::unittest::MockDeviceImageArray<std::size(Imgs)> ImgArray{Imgs};

static ur_result_t redefinedDeviceGetInfoCPU(void *pParams) {
auto params = *static_cast<ur_device_get_info_params_t *>(pParams);
Expand Down
26 changes: 13 additions & 13 deletions sycl/unittests/SYCL2020/KernelBundleStateFiltering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <detail/kernel_bundle_impl.hpp>
#include <sycl/sycl.hpp>

#include <helpers/MockDeviceImage.hpp>
#include <helpers/MockKernelInfo.hpp>
#include <helpers/UrImage.hpp>
#include <helpers/UrMock.hpp>

#include <gtest/gtest.h>
Expand All @@ -35,26 +35,26 @@ MOCK_INTEGRATION_HEADER(KernelE)
namespace {

std::set<const void *> TrackedImages;
sycl::unittest::UrImage
sycl::unittest::MockDeviceImage
generateDefaultImage(std::initializer_list<std::string> KernelNames,
sycl_device_binary_type BinaryType,
const char *DeviceTargetSpec) {
using namespace sycl::unittest;

UrPropertySet PropSet;
MockPropertySet PropSet;

static unsigned char NImage = 0;
std::vector<unsigned char> Bin{NImage++};

std::vector<UrOffloadEntry> Entries = makeEmptyKernels(KernelNames);
std::vector<MockOffloadEntry> Entries = makeEmptyKernels(KernelNames);

UrImage Img{BinaryType, // Format
DeviceTargetSpec,
"", // Compile options
"", // Link options
std::move(Bin),
std::move(Entries),
std::move(PropSet)};
MockDeviceImage Img{BinaryType, // Format
DeviceTargetSpec,
"", // Compile options
"", // Link options
std::move(Bin),
std::move(Entries),
std::move(PropSet)};
const void *BinaryPtr = Img.getBinaryPtr();
TrackedImages.insert(BinaryPtr);

Expand All @@ -69,7 +69,7 @@ generateDefaultImage(std::initializer_list<std::string> KernelNames,
// Image 5: input, KernelE
// Image 6: exe, KernelE
// Image 7: exe. KernelE
sycl::unittest::UrImage Imgs[] = {
sycl::unittest::MockDeviceImage Imgs[] = {
generateDefaultImage({"KernelA", "KernelB"}, SYCL_DEVICE_BINARY_TYPE_SPIRV,
__SYCL_DEVICE_BINARY_TARGET_SPIRV64),
generateDefaultImage({"KernelA"}, SYCL_DEVICE_BINARY_TYPE_NATIVE,
Expand All @@ -87,7 +87,7 @@ sycl::unittest::UrImage Imgs[] = {
generateDefaultImage({"KernelE"}, SYCL_DEVICE_BINARY_TYPE_NATIVE,
__SYCL_DEVICE_BINARY_TARGET_SPIRV64_X86_64)};

sycl::unittest::UrImageArray<std::size(Imgs)> ImgArray{Imgs};
sycl::unittest::MockDeviceImageArray<std::size(Imgs)> ImgArray{Imgs};
std::vector<unsigned char> UsedImageIndices;

void redefinedUrProgramCreateCommon(const void *bin) {
Expand Down
6 changes: 3 additions & 3 deletions sycl/unittests/SYCL2020/KernelID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <sycl/sycl.hpp>

#include <helpers/MockDeviceImage.hpp>
#include <helpers/MockKernelInfo.hpp>
#include <helpers/UrImage.hpp>
#include <helpers/UrMock.hpp>

#include <gtest/gtest.h>
Expand Down Expand Up @@ -47,13 +47,13 @@ struct KernelInfo<ServiceKernel1> : public unittest::MockKernelInfoBase {
} // namespace _V1
} // namespace sycl

static sycl::unittest::UrImage Imgs[2] = {
static sycl::unittest::MockDeviceImage Imgs[2] = {
sycl::unittest::generateDefaultImage(
{"KernelID_TestKernel1", "KernelID_TestKernel3"}),
sycl::unittest::generateDefaultImage(
{"KernelID_TestKernel2",
"_ZTSN2cl4sycl6detail23__sycl_service_kernel__14ServiceKernel1"})};
static sycl::unittest::UrImageArray<2> ImgArray{Imgs};
static sycl::unittest::MockDeviceImageArray<2> ImgArray{Imgs};

TEST(KernelID, AllProgramKernelIds) {
std::vector<sycl::kernel_id> AllKernelIDs = sycl::get_kernel_ids();
Expand Down
Loading

0 comments on commit eded703

Please sign in to comment.