-
Notifications
You must be signed in to change notification settings - Fork 0
/
clUtilUtility.cc
138 lines (108 loc) · 3.45 KB
/
clUtilUtility.cc
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
#include "clUtilUtility.h"
using namespace std;
namespace clUtil
{
namespace Utility
{
std::vector<std::string> split(std::string str, char delimiter)
{
std::istringstream strStream(str);
std::vector<std::string> fields;
while(strStream.good() == true)
{
std::string currentField;
getline(strStream, currentField, delimiter);
fields.push_back(currentField);
}
return fields;
}
cl_int fetchDeviceInfo(cl_device_id deviceID,
cl_device_info paramName,
std::string& param)
{
size_t propertySize;
cl_int err;
err = clGetDeviceInfo(deviceID,
paramName,
0,
NULL,
&propertySize);
clUtilCheckError(err);
std::unique_ptr<char[]> propertyString(new char[propertySize]);
err = clGetDeviceInfo(deviceID,
paramName,
propertySize,
propertyString.get(),
NULL);
clUtilCheckError(err);
param = std::string(propertyString.get(),
strnlen(propertyString.get(), propertySize));
return CL_SUCCESS;
}
cl_int fetchPlatformInfo(cl_platform_id platformID,
cl_platform_info paramName,
std::string& param)
{
cl_int err;
size_t paramSize;
err = clGetPlatformInfo(platformID, paramName, 0, NULL, ¶mSize);
clUtilCheckError(err);
std::unique_ptr<char[]> paramString(new char[paramSize]);
err = clGetPlatformInfo(platformID,
paramName,
paramSize,
paramString.get(),
NULL);
clUtilCheckError(err);
param = std::string(paramString.get(), paramSize);
return CL_SUCCESS;
}
double getTime()
{
#if defined(__WIN32) || defined(WIN32)
FILETIME fileTime;
uint64_t result = 0;
GetSystemTimeAsFileTime(&fileTime);
result |= fileTime.dwHighDateTime;
result <<= 32;
result |= fileTime.dwLowDateTime;
return result / 1e7;
#else
struct timeval time;
gettimeofday(&time, NULL);
return (double)time.tv_sec + (double)time.tv_usec / 1e6;
#endif
}
bool directoryExists(const char* directoryName)
{
#if defined(__WIN32) || defined(WIN32)
DWORD fileType = GetFileAttributes(directoryName);
return fileType != INVALID_FILE_ATTRIBUTES &&
fileType & FILE_ATTRIBUTE_DIRECTORY;
#else
struct stat autotuningDir;
int err = stat(directoryName, &autotuningDir);
return err == 0 && S_ISDIR(autotuningDir.st_mode);
#endif
}
bool fileExists(const char* fileName)
{
#if defined(__WIN32) || defined(WIN32)
DWORD fileType = GetFileAttributes(fileName);
return fileType != INVALID_FILE_ATTRIBUTES &&
fileType & FILE_ATTRIBUTE_NORMAL;
#else
struct stat fileStat;
return stat(filename, &fileStat) == 0 && S_ISREG(fileStat.st_mode);
#endif
}
bool makeDirectory(const char* directoryName)
{
#if defined(__WIN32) || defined(WIN32)
return CreateDirectory(directoryName, NULL) != TRUE;
#else
return mkdir(directoryName, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1;
#endif
}
}
}