Skip to content

Commit b631fd8

Browse files
committed
Revert "[SYCL][CUDA] Improvements to CUDA device selection (intel#1689)"
This reverts commit 7146426.
1 parent 41ea7e2 commit b631fd8

File tree

8 files changed

+43
-76
lines changed

8 files changed

+43
-76
lines changed

sycl/include/CL/sycl/device_selector.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ class device;
2525
///
2626
/// \ingroup sycl_api_dev_sel
2727
class __SYCL_EXPORT device_selector {
28-
protected:
29-
// SYCL 1.2.1 defines a negative score to reject a device from selection
30-
static constexpr int REJECT_DEVICE_SCORE = -1;
31-
3228
public:
3329
virtual ~device_selector() = default;
3430

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ pi_result cuda_piPlatformGetInfo(pi_platform platform,
619619
switch (param_name) {
620620
case PI_PLATFORM_INFO_NAME:
621621
return getInfo(param_value_size, param_value, param_value_size_ret,
622-
"NVIDIA CUDA BACKEND");
622+
"NVIDIA CUDA");
623623
case PI_PLATFORM_INFO_VENDOR:
624624
return getInfo(param_value_size, param_value, param_value_size_ret,
625625
"NVIDIA Corporation");

sycl/source/detail/context_impl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ context_impl::context_impl(const vector_class<cl::sycl::device> Devices,
4141
DeviceIds.push_back(getSyclObjImpl(D)->getHandleRef());
4242
}
4343

44-
const auto Backend = getPlugin().getBackend();
45-
if (Backend == backend::cuda) {
44+
if (MPlatform->is_cuda()) {
4645
#if USE_PI_CUDA
4746
const pi_context_properties props[] = {
4847
static_cast<pi_context_properties>(PI_CONTEXT_PROPERTIES_CUDA_PRIMARY),

sycl/source/detail/platform_impl.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,6 @@ __SYCL_INLINE_NAMESPACE(cl) {
2020
namespace sycl {
2121
namespace detail {
2222

23-
static bool IsBannedPlatform(platform Platform) {
24-
// The NVIDIA OpenCL platform is currently not compatible with DPC++
25-
// since it is only 1.2 but gets selected by default in many systems
26-
// There is also no support on the PTX backend for OpenCL consumption,
27-
// and there have been some internal reports.
28-
// To avoid problems on default users and deployment of DPC++ on platforms
29-
// where CUDA is available, the OpenCL support is disabled.
30-
//
31-
auto IsNVIDIAOpenCL = [](platform Platform) {
32-
if (Platform.is_host())
33-
return false;
34-
35-
const bool HasCUDA = Platform.get_info<info::platform::name>().find(
36-
"NVIDIA CUDA") != std::string::npos;
37-
const auto Backend =
38-
detail::getSyclObjImpl(Platform)->getPlugin().getBackend();
39-
const bool IsCUDAOCL = (HasCUDA && Backend == backend::opencl);
40-
if (detail::pi::trace(detail::pi::TraceLevel::PI_TRACE_ALL) && IsCUDAOCL) {
41-
std::cout << "SYCL_PI_TRACE[all]: "
42-
<< "NVIDIA CUDA OpenCL platform found but is not compatible."
43-
<< std::endl;
44-
}
45-
return IsCUDAOCL;
46-
};
47-
return IsNVIDIAOpenCL(Platform);
48-
}
49-
5023
vector_class<platform> platform_impl::get_platforms() {
5124
vector_class<platform> Platforms;
5225
vector_class<plugin> Plugins = RT::initialize();
@@ -66,8 +39,7 @@ vector_class<platform> platform_impl::get_platforms() {
6639
platform Platform = detail::createSyclObjFromImpl<platform>(
6740
std::make_shared<platform_impl>(PiPlatform, Plugins[i]));
6841
// Skip platforms which do not contain requested device types
69-
if (!Platform.get_devices(ForcedType).empty() &&
70-
!IsBannedPlatform(Platform))
42+
if (!Platform.get_devices(ForcedType).empty())
7143
Platforms.push_back(Platform);
7244
}
7345
}

sycl/source/detail/platform_impl.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class platform_impl {
7373
/// \return true if this SYCL platform is a host platform.
7474
bool is_host() const { return MHostPlatform; };
7575

76+
bool is_cuda() const {
77+
const string_class CUDA_PLATFORM_STRING = "NVIDIA CUDA";
78+
const string_class PlatformName =
79+
get_platform_info<string_class, info::platform::name>::get(MPlatform,
80+
getPlugin());
81+
return PlatformName == CUDA_PLATFORM_STRING;
82+
}
83+
7684
/// \return an instance of OpenCL cl_platform_id.
7785
cl_platform_id get() const {
7886
if (is_host())

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,29 @@ static RT::PiProgram createBinaryProgram(const ContextImplPtr Context,
8686

8787
RT::PiProgram Program;
8888

89+
bool IsCUDA = false;
90+
8991
// TODO: Implement `piProgramCreateWithBinary` to not require extra logic for
9092
// the CUDA backend.
91-
const auto Backend = Context->getPlugin().getBackend();
92-
if (Backend == backend::cuda) {
93+
#if USE_PI_CUDA
94+
// All devices in a context are from the same platform.
95+
RT::PiDevice Device = getFirstDevice(Context);
96+
RT::PiPlatform Platform = nullptr;
97+
Plugin.call<PiApiKind::piDeviceGetInfo>(Device, PI_DEVICE_INFO_PLATFORM, sizeof(Platform),
98+
&Platform, nullptr);
99+
size_t PlatformNameSize = 0u;
100+
Plugin.call<PiApiKind::piPlatformGetInfo>(Platform, PI_PLATFORM_INFO_NAME, 0u, nullptr,
101+
&PlatformNameSize);
102+
std::vector<char> PlatformName(PlatformNameSize, '\0');
103+
Plugin.call<PiApiKind::piPlatformGetInfo>(Platform, PI_PLATFORM_INFO_NAME,
104+
PlatformName.size(), PlatformName.data(), nullptr);
105+
if (PlatformNameSize > 0u &&
106+
std::strncmp(PlatformName.data(), "NVIDIA CUDA", PlatformNameSize) == 0) {
107+
IsCUDA = true;
108+
}
109+
#endif // USE_PI_CUDA
110+
111+
if (IsCUDA) {
93112
// TODO: Reemplace CreateWithSource with CreateWithBinary in CUDA backend
94113
const char *SignedData = reinterpret_cast<const char *>(Data);
95114
Plugin.call<PiApiKind::piclProgramCreateWithSource>(Context->getHandleRef(), 1 /*one binary*/, &SignedData,
@@ -240,13 +259,6 @@ RetT *getOrBuild(KernelProgramCache &KPCache, KeyT &&CacheKey,
240259

241260
static bool isDeviceBinaryTypeSupported(const context &C,
242261
RT::PiDeviceBinaryType Format) {
243-
const backend ContextBackend =
244-
detail::getSyclObjImpl(C)->getPlugin().getBackend();
245-
246-
// The CUDA backend cannot use SPIRV
247-
if (ContextBackend == backend::cuda && Format == PI_DEVICE_BINARY_TYPE_SPIRV)
248-
return false;
249-
250262
// All formats except PI_DEVICE_BINARY_TYPE_SPIRV are supported.
251263
if (Format != PI_DEVICE_BINARY_TYPE_SPIRV)
252264
return true;
@@ -260,7 +272,8 @@ static bool isDeviceBinaryTypeSupported(const context &C,
260272
}
261273

262274
// OpenCL 2.1 and greater require clCreateProgramWithIL
263-
if ((ContextBackend == backend::opencl) &&
275+
backend CBackend = (detail::getSyclObjImpl(C)->getPlugin()).getBackend();
276+
if ((CBackend == backend::opencl) &&
264277
C.get_platform().get_info<info::platform::version>() >= "2.1")
265278
return true;
266279

@@ -324,7 +337,7 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img,
324337

325338
if (!isDeviceBinaryTypeSupported(Context, Format))
326339
throw feature_not_supported(
327-
"SPIR-V online compilation is not supported in this context",
340+
"Online compilation is not supported in this context",
328341
PI_INVALID_OPERATION);
329342

330343
// Load the image

sycl/source/device_selector.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,28 @@ static bool isDeviceOfPreferredSyclBe(const device &Device) {
3030

3131
device device_selector::select_device() const {
3232
vector_class<device> devices = device::get_devices();
33-
int score = REJECT_DEVICE_SCORE;
33+
int score = -1;
3434
const device *res = nullptr;
35-
3635
for (const auto &dev : devices) {
3736
int dev_score = (*this)(dev);
38-
3937
if (detail::pi::trace(detail::pi::TraceLevel::PI_TRACE_ALL)) {
4038
string_class PlatformVersion = dev.get_info<info::device::platform>()
4139
.get_info<info::platform::version>();
4240
string_class DeviceName = dev.get_info<info::device::name>();
4341
std::cout << "SYCL_PI_TRACE[all]: "
44-
<< "select_device(): -> score = " << score
45-
<< ((score == REJECT_DEVICE_SCORE) ? "(REJECTED)" : " ")
46-
<< std::endl
42+
<< "select_device(): -> score = " << score << std::endl
4743
<< "SYCL_PI_TRACE[all]: "
4844
<< " platform: " << PlatformVersion << std::endl
4945
<< "SYCL_PI_TRACE[all]: "
5046
<< " device: " << DeviceName << std::endl;
5147
}
5248

53-
// Device is discarded if is marked with REJECT_DEVICE_SCORE
54-
if (dev_score == REJECT_DEVICE_SCORE)
55-
continue;
56-
5749
// SYCL spec says: "If more than one device receives the high score then
5850
// one of those tied devices will be returned, but which of the devices
5951
// from the tied set is to be returned is not defined". Here we give a
6052
// preference to the device of the preferred BE.
6153
//
62-
if ((score < dev_score) ||
54+
if (score < dev_score ||
6355
(score == dev_score && isDeviceOfPreferredSyclBe(dev))) {
6456
res = &dev;
6557
score = dev_score;
@@ -91,7 +83,7 @@ device device_selector::select_device() const {
9183
/// 3. Host
9284
int default_selector::operator()(const device &dev) const {
9385

94-
int Score = REJECT_DEVICE_SCORE;
86+
int Score = -1;
9587

9688
// Give preference to device of SYCL BE.
9789
if (isDeviceOfPreferredSyclBe(dev))
@@ -114,8 +106,7 @@ int default_selector::operator()(const device &dev) const {
114106
}
115107

116108
int gpu_selector::operator()(const device &dev) const {
117-
int Score = REJECT_DEVICE_SCORE;
118-
109+
int Score = -1;
119110
if (dev.is_gpu()) {
120111
Score = 1000;
121112
// Give preference to device of SYCL BE.
@@ -126,7 +117,7 @@ int gpu_selector::operator()(const device &dev) const {
126117
}
127118

128119
int cpu_selector::operator()(const device &dev) const {
129-
int Score = REJECT_DEVICE_SCORE;
120+
int Score = -1;
130121
if (dev.is_cpu()) {
131122
Score = 1000;
132123
// Give preference to device of SYCL BE.
@@ -137,7 +128,7 @@ int cpu_selector::operator()(const device &dev) const {
137128
}
138129

139130
int accelerator_selector::operator()(const device &dev) const {
140-
int Score = REJECT_DEVICE_SCORE;
131+
int Score = -1;
141132
if (dev.is_accelerator()) {
142133
Score = 1000;
143134
// Give preference to device of SYCL BE.
@@ -148,7 +139,7 @@ int accelerator_selector::operator()(const device &dev) const {
148139
}
149140

150141
int host_selector::operator()(const device &dev) const {
151-
int Score = REJECT_DEVICE_SCORE;
142+
int Score = -1;
152143
if (dev.is_host()) {
153144
Score = 1000;
154145
// Give preference to device of SYCL BE.

sycl/tools/get_device_count_by_type.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include <algorithm>
2323
#include <cstdlib>
24-
#include <cstring>
2524
#include <iostream>
2625
#include <sstream>
2726
#include <string>
@@ -89,17 +88,6 @@ static bool queryOpenCL(cl_device_type deviceType, cl_uint &deviceCount,
8988
}
9089

9190
for (cl_uint i = 0; i < platformCount; i++) {
92-
const size_t MAX_PLATFORM_VENDOR = 100u;
93-
char info[MAX_PLATFORM_VENDOR];
94-
// get platform attribute value
95-
clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, MAX_PLATFORM_VENDOR,
96-
info, NULL);
97-
const auto IsNVIDIAOpenCL = strstr(info, "NVIDIA") != NULL;
98-
if (IsNVIDIAOpenCL) {
99-
// Ignore NVIDIA OpenCL platform for testing
100-
continue;
101-
}
102-
10391
cl_uint deviceCountPart = 0;
10492
iRet =
10593
clGetDeviceIDs(platforms[i], deviceType, 0, nullptr, &deviceCountPart);

0 commit comments

Comments
 (0)