Alien-XGBoost
view release on metacpan or search on metacpan
xgboost/cub/test/test_util.h view on Meta::CPAN
// Clear any default values
vals.clear();
// Recover from multi-value string
for (int i = 0; i < keys.size(); ++i)
{
if (keys[i] == string(arg_name))
{
string val_string(values[i]);
istringstream str_stream(val_string);
string::size_type old_pos = 0;
string::size_type new_pos = 0;
// Iterate comma-separated values
T val;
while ((new_pos = val_string.find(',', old_pos)) != string::npos)
{
if (new_pos != old_pos)
{
str_stream.width(new_pos - old_pos);
str_stream >> val;
vals.push_back(val);
}
// skip over comma
str_stream.ignore(1);
old_pos = new_pos + 1;
}
// Read last value
str_stream >> val;
vals.push_back(val);
}
}
}
}
/**
* The number of pairs parsed
*/
int ParsedArgc()
{
return (int) keys.size();
}
/**
* Initialize device
*/
cudaError_t DeviceInit(int dev = -1)
{
cudaError_t error = cudaSuccess;
do
{
int deviceCount;
error = CubDebug(cudaGetDeviceCount(&deviceCount));
if (error) break;
if (deviceCount == 0) {
fprintf(stderr, "No devices supporting CUDA.\n");
exit(1);
}
if (dev < 0)
{
GetCmdLineArgument("device", dev);
}
if ((dev > deviceCount - 1) || (dev < 0))
{
dev = 0;
}
error = CubDebug(cudaSetDevice(dev));
if (error) break;
CubDebugExit(cudaMemGetInfo(&device_free_physmem, &device_total_physmem));
int ptx_version;
error = CubDebug(cub::PtxVersion(ptx_version));
if (error) break;
error = CubDebug(cudaGetDeviceProperties(&deviceProp, dev));
if (error) break;
if (deviceProp.major < 1) {
fprintf(stderr, "Device does not support CUDA.\n");
exit(1);
}
device_giga_bandwidth = float(deviceProp.memoryBusWidth) * deviceProp.memoryClockRate * 2 / 8 / 1000 / 1000;
if (!CheckCmdLineFlag("quiet"))
{
printf(
"Using device %d: %s (PTX version %d, SM%d, %d SMs, "
"%lld free / %lld total MB physmem, "
"%.3f GB/s @ %d kHz mem clock, ECC %s)\n",
dev,
deviceProp.name,
ptx_version,
deviceProp.major * 100 + deviceProp.minor * 10,
deviceProp.multiProcessorCount,
(unsigned long long) device_free_physmem / 1024 / 1024,
(unsigned long long) device_total_physmem / 1024 / 1024,
device_giga_bandwidth,
deviceProp.memoryClockRate,
(deviceProp.ECCEnabled) ? "on" : "off");
fflush(stdout);
}
} while (0);
return error;
}
};
/******************************************************************************
* Random bits generator
******************************************************************************/
int g_num_rand_samples = 0;
template <typename T>
bool IsNaN(T val) { return false; }
template<>
__noinline__ bool IsNaN<float>(float val)
{
volatile unsigned int bits = reinterpret_cast<unsigned int &>(val);
return (((bits >= 0x7F800001) && (bits <= 0x7FFFFFFF)) ||
((bits >= 0xFF800001) && (bits <= 0xFFFFFFFF)));
}
template<>
__noinline__ bool IsNaN<float1>(float1 val)
{
return (IsNaN(val.x));
}
template<>
__noinline__ bool IsNaN<float2>(float2 val)
{
return (IsNaN(val.y) || IsNaN(val.x));
}
( run in 0.923 second using v1.01-cache-2.11-cpan-df04353d9ac )