Skip to content

Commit

Permalink
Fix failing platform test case. (#116)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
diptorupd committed Oct 8, 2020
1 parent 7c311f4 commit 9fcbaa5
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 110 deletions.
15 changes: 8 additions & 7 deletions backends/include/dppl_sycl_platform_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,30 @@
DPPL_C_EXTERN_C_BEGIN

/*!
* @brief Returns the number of sycl::platform available on the system.
* @brief Returns the number of non-host type sycl::platform available on the
* system.
*
* @return The number of available sycl::platforms.
*/
DPPL_API
size_t DPPLPlatform_GetNumPlatforms ();
size_t DPPLPlatform_GetNumNonHostPlatforms ();

/*!
* @brief Returns the number of unique sycl backends on the system not counting
* the host backend.
* @brief Returns the number of unique non-host sycl backends on the system.
*
* @return The number of unique sycl backends.
*/
DPPL_API
size_t DPPLPlatform_GetNumBackends ();
size_t DPPLPlatform_GetNumNonHostBackends ();

/*!
* @brief Returns an array of the unique DPPLSyclBackendType values on the system.
* @brief Returns an array of the unique non-host DPPLSyclBackendType values on
* the system.
*
* @return An array of DPPLSyclBackendType enum values.
*/
DPPL_API
__dppl_give DPPLSyclBackendType* DPPLPlatform_GetListOfBackends ();
__dppl_give DPPLSyclBackendType* DPPLPlatform_GetListOfNonHostBackends ();

/*!
* @brief Frees an array of DPPLSyclBackendType enum values.
Expand Down
1 change: 0 additions & 1 deletion backends/include/dppl_sycl_queue_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ DPPLQueueMgr_GetQueue (DPPLSyclBackendType BETy,
DPPL_API
size_t DPPLQueueMgr_GetNumActivatedQueues ();


/*!
* @brief Get the number of available queues for given backend and device type
* combination.
Expand Down
21 changes: 13 additions & 8 deletions backends/source/dppl_sycl_platform_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace cl::sycl;
namespace
{
std::set<DPPLSyclBackendType>
get_set_of_backends ()
get_set_of_non_hostbackends ()
{
std::set<DPPLSyclBackendType> be_set;
for (auto p : platform::get_platforms()) {
Expand All @@ -47,7 +47,6 @@ get_set_of_backends ()
switch (be)
{
case backend::host:
be_set.insert(DPPLSyclBackendType::DPPL_HOST);
break;
case backend::cuda:
be_set.insert(DPPLSyclBackendType::DPPL_CUDA);
Expand Down Expand Up @@ -154,19 +153,25 @@ void DPPLPlatform_DumpInfo ()
/*!
* Returns the number of sycl::platform on the system.
*/
size_t DPPLPlatform_GetNumPlatforms ()
size_t DPPLPlatform_GetNumNonHostPlatforms ()
{
return platform::get_platforms().size();
auto nNonHostPlatforms = 0ul;
for (auto &p : platform::get_platforms()) {
if (p.is_host())
continue;
++nNonHostPlatforms;
}
return nNonHostPlatforms;
}

size_t DPPLPlatform_GetNumBackends ()
size_t DPPLPlatform_GetNumNonHostBackends ()
{
return get_set_of_backends().size();
return get_set_of_non_hostbackends().size();
}

__dppl_give DPPLSyclBackendType *DPPLPlatform_GetListOfBackends ()
__dppl_give DPPLSyclBackendType *DPPLPlatform_GetListOfNonHostBackends ()
{
auto be_set = get_set_of_backends();
auto be_set = get_set_of_non_hostbackends();

if (be_set.empty())
return nullptr;
Expand Down
13 changes: 11 additions & 2 deletions backends/source/dppl_sycl_queue_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "dppl_sycl_queue_interface.h"
#include "dppl_sycl_context_interface.h"
#include "Support/CBindingWrapping.h"
#include <exception>
#include <stdexcept>

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

Expand Down Expand Up @@ -134,8 +136,15 @@ bool DPPLQueue_AreEq (__dppl_keep const DPPLSyclQueueRef QRef1,
DPPLSyclBackendType DPPLQueue_GetBackend (__dppl_keep DPPLSyclQueueRef QRef)
{
auto Q = unwrap(QRef);
auto C = Q->get_context();
return DPPLContext_GetBackend(wrap(&C));
try {
auto C = Q->get_context();
return DPPLContext_GetBackend(wrap(&C));
}
catch (runtime_error &re) {
std::cerr << re.what() << '\n';
// store error message
return DPPL_UNKNOWN_BACKEND;
}
}

__dppl_give DPPLSyclDeviceRef
Expand Down
47 changes: 41 additions & 6 deletions backends/source/dppl_sycl_queue_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
//===----------------------------------------------------------------------===//
#include "dppl_sycl_queue_manager.h"
#include "Support/CBindingWrapping.h"
#include <exception>
#include <string>
#include <vector>

Expand Down Expand Up @@ -54,7 +53,8 @@ class QMgrHelper
public:
using QVec = vector_class<queue>;

static QVec* init_queues (backend BE, info::device_type DTy) {
static QVec* init_queues (backend BE, info::device_type DTy)
{
QVec *queues = new QVec();
auto Platforms = platform::get_platforms();
for (auto &p : Platforms) {
Expand Down Expand Up @@ -95,6 +95,42 @@ class QMgrHelper
return queues;
}

static QVec* init_active_queues ()
{
QVec *active_queues;
try {
auto def_device = std::move(default_selector().select_device());
auto BE = def_device.get_platform().get_backend();
auto DevTy = def_device.get_info<info::device::device_type>();

// \todo : We need to have a better way to match the default device
// to what SYCL returns based on the same scoring logic. Just
// storing the first device is not correct when we will have
// multiple devices of same type.
if(BE == backend::opencl &&
DevTy == info::device_type::cpu) {
active_queues = new QVec({get_opencl_cpu_queues()[0]});
}
else if(BE == backend::opencl &&
DevTy == info::device_type::gpu) {
active_queues = new QVec({get_opencl_gpu_queues()[0]});
}
else if(BE == backend::level_zero &&
DevTy == info::device_type::gpu) {
active_queues = new QVec({get_level0_gpu_queues()[0]});
}
else {
active_queues = new QVec();
}
}
catch (runtime_error &re) {
// \todo Handle the error
active_queues = new QVec();
}

return active_queues;
}

static QVec& get_opencl_cpu_queues ()
{
static QVec* queues = init_queues(backend::opencl,
Expand All @@ -118,8 +154,7 @@ class QMgrHelper

static QVec& get_active_queues ()
{
thread_local static QVec* active_queues =
new QVec({default_selector()});
thread_local static QVec *active_queues = init_active_queues();
return *active_queues;
}

Expand Down Expand Up @@ -156,7 +191,7 @@ class QMgrHelper
*/
DPPLSyclQueueRef QMgrHelper::getCurrentQueue ()
{
auto activated_q = get_active_queues();
auto &activated_q = get_active_queues();
if(activated_q.empty()) {
// \todo handle error
std::cerr << "No currently active queues.\n";
Expand Down Expand Up @@ -232,7 +267,7 @@ QMgrHelper::getQueue (DPPLSyclBackendType BETy,
*/
bool QMgrHelper::isCurrentQueue (__dppl_keep const DPPLSyclQueueRef QRef)
{
auto activated_q = get_active_queues();
auto &activated_q = get_active_queues();
if(activated_q.empty()) {
// \todo handle error
std::cerr << "No currently active queues.\n";
Expand Down
17 changes: 11 additions & 6 deletions backends/tests/test_sycl_platform_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,31 @@ struct TestDPPLSyclPlatformInterface : public ::testing::Test

TEST_F (TestDPPLSyclPlatformInterface, CheckGetNumPlatforms)
{
auto nplatforms = DPPLPlatform_GetNumPlatforms();
auto nplatforms = DPPLPlatform_GetNumNonHostPlatforms();
EXPECT_GE(nplatforms, 0);
}

TEST_F (TestDPPLSyclPlatformInterface, GetNumBackends)
{
auto nbackends = DPPLPlatform_GetNumBackends();
auto nbackends = DPPLPlatform_GetNumNonHostBackends();
EXPECT_GE(nbackends, 0);
}

TEST_F (TestDPPLSyclPlatformInterface, GetListOfBackends)
{
auto nbackends = DPPLPlatform_GetNumBackends();
auto backends = DPPLPlatform_GetListOfBackends();
EXPECT_TRUE(backends != nullptr);
auto nbackends = DPPLPlatform_GetNumNonHostBackends();

if(!nbackends)
GTEST_SKIP_("No non host backends available");

auto backends = DPPLPlatform_GetListOfNonHostBackends();
EXPECT_TRUE(backends != nullptr);
for(auto i = 0ul; i < nbackends; ++i) {
EXPECT_TRUE(
backends[i] == DPPLSyclBackendType::DPPL_CUDA ||
backends[i] == DPPLSyclBackendType::DPPL_OPENCL ||
backends[i] == DPPLSyclBackendType::DPPL_LEVEL_ZERO);
backends[i] == DPPLSyclBackendType::DPPL_LEVEL_ZERO
);
}
DPPLPlatform_DeleteListOfBackends(backends);
}
Expand Down
Loading

0 comments on commit 9fcbaa5

Please sign in to comment.