Skip to content

Fix failing platform test case. #116

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

Merged
Merged
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
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 @@ -88,6 +88,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 @@ -111,8 +147,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 @@ -149,7 +184,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 @@ -225,7 +260,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