Skip to content

Commit 16cb75c

Browse files
committed
NVML Checks: stderr Writing
Do not write randomly to stderr even if errors are catched.
1 parent 21050ab commit 16cb75c

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

cuda_memtest.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define __MEMTEST_H__
4343

4444
#include <cstdio>
45+
#include <sstream>
4546
#include <stdint.h>
4647
#include <pthread.h>
4748
#include <iostream>
@@ -143,11 +144,26 @@ extern void get_driver_info(char* info, unsigned int len);
143144
*
144145
* @param cmd command with nvmlReturn_t return value to check
145146
*/
146-
#define NVML_CHECK(cmd) {nvmlReturn_t returnVal = cmd; if(returnVal!=NVML_SUCCESS){std::cerr<<"<"<<__FILE__<<">:"<<__LINE__<<std::endl; throw std::runtime_error(std::string("[NVML] Error: ") + std::string(nvmlErrorString(returnVal)));}}
147-
148-
#define NVML_CHECK_MSG(cmd,msg) {nvmlReturn_t returnVal = cmd; if(returnVal!=NVML_SUCCESS){std::cerr<<"<"<<__FILE__<<">:"<<__LINE__<<msg<<std::endl; throw std::runtime_error(std::string("[NVML] Error: ") + std::string(nvmlErrorString(returnVal)));}}
149-
150-
#define NVML_CHECK_NO_EXCEP(cmd) {nvmlReturn_t returnVal = cmd; if(returnVal!=NVML_SUCCESS){std::cerr<<"[NVML] Error: <"<<__FILE__<<">:"<<__LINE__<<std::endl;}}
147+
#define NVML_CHECK(cmd) {nvmlReturn_t returnVal = cmd; if(returnVal!=NVML_SUCCESS){ \
148+
std::ostringstream sstr; \
149+
sstr << "[NVML] Error: '" << nvmlErrorString(returnVal) << \
150+
<< "' in <" << __FILE__ << ">:" <<__LINE__; \
151+
throw std::runtime_error(sstr.str()); \
152+
}}
153+
154+
#define NVML_CHECK_MSG(cmd,msg) {nvmlReturn_t returnVal = cmd; if(returnVal!=NVML_SUCCESS){ \
155+
std::ostringstream sstr; \
156+
sstr << "[NVML] Error: '" << nvmlErrorString(returnVal) << \
157+
<< "' in <" << __FILE__ << ">:" <<__LINE__ \
158+
<< " " << msg; \
159+
throw std::runtime_error(sstr.str()); \
160+
}}
161+
162+
#define NVML_CHECK_NO_EXCEP(cmd) {nvmlReturn_t returnVal = cmd; if(returnVal!=NVML_SUCCESS){{ \
163+
std::cerr << "[NVML] Error: '" << nvmlErrorString(returnVal) << \
164+
<< "' in <" << __FILE__ << ">:" <<__LINE__ \
165+
<< std::endl \
166+
}}
151167
#endif
152168

153169
#define TDIFF(tb, ta) (tb.tv_sec - ta.tv_sec + 0.000001*(tb.tv_usec - ta.tv_usec))

0 commit comments

Comments
 (0)