Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UR] Consolidate platform and adapter backend enums into one. #17605

Open
wants to merge 3 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions sycl/source/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ static const AdapterPtr &getAdapter(backend Backend) {
}
}

backend convertUrBackend(ur_platform_backend_t UrBackend) {
backend convertUrBackend(ur_backend_t UrBackend) {
switch (UrBackend) {
case UR_PLATFORM_BACKEND_UNKNOWN:
case UR_BACKEND_UNKNOWN:
return backend::all; // No specific backend
case UR_PLATFORM_BACKEND_LEVEL_ZERO:
case UR_BACKEND_LEVEL_ZERO:
return backend::ext_oneapi_level_zero;
case UR_PLATFORM_BACKEND_OPENCL:
case UR_BACKEND_OPENCL:
return backend::opencl;
case UR_PLATFORM_BACKEND_CUDA:
case UR_BACKEND_CUDA:
return backend::ext_oneapi_cuda;
case UR_PLATFORM_BACKEND_HIP:
case UR_BACKEND_HIP:
return backend::ext_oneapi_hip;
case UR_PLATFORM_BACKEND_NATIVE_CPU:
case UR_BACKEND_NATIVE_CPU:
return backend::ext_oneapi_native_cpu;
default:
throw exception(make_error_code(errc::runtime),
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/platform_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ platform_impl::filterDeviceFilter(std::vector<ur_device_handle_t> &UrDevices,
std::vector<int> original_indices;

// Find out backend of the platform
ur_platform_backend_t UrBackend = UR_PLATFORM_BACKEND_UNKNOWN;
ur_backend_t UrBackend = UR_BACKEND_UNKNOWN;
MAdapter->call<UrApiKind::urPlatformGetInfo>(
MPlatform, UR_PLATFORM_INFO_BACKEND, sizeof(ur_platform_backend_t),
&UrBackend, nullptr);
MPlatform, UR_PLATFORM_INFO_BACKEND, sizeof(ur_backend_t), &UrBackend,
nullptr);
backend Backend = convertUrBackend(UrBackend);

int InsertIDx = 0;
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/platform_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class platform_impl {
const std::shared_ptr<Adapter> &AAdapter)
: MPlatform(APlatform), MAdapter(AAdapter) {
// Find out backend of the platform
ur_platform_backend_t UrBackend = UR_PLATFORM_BACKEND_UNKNOWN;
ur_backend_t UrBackend = UR_BACKEND_UNKNOWN;
AAdapter->call_nocheck<UrApiKind::urPlatformGetInfo>(
APlatform, UR_PLATFORM_INFO_BACKEND, sizeof(ur_platform_backend_t),
&UrBackend, nullptr);
APlatform, UR_PLATFORM_INFO_BACKEND, sizeof(ur_backend_t), &UrBackend,
nullptr);
MBackend = convertUrBackend(UrBackend);
}

Expand Down
14 changes: 7 additions & 7 deletions sycl/source/detail/ur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,17 @@ static void initializeAdapters(std::vector<AdapterPtr> &Adapters,
std::vector<ur_adapter_handle_t> adapters(adapterCount);
CHECK_UR_SUCCESS(adapterGet(adapterCount, adapters.data(), nullptr));

auto UrToSyclBackend = [](ur_adapter_backend_t backend) -> sycl::backend {
auto UrToSyclBackend = [](ur_backend_t backend) -> sycl::backend {
switch (backend) {
case UR_ADAPTER_BACKEND_LEVEL_ZERO:
case UR_BACKEND_LEVEL_ZERO:
return backend::ext_oneapi_level_zero;
case UR_ADAPTER_BACKEND_OPENCL:
case UR_BACKEND_OPENCL:
return backend::opencl;
case UR_ADAPTER_BACKEND_CUDA:
case UR_BACKEND_CUDA:
return backend::ext_oneapi_cuda;
case UR_ADAPTER_BACKEND_HIP:
case UR_BACKEND_HIP:
return backend::ext_oneapi_hip;
case UR_ADAPTER_BACKEND_NATIVE_CPU:
case UR_BACKEND_NATIVE_CPU:
return backend::ext_oneapi_native_cpu;
default:
// Throw an exception, this should be unreachable.
Expand All @@ -213,7 +213,7 @@ static void initializeAdapters(std::vector<AdapterPtr> &Adapters,
};

for (const auto &UrAdapter : adapters) {
ur_adapter_backend_t adapterBackend = UR_ADAPTER_BACKEND_UNKNOWN;
ur_backend_t adapterBackend = UR_BACKEND_UNKNOWN;
CHECK_UR_SUCCESS(adapterGetInfo(UrAdapter, UR_ADAPTER_INFO_BACKEND,
sizeof(adapterBackend), &adapterBackend,
nullptr));
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ template <backend BE> const AdapterPtr &getAdapter();
} // namespace ur

// Convert from UR backend to SYCL backend enum
backend convertUrBackend(ur_platform_backend_t UrBackend);
backend convertUrBackend(ur_backend_t UrBackend);

} // namespace detail
} // namespace _V1
Expand Down
2 changes: 1 addition & 1 deletion sycl/unittests/Extensions/FPGADeviceSelectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ template <const char PlatformName[]> struct RedefTemplatedWrapper {
return UR_RESULT_SUCCESS;
}
case UR_PLATFORM_INFO_BACKEND: {
constexpr auto MockPlatformBackend = UR_PLATFORM_BACKEND_UNKNOWN;
constexpr auto MockPlatformBackend = UR_BACKEND_UNKNOWN;
if (*params.ppPropValue) {
std::memcpy(*params.ppPropValue, &MockPlatformBackend,
sizeof(MockPlatformBackend));
Expand Down
48 changes: 14 additions & 34 deletions sycl/unittests/helpers/UrMock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ inline ur_result_t mock_urDeviceGet(void *pParams) {
inline ur_result_t mock_urDeviceRetain(void *) { return UR_RESULT_SUCCESS; }
inline ur_result_t mock_urDeviceRelease(void *) { return UR_RESULT_SUCCESS; }

template <ur_adapter_backend_t Backend>
template <ur_backend_t Backend>
inline ur_result_t mock_urAdapterGetInfo(void *pParams) {
auto params = reinterpret_cast<ur_adapter_get_info_params_t *>(pParams);

Expand All @@ -100,7 +100,7 @@ inline ur_result_t mock_urAdapterGetInfo(void *pParams) {
return UR_RESULT_SUCCESS;
}

template <ur_platform_backend_t Backend>
template <ur_backend_t Backend>
inline ur_result_t mock_urPlatformGetInfo(void *pParams) {
auto params = reinterpret_cast<ur_platform_get_info_params_t *>(pParams);
constexpr char MockPlatformName[] = "Mock platform";
Expand Down Expand Up @@ -556,16 +556,14 @@ template <sycl::backend Backend = backend::opencl> class UrMock {
#define ADD_DEFAULT_OVERRIDE(func_name, func_override) \
mock::getCallbacks().set_replace_callback(#func_name, \
&MockAdapter::func_override);
ADD_DEFAULT_OVERRIDE(
urAdapterGetInfo,
mock_urAdapterGetInfo<convertToUrAdapterBackend(Backend)>)
ADD_DEFAULT_OVERRIDE(urAdapterGetInfo,
mock_urAdapterGetInfo<convertToUrBackend(Backend)>)
ADD_DEFAULT_OVERRIDE(urPlatformGet, mock_urPlatformGet)
ADD_DEFAULT_OVERRIDE(urDeviceGet, mock_urDeviceGet)
ADD_DEFAULT_OVERRIDE(urDeviceRetain, mock_urDeviceRetain)
ADD_DEFAULT_OVERRIDE(urDeviceRelease, mock_urDeviceRelease)
ADD_DEFAULT_OVERRIDE(
urPlatformGetInfo,
mock_urPlatformGetInfo<convertToUrPlatformBackend(Backend)>)
ADD_DEFAULT_OVERRIDE(urPlatformGetInfo,
mock_urPlatformGetInfo<convertToUrBackend(Backend)>)
ADD_DEFAULT_OVERRIDE(urDeviceGetInfo, mock_urDeviceGetInfo)
ADD_DEFAULT_OVERRIDE(urProgramGetInfo, mock_urProgramGetInfo)
ADD_DEFAULT_OVERRIDE(urContextGetInfo, mock_urContextGetInfo)
Expand Down Expand Up @@ -619,39 +617,21 @@ template <sycl::backend Backend = backend::opencl> class UrMock {
private:
// These two helpers are needed to enable arbitrary backend selection
// at compile time.
static constexpr ur_platform_backend_t
convertToUrPlatformBackend(const sycl::backend SyclBackend) {
static constexpr ur_backend_t
convertToUrBackend(const sycl::backend SyclBackend) {
switch (SyclBackend) {
case sycl::backend::opencl:
return UR_PLATFORM_BACKEND_OPENCL;
return UR_BACKEND_OPENCL;
case sycl::backend::ext_oneapi_level_zero:
return UR_PLATFORM_BACKEND_LEVEL_ZERO;
return UR_BACKEND_LEVEL_ZERO;
case sycl::backend::ext_oneapi_cuda:
return UR_PLATFORM_BACKEND_CUDA;
return UR_BACKEND_CUDA;
case sycl::backend::ext_oneapi_hip:
return UR_PLATFORM_BACKEND_HIP;
return UR_BACKEND_HIP;
case sycl::backend::ext_oneapi_native_cpu:
return UR_PLATFORM_BACKEND_NATIVE_CPU;
return UR_BACKEND_NATIVE_CPU;
default:
return UR_PLATFORM_BACKEND_UNKNOWN;
}
}

static constexpr ur_adapter_backend_t
convertToUrAdapterBackend(sycl::backend SyclBackend) {
switch (SyclBackend) {
case sycl::backend::opencl:
return UR_ADAPTER_BACKEND_OPENCL;
case sycl::backend::ext_oneapi_level_zero:
return UR_ADAPTER_BACKEND_LEVEL_ZERO;
case sycl::backend::ext_oneapi_cuda:
return UR_ADAPTER_BACKEND_CUDA;
case sycl::backend::ext_oneapi_hip:
return UR_ADAPTER_BACKEND_HIP;
case sycl::backend::ext_oneapi_native_cpu:
return UR_ADAPTER_BACKEND_NATIVE_CPU;
default:
return UR_ADAPTER_BACKEND_UNKNOWN;
return UR_BACKEND_UNKNOWN;
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions unified-runtime/examples/codegen/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ std::vector<ur_adapter_handle_t>
get_supported_adapters(std::vector<ur_adapter_handle_t> &adapters) {
std::vector<ur_adapter_handle_t> supported_adapters;
for (auto adapter : adapters) {
ur_adapter_backend_t backend;
ur_backend_t backend;
ur_check(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
sizeof(ur_adapter_backend_t), &backend, nullptr));
sizeof(ur_backend_t), &backend, nullptr));

if (backend == UR_ADAPTER_BACKEND_LEVEL_ZERO) {
if (backend == UR_BACKEND_LEVEL_ZERO) {
supported_adapters.push_back(adapter);
}
}
Expand Down
71 changes: 25 additions & 46 deletions unified-runtime/include/ur_api.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 11 additions & 20 deletions unified-runtime/include/ur_print.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading