annotate src/parallel_execution/helper_string.h @ 411:0eba9a04633f

Work CUDAtwice
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 14 Sep 2017 18:26:52 +0900
parents 8c2123bb577b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
291
87128b876c63 add test
ikkun
parents:
diff changeset
1 /**
87128b876c63 add test
ikkun
parents:
diff changeset
2 * Copyright 1993-2013 NVIDIA Corporation. All rights reserved.
87128b876c63 add test
ikkun
parents:
diff changeset
3 *
87128b876c63 add test
ikkun
parents:
diff changeset
4 * Please refer to the NVIDIA end user license agreement (EULA) associated
87128b876c63 add test
ikkun
parents:
diff changeset
5 * with this source code for terms and conditions that govern your use of
87128b876c63 add test
ikkun
parents:
diff changeset
6 * this software. Any use, reproduction, disclosure, or distribution of
87128b876c63 add test
ikkun
parents:
diff changeset
7 * this software and related documentation outside the terms of the EULA
87128b876c63 add test
ikkun
parents:
diff changeset
8 * is strictly prohibited.
87128b876c63 add test
ikkun
parents:
diff changeset
9 *
87128b876c63 add test
ikkun
parents:
diff changeset
10 */
87128b876c63 add test
ikkun
parents:
diff changeset
11
87128b876c63 add test
ikkun
parents:
diff changeset
12 // These are helper functions for the SDK samples (string parsing, timers, etc)
87128b876c63 add test
ikkun
parents:
diff changeset
13 #ifndef STRING_HELPER_H
87128b876c63 add test
ikkun
parents:
diff changeset
14 #define STRING_HELPER_H
87128b876c63 add test
ikkun
parents:
diff changeset
15
87128b876c63 add test
ikkun
parents:
diff changeset
16 #include <stdio.h>
87128b876c63 add test
ikkun
parents:
diff changeset
17 #include <stdlib.h>
303
1dbaef86593b CUDAtwice.cbc
ikkun
parents: 291
diff changeset
18 #include <string.h>
291
87128b876c63 add test
ikkun
parents:
diff changeset
19
87128b876c63 add test
ikkun
parents:
diff changeset
20 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
87128b876c63 add test
ikkun
parents:
diff changeset
21 #ifndef _CRT_SECURE_NO_DEPRECATE
87128b876c63 add test
ikkun
parents:
diff changeset
22 #define _CRT_SECURE_NO_DEPRECATE
87128b876c63 add test
ikkun
parents:
diff changeset
23 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
24 #ifndef STRCASECMP
87128b876c63 add test
ikkun
parents:
diff changeset
25 #define STRCASECMP _stricmp
87128b876c63 add test
ikkun
parents:
diff changeset
26 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
27 #ifndef STRNCASECMP
87128b876c63 add test
ikkun
parents:
diff changeset
28 #define STRNCASECMP _strnicmp
87128b876c63 add test
ikkun
parents:
diff changeset
29 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
30 #ifndef STRCPY
87128b876c63 add test
ikkun
parents:
diff changeset
31 #define STRCPY(sFilePath, nLength, sPath) strcpy_s(sFilePath, nLength, sPath)
87128b876c63 add test
ikkun
parents:
diff changeset
32 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
33
87128b876c63 add test
ikkun
parents:
diff changeset
34 #ifndef FOPEN
87128b876c63 add test
ikkun
parents:
diff changeset
35 #define FOPEN(fHandle,filename,mode) fopen_s(&fHandle, filename, mode)
87128b876c63 add test
ikkun
parents:
diff changeset
36 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
37 #ifndef FOPEN_FAIL
87128b876c63 add test
ikkun
parents:
diff changeset
38 #define FOPEN_FAIL(result) (result != 0)
87128b876c63 add test
ikkun
parents:
diff changeset
39 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
40 #ifndef SSCANF
87128b876c63 add test
ikkun
parents:
diff changeset
41 #define SSCANF sscanf_s
87128b876c63 add test
ikkun
parents:
diff changeset
42 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
43 #ifndef SPRINTF
87128b876c63 add test
ikkun
parents:
diff changeset
44 #define SPRINTF sprintf_s
87128b876c63 add test
ikkun
parents:
diff changeset
45 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
46 #else // Linux Includes
87128b876c63 add test
ikkun
parents:
diff changeset
47 #include <string.h>
87128b876c63 add test
ikkun
parents:
diff changeset
48 #include <strings.h>
87128b876c63 add test
ikkun
parents:
diff changeset
49
87128b876c63 add test
ikkun
parents:
diff changeset
50 #ifndef STRCASECMP
87128b876c63 add test
ikkun
parents:
diff changeset
51 #define STRCASECMP strcasecmp
87128b876c63 add test
ikkun
parents:
diff changeset
52 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
53 #ifndef STRNCASECMP
87128b876c63 add test
ikkun
parents:
diff changeset
54 #define STRNCASECMP strncasecmp
87128b876c63 add test
ikkun
parents:
diff changeset
55 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
56 #ifndef STRCPY
87128b876c63 add test
ikkun
parents:
diff changeset
57 #define STRCPY(sFilePath, nLength, sPath) strcpy(sFilePath, sPath)
87128b876c63 add test
ikkun
parents:
diff changeset
58 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
59
87128b876c63 add test
ikkun
parents:
diff changeset
60 #ifndef FOPEN
87128b876c63 add test
ikkun
parents:
diff changeset
61 #define FOPEN(fHandle,filename,mode) (fHandle = fopen(filename, mode))
87128b876c63 add test
ikkun
parents:
diff changeset
62 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
63 #ifndef FOPEN_FAIL
87128b876c63 add test
ikkun
parents:
diff changeset
64 #define FOPEN_FAIL(result) (result == NULL)
87128b876c63 add test
ikkun
parents:
diff changeset
65 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
66 #ifndef SSCANF
87128b876c63 add test
ikkun
parents:
diff changeset
67 #define SSCANF sscanf
87128b876c63 add test
ikkun
parents:
diff changeset
68 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
69 #ifndef SPRINTF
87128b876c63 add test
ikkun
parents:
diff changeset
70 #define SPRINTF sprintf
87128b876c63 add test
ikkun
parents:
diff changeset
71 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
72 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
73
87128b876c63 add test
ikkun
parents:
diff changeset
74 #ifndef EXIT_WAIVED
87128b876c63 add test
ikkun
parents:
diff changeset
75 #define EXIT_WAIVED 2
87128b876c63 add test
ikkun
parents:
diff changeset
76 #endif
87128b876c63 add test
ikkun
parents:
diff changeset
77
309
8c2123bb577b fix compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 304
diff changeset
78 #ifndef bool
8c2123bb577b fix compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 304
diff changeset
79 typedef int bool;
8c2123bb577b fix compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 304
diff changeset
80 #define false 0
8c2123bb577b fix compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 304
diff changeset
81 #define true 1
8c2123bb577b fix compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 304
diff changeset
82 #endif
8c2123bb577b fix compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 304
diff changeset
83
291
87128b876c63 add test
ikkun
parents:
diff changeset
84 // CUDA Utility Helper Functions
87128b876c63 add test
ikkun
parents:
diff changeset
85 inline int stringRemoveDelimiter(char delimiter, const char *string)
87128b876c63 add test
ikkun
parents:
diff changeset
86 {
87128b876c63 add test
ikkun
parents:
diff changeset
87 int string_start = 0;
87128b876c63 add test
ikkun
parents:
diff changeset
88
87128b876c63 add test
ikkun
parents:
diff changeset
89 while (string[string_start] == delimiter)
87128b876c63 add test
ikkun
parents:
diff changeset
90 {
87128b876c63 add test
ikkun
parents:
diff changeset
91 string_start++;
87128b876c63 add test
ikkun
parents:
diff changeset
92 }
87128b876c63 add test
ikkun
parents:
diff changeset
93
87128b876c63 add test
ikkun
parents:
diff changeset
94 if (string_start >= (int)strlen(string)-1)
87128b876c63 add test
ikkun
parents:
diff changeset
95 {
87128b876c63 add test
ikkun
parents:
diff changeset
96 return 0;
87128b876c63 add test
ikkun
parents:
diff changeset
97 }
87128b876c63 add test
ikkun
parents:
diff changeset
98
87128b876c63 add test
ikkun
parents:
diff changeset
99 return string_start;
87128b876c63 add test
ikkun
parents:
diff changeset
100 }
87128b876c63 add test
ikkun
parents:
diff changeset
101
87128b876c63 add test
ikkun
parents:
diff changeset
102 inline int getFileExtension(char *filename, char **extension)
87128b876c63 add test
ikkun
parents:
diff changeset
103 {
87128b876c63 add test
ikkun
parents:
diff changeset
104 int string_length = (int)strlen(filename);
87128b876c63 add test
ikkun
parents:
diff changeset
105
87128b876c63 add test
ikkun
parents:
diff changeset
106 while (filename[string_length--] != '.')
87128b876c63 add test
ikkun
parents:
diff changeset
107 {
87128b876c63 add test
ikkun
parents:
diff changeset
108 if (string_length == 0)
87128b876c63 add test
ikkun
parents:
diff changeset
109 break;
87128b876c63 add test
ikkun
parents:
diff changeset
110 }
87128b876c63 add test
ikkun
parents:
diff changeset
111
87128b876c63 add test
ikkun
parents:
diff changeset
112 if (string_length > 0) string_length += 2;
87128b876c63 add test
ikkun
parents:
diff changeset
113
87128b876c63 add test
ikkun
parents:
diff changeset
114 if (string_length == 0)
87128b876c63 add test
ikkun
parents:
diff changeset
115 *extension = NULL;
87128b876c63 add test
ikkun
parents:
diff changeset
116 else
87128b876c63 add test
ikkun
parents:
diff changeset
117 *extension = &filename[string_length];
87128b876c63 add test
ikkun
parents:
diff changeset
118
87128b876c63 add test
ikkun
parents:
diff changeset
119 return string_length;
87128b876c63 add test
ikkun
parents:
diff changeset
120 }
87128b876c63 add test
ikkun
parents:
diff changeset
121
87128b876c63 add test
ikkun
parents:
diff changeset
122
87128b876c63 add test
ikkun
parents:
diff changeset
123 inline bool checkCmdLineFlag(const int argc, const char **argv, const char *string_ref)
87128b876c63 add test
ikkun
parents:
diff changeset
124 {
87128b876c63 add test
ikkun
parents:
diff changeset
125 bool bFound = false;
87128b876c63 add test
ikkun
parents:
diff changeset
126
87128b876c63 add test
ikkun
parents:
diff changeset
127 if (argc >= 1)
87128b876c63 add test
ikkun
parents:
diff changeset
128 {
87128b876c63 add test
ikkun
parents:
diff changeset
129 for (int i=1; i < argc; i++)
87128b876c63 add test
ikkun
parents:
diff changeset
130 {
87128b876c63 add test
ikkun
parents:
diff changeset
131 int string_start = stringRemoveDelimiter('-', argv[i]);
87128b876c63 add test
ikkun
parents:
diff changeset
132 const char *string_argv = &argv[i][string_start];
87128b876c63 add test
ikkun
parents:
diff changeset
133
87128b876c63 add test
ikkun
parents:
diff changeset
134 const char *equal_pos = strchr(string_argv, '=');
87128b876c63 add test
ikkun
parents:
diff changeset
135 int argv_length = (int)(equal_pos == 0 ? strlen(string_argv) : equal_pos - string_argv);
87128b876c63 add test
ikkun
parents:
diff changeset
136
87128b876c63 add test
ikkun
parents:
diff changeset
137 int length = (int)strlen(string_ref);
87128b876c63 add test
ikkun
parents:
diff changeset
138
87128b876c63 add test
ikkun
parents:
diff changeset
139 if (length == argv_length && !STRNCASECMP(string_argv, string_ref, length))
87128b876c63 add test
ikkun
parents:
diff changeset
140 {
87128b876c63 add test
ikkun
parents:
diff changeset
141 bFound = true;
87128b876c63 add test
ikkun
parents:
diff changeset
142 continue;
87128b876c63 add test
ikkun
parents:
diff changeset
143 }
87128b876c63 add test
ikkun
parents:
diff changeset
144 }
87128b876c63 add test
ikkun
parents:
diff changeset
145 }
87128b876c63 add test
ikkun
parents:
diff changeset
146
87128b876c63 add test
ikkun
parents:
diff changeset
147 return bFound;
87128b876c63 add test
ikkun
parents:
diff changeset
148 }
87128b876c63 add test
ikkun
parents:
diff changeset
149
87128b876c63 add test
ikkun
parents:
diff changeset
150
87128b876c63 add test
ikkun
parents:
diff changeset
151 inline int getCmdLineArgumentInt(const int argc, const char **argv, const char *string_ref)
87128b876c63 add test
ikkun
parents:
diff changeset
152 {
87128b876c63 add test
ikkun
parents:
diff changeset
153 bool bFound = false;
87128b876c63 add test
ikkun
parents:
diff changeset
154 int value = -1;
87128b876c63 add test
ikkun
parents:
diff changeset
155
87128b876c63 add test
ikkun
parents:
diff changeset
156 if (argc >= 1)
87128b876c63 add test
ikkun
parents:
diff changeset
157 {
87128b876c63 add test
ikkun
parents:
diff changeset
158 for (int i=1; i < argc; i++)
87128b876c63 add test
ikkun
parents:
diff changeset
159 {
87128b876c63 add test
ikkun
parents:
diff changeset
160 int string_start = stringRemoveDelimiter('-', argv[i]);
87128b876c63 add test
ikkun
parents:
diff changeset
161 const char *string_argv = &argv[i][string_start];
87128b876c63 add test
ikkun
parents:
diff changeset
162 int length = (int)strlen(string_ref);
87128b876c63 add test
ikkun
parents:
diff changeset
163
87128b876c63 add test
ikkun
parents:
diff changeset
164 if (!STRNCASECMP(string_argv, string_ref, length))
87128b876c63 add test
ikkun
parents:
diff changeset
165 {
87128b876c63 add test
ikkun
parents:
diff changeset
166 if (length+1 <= (int)strlen(string_argv))
87128b876c63 add test
ikkun
parents:
diff changeset
167 {
87128b876c63 add test
ikkun
parents:
diff changeset
168 int auto_inc = (string_argv[length] == '=') ? 1 : 0;
87128b876c63 add test
ikkun
parents:
diff changeset
169 value = atoi(&string_argv[length + auto_inc]);
87128b876c63 add test
ikkun
parents:
diff changeset
170 }
87128b876c63 add test
ikkun
parents:
diff changeset
171 else
87128b876c63 add test
ikkun
parents:
diff changeset
172 {
87128b876c63 add test
ikkun
parents:
diff changeset
173 value = 0;
87128b876c63 add test
ikkun
parents:
diff changeset
174 }
87128b876c63 add test
ikkun
parents:
diff changeset
175
87128b876c63 add test
ikkun
parents:
diff changeset
176 bFound = true;
87128b876c63 add test
ikkun
parents:
diff changeset
177 continue;
87128b876c63 add test
ikkun
parents:
diff changeset
178 }
87128b876c63 add test
ikkun
parents:
diff changeset
179 }
87128b876c63 add test
ikkun
parents:
diff changeset
180 }
87128b876c63 add test
ikkun
parents:
diff changeset
181
87128b876c63 add test
ikkun
parents:
diff changeset
182 if (bFound)
87128b876c63 add test
ikkun
parents:
diff changeset
183 {
87128b876c63 add test
ikkun
parents:
diff changeset
184 return value;
87128b876c63 add test
ikkun
parents:
diff changeset
185 }
87128b876c63 add test
ikkun
parents:
diff changeset
186 else
87128b876c63 add test
ikkun
parents:
diff changeset
187 {
87128b876c63 add test
ikkun
parents:
diff changeset
188 return 0;
87128b876c63 add test
ikkun
parents:
diff changeset
189 }
87128b876c63 add test
ikkun
parents:
diff changeset
190 }
87128b876c63 add test
ikkun
parents:
diff changeset
191
87128b876c63 add test
ikkun
parents:
diff changeset
192 inline float getCmdLineArgumentFloat(const int argc, const char **argv, const char *string_ref)
87128b876c63 add test
ikkun
parents:
diff changeset
193 {
87128b876c63 add test
ikkun
parents:
diff changeset
194 bool bFound = false;
87128b876c63 add test
ikkun
parents:
diff changeset
195 float value = -1;
87128b876c63 add test
ikkun
parents:
diff changeset
196
87128b876c63 add test
ikkun
parents:
diff changeset
197 if (argc >= 1)
87128b876c63 add test
ikkun
parents:
diff changeset
198 {
87128b876c63 add test
ikkun
parents:
diff changeset
199 for (int i=1; i < argc; i++)
87128b876c63 add test
ikkun
parents:
diff changeset
200 {
87128b876c63 add test
ikkun
parents:
diff changeset
201 int string_start = stringRemoveDelimiter('-', argv[i]);
87128b876c63 add test
ikkun
parents:
diff changeset
202 const char *string_argv = &argv[i][string_start];
87128b876c63 add test
ikkun
parents:
diff changeset
203 int length = (int)strlen(string_ref);
87128b876c63 add test
ikkun
parents:
diff changeset
204
87128b876c63 add test
ikkun
parents:
diff changeset
205 if (!STRNCASECMP(string_argv, string_ref, length))
87128b876c63 add test
ikkun
parents:
diff changeset
206 {
87128b876c63 add test
ikkun
parents:
diff changeset
207 if (length+1 <= (int)strlen(string_argv))
87128b876c63 add test
ikkun
parents:
diff changeset
208 {
87128b876c63 add test
ikkun
parents:
diff changeset
209 int auto_inc = (string_argv[length] == '=') ? 1 : 0;
87128b876c63 add test
ikkun
parents:
diff changeset
210 value = (float)atof(&string_argv[length + auto_inc]);
87128b876c63 add test
ikkun
parents:
diff changeset
211 }
87128b876c63 add test
ikkun
parents:
diff changeset
212 else
87128b876c63 add test
ikkun
parents:
diff changeset
213 {
87128b876c63 add test
ikkun
parents:
diff changeset
214 value = 0.f;
87128b876c63 add test
ikkun
parents:
diff changeset
215 }
87128b876c63 add test
ikkun
parents:
diff changeset
216
87128b876c63 add test
ikkun
parents:
diff changeset
217 bFound = true;
87128b876c63 add test
ikkun
parents:
diff changeset
218 continue;
87128b876c63 add test
ikkun
parents:
diff changeset
219 }
87128b876c63 add test
ikkun
parents:
diff changeset
220 }
87128b876c63 add test
ikkun
parents:
diff changeset
221 }
87128b876c63 add test
ikkun
parents:
diff changeset
222
87128b876c63 add test
ikkun
parents:
diff changeset
223 if (bFound)
87128b876c63 add test
ikkun
parents:
diff changeset
224 {
87128b876c63 add test
ikkun
parents:
diff changeset
225 return value;
87128b876c63 add test
ikkun
parents:
diff changeset
226 }
87128b876c63 add test
ikkun
parents:
diff changeset
227 else
87128b876c63 add test
ikkun
parents:
diff changeset
228 {
87128b876c63 add test
ikkun
parents:
diff changeset
229 return 0;
87128b876c63 add test
ikkun
parents:
diff changeset
230 }
87128b876c63 add test
ikkun
parents:
diff changeset
231 }
87128b876c63 add test
ikkun
parents:
diff changeset
232
87128b876c63 add test
ikkun
parents:
diff changeset
233 inline bool getCmdLineArgumentString(const int argc, const char **argv,
87128b876c63 add test
ikkun
parents:
diff changeset
234 const char *string_ref, char **string_retval)
87128b876c63 add test
ikkun
parents:
diff changeset
235 {
87128b876c63 add test
ikkun
parents:
diff changeset
236 bool bFound = false;
87128b876c63 add test
ikkun
parents:
diff changeset
237
87128b876c63 add test
ikkun
parents:
diff changeset
238 if (argc >= 1)
87128b876c63 add test
ikkun
parents:
diff changeset
239 {
87128b876c63 add test
ikkun
parents:
diff changeset
240 for (int i=1; i < argc; i++)
87128b876c63 add test
ikkun
parents:
diff changeset
241 {
87128b876c63 add test
ikkun
parents:
diff changeset
242 int string_start = stringRemoveDelimiter('-', argv[i]);
87128b876c63 add test
ikkun
parents:
diff changeset
243 char *string_argv = (char *)&argv[i][string_start];
87128b876c63 add test
ikkun
parents:
diff changeset
244 int length = (int)strlen(string_ref);
87128b876c63 add test
ikkun
parents:
diff changeset
245
87128b876c63 add test
ikkun
parents:
diff changeset
246 if (!STRNCASECMP(string_argv, string_ref, length))
87128b876c63 add test
ikkun
parents:
diff changeset
247 {
87128b876c63 add test
ikkun
parents:
diff changeset
248 *string_retval = &string_argv[length+1];
87128b876c63 add test
ikkun
parents:
diff changeset
249 bFound = true;
87128b876c63 add test
ikkun
parents:
diff changeset
250 continue;
87128b876c63 add test
ikkun
parents:
diff changeset
251 }
87128b876c63 add test
ikkun
parents:
diff changeset
252 }
87128b876c63 add test
ikkun
parents:
diff changeset
253 }
87128b876c63 add test
ikkun
parents:
diff changeset
254
87128b876c63 add test
ikkun
parents:
diff changeset
255 if (!bFound)
87128b876c63 add test
ikkun
parents:
diff changeset
256 {
87128b876c63 add test
ikkun
parents:
diff changeset
257 *string_retval = NULL;
87128b876c63 add test
ikkun
parents:
diff changeset
258 }
87128b876c63 add test
ikkun
parents:
diff changeset
259
87128b876c63 add test
ikkun
parents:
diff changeset
260 return bFound;
87128b876c63 add test
ikkun
parents:
diff changeset
261 }
87128b876c63 add test
ikkun
parents:
diff changeset
262
87128b876c63 add test
ikkun
parents:
diff changeset
263
87128b876c63 add test
ikkun
parents:
diff changeset
264 #endif