Skip to content

Commit 9fcbaa5

Browse files
authored
Fix failing platform test case. (#116)
* Fix failing platform test case. * Skip if no non-host back end is there. * Remove extra new line. * change how the initial active queue is populated. * It is fine for the queue manager to store the host queue. Up to clients what they want to do with it. * Fix gtests. * Add try catch... * handle exception. * Skip tests when no OpenCL devices are available. * Skip more tests if no devices exist. * Skip Python tests. * Skip Python test if no usable device exists. * Only report number of non-host platforms. * Add skip tests to test_sycl_usm.py * Skip more tests if no platform is available. * Properly fix initialization of static variable. * Do not create new std::vector. * Raise exception if DPPLSyclQueueRef is NULL.
1 parent 7c311f4 commit 9fcbaa5

13 files changed

+251
-110
lines changed

backends/include/dppl_sycl_platform_interface.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,30 @@
3434
DPPL_C_EXTERN_C_BEGIN
3535

3636
/*!
37-
* @brief Returns the number of sycl::platform available on the system.
37+
* @brief Returns the number of non-host type sycl::platform available on the
38+
* system.
3839
*
3940
* @return The number of available sycl::platforms.
4041
*/
4142
DPPL_API
42-
size_t DPPLPlatform_GetNumPlatforms ();
43+
size_t DPPLPlatform_GetNumNonHostPlatforms ();
4344

4445
/*!
45-
* @brief Returns the number of unique sycl backends on the system not counting
46-
* the host backend.
46+
* @brief Returns the number of unique non-host sycl backends on the system.
4747
*
4848
* @return The number of unique sycl backends.
4949
*/
5050
DPPL_API
51-
size_t DPPLPlatform_GetNumBackends ();
51+
size_t DPPLPlatform_GetNumNonHostBackends ();
5252

5353
/*!
54-
* @brief Returns an array of the unique DPPLSyclBackendType values on the system.
54+
* @brief Returns an array of the unique non-host DPPLSyclBackendType values on
55+
* the system.
5556
*
5657
* @return An array of DPPLSyclBackendType enum values.
5758
*/
5859
DPPL_API
59-
__dppl_give DPPLSyclBackendType* DPPLPlatform_GetListOfBackends ();
60+
__dppl_give DPPLSyclBackendType* DPPLPlatform_GetListOfNonHostBackends ();
6061

6162
/*!
6263
* @brief Frees an array of DPPLSyclBackendType enum values.

backends/include/dppl_sycl_queue_manager.h

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ DPPLQueueMgr_GetQueue (DPPLSyclBackendType BETy,
7878
DPPL_API
7979
size_t DPPLQueueMgr_GetNumActivatedQueues ();
8080

81-
8281
/*!
8382
* @brief Get the number of available queues for given backend and device type
8483
* combination.

backends/source/dppl_sycl_platform_interface.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ using namespace cl::sycl;
3737
namespace
3838
{
3939
std::set<DPPLSyclBackendType>
40-
get_set_of_backends ()
40+
get_set_of_non_hostbackends ()
4141
{
4242
std::set<DPPLSyclBackendType> be_set;
4343
for (auto p : platform::get_platforms()) {
@@ -47,7 +47,6 @@ get_set_of_backends ()
4747
switch (be)
4848
{
4949
case backend::host:
50-
be_set.insert(DPPLSyclBackendType::DPPL_HOST);
5150
break;
5251
case backend::cuda:
5352
be_set.insert(DPPLSyclBackendType::DPPL_CUDA);
@@ -154,19 +153,25 @@ void DPPLPlatform_DumpInfo ()
154153
/*!
155154
* Returns the number of sycl::platform on the system.
156155
*/
157-
size_t DPPLPlatform_GetNumPlatforms ()
156+
size_t DPPLPlatform_GetNumNonHostPlatforms ()
158157
{
159-
return platform::get_platforms().size();
158+
auto nNonHostPlatforms = 0ul;
159+
for (auto &p : platform::get_platforms()) {
160+
if (p.is_host())
161+
continue;
162+
++nNonHostPlatforms;
163+
}
164+
return nNonHostPlatforms;
160165
}
161166

162-
size_t DPPLPlatform_GetNumBackends ()
167+
size_t DPPLPlatform_GetNumNonHostBackends ()
163168
{
164-
return get_set_of_backends().size();
169+
return get_set_of_non_hostbackends().size();
165170
}
166171

167-
__dppl_give DPPLSyclBackendType *DPPLPlatform_GetListOfBackends ()
172+
__dppl_give DPPLSyclBackendType *DPPLPlatform_GetListOfNonHostBackends ()
168173
{
169-
auto be_set = get_set_of_backends();
174+
auto be_set = get_set_of_non_hostbackends();
170175

171176
if (be_set.empty())
172177
return nullptr;

backends/source/dppl_sycl_queue_interface.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "dppl_sycl_queue_interface.h"
2828
#include "dppl_sycl_context_interface.h"
2929
#include "Support/CBindingWrapping.h"
30+
#include <exception>
31+
#include <stdexcept>
3032

3133
#include <CL/sycl.hpp> /* SYCL headers */
3234

@@ -134,8 +136,15 @@ bool DPPLQueue_AreEq (__dppl_keep const DPPLSyclQueueRef QRef1,
134136
DPPLSyclBackendType DPPLQueue_GetBackend (__dppl_keep DPPLSyclQueueRef QRef)
135137
{
136138
auto Q = unwrap(QRef);
137-
auto C = Q->get_context();
138-
return DPPLContext_GetBackend(wrap(&C));
139+
try {
140+
auto C = Q->get_context();
141+
return DPPLContext_GetBackend(wrap(&C));
142+
}
143+
catch (runtime_error &re) {
144+
std::cerr << re.what() << '\n';
145+
// store error message
146+
return DPPL_UNKNOWN_BACKEND;
147+
}
139148
}
140149

141150
__dppl_give DPPLSyclDeviceRef

backends/source/dppl_sycl_queue_manager.cpp

+41-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
//===----------------------------------------------------------------------===//
2626
#include "dppl_sycl_queue_manager.h"
2727
#include "Support/CBindingWrapping.h"
28-
#include <exception>
2928
#include <string>
3029
#include <vector>
3130

@@ -54,7 +53,8 @@ class QMgrHelper
5453
public:
5554
using QVec = vector_class<queue>;
5655

57-
static QVec* init_queues (backend BE, info::device_type DTy) {
56+
static QVec* init_queues (backend BE, info::device_type DTy)
57+
{
5858
QVec *queues = new QVec();
5959
auto Platforms = platform::get_platforms();
6060
for (auto &p : Platforms) {
@@ -95,6 +95,42 @@ class QMgrHelper
9595
return queues;
9696
}
9797

98+
static QVec* init_active_queues ()
99+
{
100+
QVec *active_queues;
101+
try {
102+
auto def_device = std::move(default_selector().select_device());
103+
auto BE = def_device.get_platform().get_backend();
104+
auto DevTy = def_device.get_info<info::device::device_type>();
105+
106+
// \todo : We need to have a better way to match the default device
107+
// to what SYCL returns based on the same scoring logic. Just
108+
// storing the first device is not correct when we will have
109+
// multiple devices of same type.
110+
if(BE == backend::opencl &&
111+
DevTy == info::device_type::cpu) {
112+
active_queues = new QVec({get_opencl_cpu_queues()[0]});
113+
}
114+
else if(BE == backend::opencl &&
115+
DevTy == info::device_type::gpu) {
116+
active_queues = new QVec({get_opencl_gpu_queues()[0]});
117+
}
118+
else if(BE == backend::level_zero &&
119+
DevTy == info::device_type::gpu) {
120+
active_queues = new QVec({get_level0_gpu_queues()[0]});
121+
}
122+
else {
123+
active_queues = new QVec();
124+
}
125+
}
126+
catch (runtime_error &re) {
127+
// \todo Handle the error
128+
active_queues = new QVec();
129+
}
130+
131+
return active_queues;
132+
}
133+
98134
static QVec& get_opencl_cpu_queues ()
99135
{
100136
static QVec* queues = init_queues(backend::opencl,
@@ -118,8 +154,7 @@ class QMgrHelper
118154

119155
static QVec& get_active_queues ()
120156
{
121-
thread_local static QVec* active_queues =
122-
new QVec({default_selector()});
157+
thread_local static QVec *active_queues = init_active_queues();
123158
return *active_queues;
124159
}
125160

@@ -156,7 +191,7 @@ class QMgrHelper
156191
*/
157192
DPPLSyclQueueRef QMgrHelper::getCurrentQueue ()
158193
{
159-
auto activated_q = get_active_queues();
194+
auto &activated_q = get_active_queues();
160195
if(activated_q.empty()) {
161196
// \todo handle error
162197
std::cerr << "No currently active queues.\n";
@@ -232,7 +267,7 @@ QMgrHelper::getQueue (DPPLSyclBackendType BETy,
232267
*/
233268
bool QMgrHelper::isCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef)
234269
{
235-
auto activated_q = get_active_queues();
270+
auto &activated_q = get_active_queues();
236271
if(activated_q.empty()) {
237272
// \todo handle error
238273
std::cerr << "No currently active queues.\n";

backends/tests/test_sycl_platform_interface.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,31 @@ struct TestDPPLSyclPlatformInterface : public ::testing::Test
3131

3232
TEST_F (TestDPPLSyclPlatformInterface, CheckGetNumPlatforms)
3333
{
34-
auto nplatforms = DPPLPlatform_GetNumPlatforms();
34+
auto nplatforms = DPPLPlatform_GetNumNonHostPlatforms();
3535
EXPECT_GE(nplatforms, 0);
3636
}
3737

3838
TEST_F (TestDPPLSyclPlatformInterface, GetNumBackends)
3939
{
40-
auto nbackends = DPPLPlatform_GetNumBackends();
40+
auto nbackends = DPPLPlatform_GetNumNonHostBackends();
4141
EXPECT_GE(nbackends, 0);
4242
}
4343

4444
TEST_F (TestDPPLSyclPlatformInterface, GetListOfBackends)
4545
{
46-
auto nbackends = DPPLPlatform_GetNumBackends();
47-
auto backends = DPPLPlatform_GetListOfBackends();
48-
EXPECT_TRUE(backends != nullptr);
46+
auto nbackends = DPPLPlatform_GetNumNonHostBackends();
47+
48+
if(!nbackends)
49+
GTEST_SKIP_("No non host backends available");
50+
51+
auto backends = DPPLPlatform_GetListOfNonHostBackends();
52+
EXPECT_TRUE(backends != nullptr);
4953
for(auto i = 0ul; i < nbackends; ++i) {
5054
EXPECT_TRUE(
5155
backends[i] == DPPLSyclBackendType::DPPL_CUDA ||
5256
backends[i] == DPPLSyclBackendType::DPPL_OPENCL ||
53-
backends[i] == DPPLSyclBackendType::DPPL_LEVEL_ZERO);
57+
backends[i] == DPPLSyclBackendType::DPPL_LEVEL_ZERO
58+
);
5459
}
5560
DPPLPlatform_DeleteListOfBackends(backends);
5661
}

0 commit comments

Comments
 (0)