39 #include <SkelCL/detail/Device.h>
40 #include <SkelCL/detail/DeviceProperties.h>
41 #include <SkelCL/detail/DeviceList.h>
43 #define __CL_ENABLE_EXCEPTIONS
45 #undef __CL_ENABLE_EXCEPTIONS
51 class DeviceSelectionTest :
public ::testing::Test {
53 DeviceSelectionTest() : cpuCount(0), gpuCount(0) {
57 std::vector<cl::Platform> platforms;
58 cl::Platform::get(&platforms);
59 if (platforms.size() > 0) {
63 std::vector<cl::Device> devices;
64 platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
66 for (
auto&
device : devices) {
67 auto type =
device.getInfo<CL_DEVICE_TYPE>();
68 if (type == CL_DEVICE_TYPE_CPU) {
70 }
else if (type == CL_DEVICE_TYPE_GPU) {
78 ~DeviceSelectionTest() {
86 using namespace skelcl;
88 TEST_F(DeviceSelectionTest, SelectAll) {
89 if (cpuCount + gpuCount > 0) {
91 EXPECT_GE(skelcl::detail::globalDeviceList.size(), cpuCount + gpuCount);
95 TEST_F(DeviceSelectionTest, SelectAllGPUs) {
98 EXPECT_EQ(skelcl::detail::globalDeviceList.size(), gpuCount);
99 for (
auto&
device : skelcl::detail::globalDeviceList) {
100 EXPECT_TRUE(
device->isType(device_type::GPU) );
105 TEST_F(DeviceSelectionTest, SelectOne) {
106 if (cpuCount + gpuCount > 0) {
108 EXPECT_EQ(skelcl::detail::globalDeviceList.size(), 1);
112 TEST_F(DeviceSelectionTest, SelectOneGPU) {
115 ASSERT_EQ(skelcl::detail::globalDeviceList.size(), 1);
116 EXPECT_TRUE(skelcl::detail::globalDeviceList.front()->isType(skelcl::device_type::GPU));
120 TEST_F(DeviceSelectionTest, SelectFirstDeviceOfFirstPlatform)
122 if (cpuCount + gpuCount > 0) {
124 ASSERT_EQ(skelcl::detail::globalDeviceList.size(), 1);
SKELCL_DLL detail::DeviceProperties allDevices()
Creates a detail::DeviceProperties object representing all devices in the system. This object should ...
SKELCL_DLL void init(detail::DeviceProperties properties=allDevices())
Initializes the SkelCL library. This function (or another init function) has to be called prior to ev...
SKELCL_DLL detail::DeviceID device(size_t dID)
Creates an OpenCL device ID to be used as parameter of the init(detail::PlatformID, detail::DeviceID) function.
SKELCL_DLL detail::DeviceProperties nDevices(size_t n)
Creates a detail::DeviceProperties object representing n devices. This object should be used as param...
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.
SKELCL_DLL detail::PlatformID platform(size_t pID)
Creates an OpenCL platform ID to be used as parameter of the init(detail::PlatformID, detail::DeviceID) function.