1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#define BOOST_TEST_MODULE TestDevice
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <boost/compute/device.hpp>
#include <boost/compute/system.hpp>
#include <boost/compute/detail/nvidia_compute_capability.hpp>
#include "opencl_version_check.hpp"
BOOST_AUTO_TEST_CASE(null_device)
{
boost::compute::device null;
BOOST_CHECK(null.id() == cl_device_id());
BOOST_CHECK(null.get() == cl_device_id());
}
BOOST_AUTO_TEST_CASE(default_device_doctest)
{
//! [default_gpu]
boost::compute::device gpu = boost::compute::system::default_device();
//! [default_gpu]
BOOST_CHECK(gpu.id());
}
BOOST_AUTO_TEST_CASE(device_platform)
{
boost::compute::platform p = boost::compute::system::platforms().at(0);
BOOST_CHECK(p == p.devices().at(0).platform());
}
BOOST_AUTO_TEST_CASE(get_device_name)
{
boost::compute::device gpu = boost::compute::system::default_device();
if(gpu.id()){
BOOST_CHECK(!gpu.name().empty());
}
}
BOOST_AUTO_TEST_CASE(equality_operator)
{
boost::compute::device device1 = boost::compute::system::default_device();
BOOST_CHECK(device1 == device1);
boost::compute::device device2 = device1;
BOOST_CHECK(device1 == device2);
}
BOOST_AUTO_TEST_CASE(get_max_work_item_sizes)
{
boost::compute::device device = boost::compute::system::default_device();
std::vector<size_t> max_work_item_sizes =
device.get_info<std::vector<size_t> >(CL_DEVICE_MAX_WORK_ITEM_SIZES);
BOOST_CHECK_GE(max_work_item_sizes.size(), size_t(3));
BOOST_CHECK_GE(max_work_item_sizes[0], size_t(1));
BOOST_CHECK_GE(max_work_item_sizes[1], size_t(1));
BOOST_CHECK_GE(max_work_item_sizes[2], size_t(1));
}
#ifdef BOOST_COMPUTE_CL_VERSION_1_2
// returns true if the device supports the partitioning type
bool supports_partition_type(const boost::compute::device &device,
cl_device_partition_property type)
{
const std::vector<cl_device_partition_property> properties =
device.get_info<std::vector<cl_device_partition_property> >(
CL_DEVICE_PARTITION_PROPERTIES
);
return std::find(properties.begin(),
properties.end(),
type) != properties.end();
}
BOOST_AUTO_TEST_CASE(partition_device_equally)
{
// get default device and ensure it has at least two compute units
boost::compute::device device = boost::compute::system::default_device();
REQUIRES_OPENCL_VERSION(1,2);
if(device.compute_units() < 2){
std::cout << "skipping test: "
<< "device does not have enough compute units"
<< std::endl;
return;
}
// check that the device supports partitioning equally
if(!supports_partition_type(device, CL_DEVICE_PARTITION_EQUALLY)){
std::cout << "skipping test: "
<< "device does not support CL_DEVICE_PARTITION_EQUALLY"
<< std::endl;
return;
}
// ensure device is not a sub-device
BOOST_CHECK(device.is_subdevice() == false);
// partition default device into sub-devices with one compute unit each
std::vector<boost::compute::device>
sub_devices = device.partition_equally(1);
BOOST_CHECK_EQUAL(sub_devices.size(), size_t(device.compute_units()));
// verify each of the sub-devices
for(size_t i = 0; i < sub_devices.size(); i++){
const boost::compute::device &sub_device = sub_devices[i];
// ensure parent device id is correct
cl_device_id parent_id =
sub_device.get_info<cl_device_id>(CL_DEVICE_PARENT_DEVICE);
BOOST_CHECK(parent_id == device.id());
// ensure device is a sub-device
BOOST_CHECK(sub_device.is_subdevice() == true);
// check number of compute units
BOOST_CHECK_EQUAL(sub_device.compute_units(), size_t(1));
}
}
// used to sort devices by number of compute units
bool compare_compute_units(const boost::compute::device &a,
const boost::compute::device &b)
{
return a.compute_units() < b.compute_units();
}
BOOST_AUTO_TEST_CASE(partition_by_counts)
{
// get default device and ensure it has at least four compute units
boost::compute::device device = boost::compute::system::default_device();
REQUIRES_OPENCL_VERSION(1,2);
if(device.compute_units() < 4){
std::cout << "skipping test: "
<< "device does not have enough compute units"
<< std::endl;
return;
}
// check that the device supports partitioning by counts
if(!supports_partition_type(device, CL_DEVICE_PARTITION_BY_COUNTS)){
std::cout << "skipping test: "
<< "device does not support CL_DEVICE_PARTITION_BY_COUNTS"
<< std::endl;
return;
}
// ensure device is not a sub-device
BOOST_CHECK(device.is_subdevice() == false);
// create vector of sub-device compute unit counts
std::vector<size_t> counts;
counts.push_back(2);
counts.push_back(1);
counts.push_back(1);
// partition default device into sub-devices according to counts
std::vector<boost::compute::device>
sub_devices = device.partition_by_counts(counts);
BOOST_CHECK_EQUAL(sub_devices.size(), size_t(3));
// sort sub-devices by number of compute units (see issue #185)
std::sort(sub_devices.begin(), sub_devices.end(), compare_compute_units);
// verify each of the sub-devices
BOOST_CHECK_EQUAL(sub_devices[0].compute_units(), size_t(1));
BOOST_CHECK_EQUAL(sub_devices[1].compute_units(), size_t(1));
BOOST_CHECK_EQUAL(sub_devices[2].compute_units(), size_t(2));
}
BOOST_AUTO_TEST_CASE(partition_by_affinity_domain)
{
// get default device and ensure it has at least two compute units
boost::compute::device device = boost::compute::system::default_device();
REQUIRES_OPENCL_VERSION(1,2);
if(device.compute_units() < 2){
std::cout << "skipping test: "
<< "device does not have enough compute units"
<< std::endl;
return;
}
// check that the device supports splitting by affinity domains
if(!supports_partition_type(device, CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE)){
std::cout << "skipping test: "
<< "device does not support partitioning by affinity domain"
<< std::endl;
return;
}
// ensure device is not a sub-device
BOOST_CHECK(device.is_subdevice() == false);
std::vector<boost::compute::device> sub_devices =
device.partition_by_affinity_domain(
CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE);
BOOST_CHECK(sub_devices.size() > 0);
BOOST_CHECK(sub_devices[0].is_subdevice() == true);
}
#endif // BOOST_COMPUTE_CL_VERSION_1_2
BOOST_AUTO_TEST_CASE(nvidia_compute_capability)
{
boost::compute::device device = boost::compute::system::default_device();
int major, minor;
boost::compute::detail::get_nvidia_compute_capability(device, major, minor);
boost::compute::detail::check_nvidia_compute_capability(device, 3, 0);
}
BOOST_AUTO_TEST_CASE(get_info_specializations)
{
boost::compute::device device = boost::compute::system::default_device();
std::cout << device.get_info<CL_DEVICE_NAME>() << std::endl;
}
#ifdef BOOST_COMPUTE_CL_VERSION_2_1
BOOST_AUTO_TEST_CASE(get_host_timer)
{
boost::compute::device device = boost::compute::system::default_device();
REQUIRES_OPENCL_VERSION(2, 1);
BOOST_CHECK(device.get_host_timer() != 0);
#ifndef BOOST_COMPUTE_NO_HDR_CHRONO
typedef std::chrono::milliseconds stdms;
BOOST_CHECK(device.get_host_timer<stdms>().count() != 0);
#endif
#ifndef BOOST_COMPUTE_NO_BOOST_CHRONO
typedef boost::chrono::milliseconds bms;
BOOST_CHECK(device.get_host_timer<bms>().count() != 0);
#endif
}
BOOST_AUTO_TEST_CASE(get_device_and_host_timer)
{
boost::compute::device device = boost::compute::system::default_device();
REQUIRES_OPENCL_VERSION(2, 1);
typedef std::pair<boost::compute::ulong_, boost::compute::ulong_> dah_timer;
dah_timer timer;
BOOST_CHECK_NO_THROW(timer = device.get_device_and_host_timer());
BOOST_CHECK(timer.first != 0);
BOOST_CHECK(timer.second != 0);
#ifndef BOOST_COMPUTE_NO_HDR_CHRONO
typedef std::chrono::milliseconds stdms;
BOOST_CHECK(device.get_device_and_host_timer<stdms>().first.count() != 0);
BOOST_CHECK(device.get_device_and_host_timer<stdms>().second.count() != 0);
#endif
#ifndef BOOST_COMPUTE_NO_BOOST_CHRONO
typedef boost::chrono::milliseconds bms;
BOOST_CHECK(device.get_device_and_host_timer<bms>().first.count() != 0);
BOOST_CHECK(device.get_device_and_host_timer<bms>().second.count() != 0);
#endif
}
BOOST_AUTO_TEST_CASE(get_info_opencl21_queries)
{
boost::compute::device device = boost::compute::system::default_device();
REQUIRES_OPENCL_VERSION(2, 1);
BOOST_CHECK(!device.get_info<CL_DEVICE_IL_VERSION>().empty());
BOOST_CHECK(device.get_info<CL_DEVICE_MAX_NUM_SUB_GROUPS>() > 0);
BOOST_CHECK_NO_THROW(
device.get_info<CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS>()
);
}
#endif // BOOST_COMPUTE_CL_VERSION_2_1
|