This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuda_strings.cu
78 lines (67 loc) · 1.61 KB
/
cuda_strings.cu
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
#include "cuda_strings.hpp"
#include <algorithm>
#include <cstring>
#include <sstream>
namespace clover{
std::string matchParam
(FILE * input,
const char* param_name)
{
std::string param_string;
static char name_buf[101];
rewind(input);
/* read in line from file */
while (NULL != fgets(name_buf, 100, input))
{
/* ignore line */
if (NULL != strstr(name_buf, "!"))
{
continue;
}
/* if it has the parameter name, its the line we want */
if (NULL != strstr(name_buf, param_name))
{
if (NULL != strstr(name_buf, "="))
{
*(strstr(name_buf, "=")) = ' ';
char param_buf[100];
sscanf(name_buf, "%*s %s", param_buf);
param_string = std::string(param_buf);
break;
}
else
{
param_string = std::string("NO_SETTING");
break;
}
}
}
return param_string;
}
bool paramEnabled
(FILE* input, const char* param)
{
std::string param_string = matchParam(input, param);
return param_string.size() > 0 ? true : false;
}
int preferredDevice
(FILE* input)
{
std::string param_string = matchParam(input, "cuda_device");
int preferred_device;
if (param_string.size() == 0)
{
// not found in file
preferred_device = -1;
}
else
{
std::stringstream converter(param_string);
if (!(converter >> preferred_device))
{
preferred_device = -1;
}
}
return preferred_device;
}
}