29
29
#include " tc/core/cuda/cuda_rtc.h"
30
30
#include " tc/core/flags.h"
31
31
#include " tc/core/scope_guard.h"
32
+ #include " tc/core/utils/system.h"
32
33
33
34
namespace tc {
34
35
std::mutex nvrtc_mutex;
@@ -65,17 +66,6 @@ void checkOrCreateContext() {
65
66
}
66
67
67
68
namespace {
68
- static void checkedSystemCall (
69
- const std::string& cmd,
70
- const std::vector<std::string>& args) {
71
- std::stringstream command;
72
- command << cmd << " " ;
73
- for (const auto & s : args) {
74
- command << s << " " ;
75
- }
76
- TC_CHECK_EQ (std::system (command.str ().c_str ()), 0 ) << command.str ();
77
- }
78
-
79
69
static std::tuple<int , int , int > getCudaArchitecture () {
80
70
int device, major, minor;
81
71
CUdevice deviceHandle;
@@ -119,7 +109,7 @@ static std::string llvmCompile(
119
109
});
120
110
121
111
// Compile
122
- checkedSystemCall (
112
+ utils:: checkedSystemCall (
123
113
std::string (TC_STRINGIFY (TC_LLVM_BIN_DIR)) + " /clang++" ,
124
114
{" -x cuda " + inputFileName,
125
115
" --cuda-device-only" ,
@@ -134,7 +124,7 @@ static std::string llvmCompile(
134
124
" -o " + outputClangFile});
135
125
136
126
// Link libdevice before opt
137
- checkedSystemCall (
127
+ utils:: checkedSystemCall (
138
128
std::string (TC_STRINGIFY (TC_LLVM_BIN_DIR)) + " /llvm-link " ,
139
129
{outputClangFile,
140
130
std::string (TC_STRINGIFY (TC_CUDA_TOOLKIT_ROOT_DIR)) +
@@ -143,7 +133,7 @@ static std::string llvmCompile(
143
133
" -o " + outputLinkFile});
144
134
145
135
// Opt
146
- checkedSystemCall (
136
+ utils:: checkedSystemCall (
147
137
std::string (TC_STRINGIFY (TC_LLVM_BIN_DIR)) + " /opt" ,
148
138
{" -internalize" ,
149
139
std::string (" -internalize-public-api-list=" ) + name,
@@ -154,7 +144,7 @@ static std::string llvmCompile(
154
144
std::string (" -o " ) + outputOptFile});
155
145
156
146
// Ptx
157
- checkedSystemCall (
147
+ utils:: checkedSystemCall (
158
148
std::string (TC_STRINGIFY (TC_LLVM_BIN_DIR)) + " /llc" ,
159
149
{std::string (" -mcpu=" ) + arch,
160
150
outputOptFile,
@@ -188,7 +178,7 @@ static std::string nvccCompile(
188
178
// cstdio's std::remove to delete files
189
179
tc::ScopeGuard sgo ([&]() { std::remove (outputPtxFile.c_str ()); });
190
180
191
- checkedSystemCall (
181
+ utils:: checkedSystemCall (
192
182
std::string (TC_STRINGIFY (TC_CUDA_TOOLKIT_ROOT_DIR)) + " /bin/nvcc" ,
193
183
{" -x cu" ,
194
184
inputFileName,
0 commit comments