SkelCL
SkelCL is a high level multi GPU skeleton library developed at the university of Münster, Germany.
 All Classes Namespaces Files Functions Variables Typedefs Groups
DeviceSelectionTests.cpp
1 /*****************************************************************************
2  * Copyright (c) 2011-2012 The SkelCL Team as listed in CREDITS.txt *
3  * http://skelcl.uni-muenster.de *
4  * *
5  * This file is part of SkelCL. *
6  * SkelCL is available under multiple licenses. *
7  * The different licenses are subject to terms and condition as provided *
8  * in the files specifying the license. See "LICENSE.txt" for details *
9  * *
10  *****************************************************************************
11  * *
12  * SkelCL is free software: you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation, either version 3 of the License, or *
15  * (at your option) any later version. See "LICENSE-gpl.txt" for details. *
16  * *
17  * SkelCL is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  *****************************************************************************
23  * *
24  * For non-commercial academic use see the license specified in the file *
25  * "LICENSE-academic.txt". *
26  * *
27  *****************************************************************************
28  * *
29  * If you are interested in other licensing models, including a commercial- *
30  * license, please contact the author at michel.steuwer@uni-muenster.de *
31  * *
32  *****************************************************************************/
33 
37 
38 #include <SkelCL/SkelCL.h>
39 #include <SkelCL/detail/Device.h>
40 #include <SkelCL/detail/DeviceProperties.h>
41 #include <SkelCL/detail/DeviceList.h>
42 
43 #define __CL_ENABLE_EXCEPTIONS
44 #include <CL/cl.hpp>
45 #undef __CL_ENABLE_EXCEPTIONS
46 
47 #include "Test.h"
50 
51 class DeviceSelectionTest : public ::testing::Test {
52 protected:
53  DeviceSelectionTest() : cpuCount(0), gpuCount(0) {
54  //skelcl::detail::defaultLogger.setLoggingLevel(
55  // skelcl::detail::Logger::Severity::Debug);
56 
57  std::vector<cl::Platform> platforms;
58  cl::Platform::get(&platforms);
59  if (platforms.size() > 0) {
60  // for each platform ...
61  for (auto& platform : platforms) {
62  // .. get all devices ..
63  std::vector<cl::Device> devices;
64  platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
65 
66  for (auto& device : devices) {
67  auto type = device.getInfo<CL_DEVICE_TYPE>();
68  if (type == CL_DEVICE_TYPE_CPU) {
69  cpuCount++;
70  } else if (type == CL_DEVICE_TYPE_GPU) {
71  gpuCount++;
72  }
73  }
74  }
75  }
76  }
77 
78  ~DeviceSelectionTest() {
80  }
81 
82  int cpuCount;
83  int gpuCount;
84 };
85 
86 using namespace skelcl;
87 
88 TEST_F(DeviceSelectionTest, SelectAll) {
89  if (cpuCount + gpuCount > 0) {
91  EXPECT_GE(skelcl::detail::globalDeviceList.size(), cpuCount + gpuCount);
92  }
93 }
94 
95 TEST_F(DeviceSelectionTest, SelectAllGPUs) {
96  if (gpuCount > 0) {
97  skelcl::init( allDevices().deviceType(device_type::GPU) );
98  EXPECT_EQ(skelcl::detail::globalDeviceList.size(), gpuCount);
99  for (auto& device : skelcl::detail::globalDeviceList) {
100  EXPECT_TRUE( device->isType(device_type::GPU) );
101  }
102  }
103 }
104 
105 TEST_F(DeviceSelectionTest, SelectOne) {
106  if (cpuCount + gpuCount > 0) {
108  EXPECT_EQ(skelcl::detail::globalDeviceList.size(), 1);
109  }
110 }
111 
112 TEST_F(DeviceSelectionTest, SelectOneGPU) {
113  if (gpuCount > 0) {
114  skelcl::init(nDevices(1).deviceType(device_type::GPU));
115  ASSERT_EQ(skelcl::detail::globalDeviceList.size(), 1);
116  EXPECT_TRUE(skelcl::detail::globalDeviceList.front()->isType(skelcl::device_type::GPU));
117  }
118 }
119 
120 TEST_F(DeviceSelectionTest, SelectFirstDeviceOfFirstPlatform)
121 {
122  if (cpuCount + gpuCount > 0) {
124  ASSERT_EQ(skelcl::detail::globalDeviceList.size(), 1);
125  }
126 }
127 
129 
SKELCL_DLL detail::DeviceProperties allDevices()
Creates a detail::DeviceProperties object representing all devices in the system. This object should ...
Definition: SkelCL.cpp:61
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...
Definition: SkelCL.cpp:51
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.
Definition: SkelCL.cpp:76
SKELCL_DLL detail::DeviceProperties nDevices(size_t n)
Creates a detail::DeviceProperties object representing n devices. This object should be used as param...
Definition: SkelCL.cpp:66
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.
Definition: SkelCL.cpp:81
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.
Definition: SkelCL.cpp:71