Commit ca07b7f0 authored by fenglei.tian's avatar fenglei.tian

fix compiling bugs

parent 1a91c924
...@@ -25,39 +25,41 @@ ...@@ -25,39 +25,41 @@
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
#define NVRTC_SAFE_CALL(x) \ #define NVRTC_SAFE_CALL(x) \
do { \ do \
nvrtcResult result = x; \ { \
if (result != NVRTC_SUCCESS) { \ nvrtcResult result = x; \
std::cerr << "\nerror: " #x " failed with error " \ if (result != NVRTC_SUCCESS) \
<< nvrtcGetErrorString(result) << '\n'; \ { \
exit(1); \ std::cerr << "\nerror: " #x " failed with error " << nvrtcGetErrorString(result) \
} \ << '\n'; \
} while(0) exit(1); \
} \
} while (0)
#define CUDA_SAFE_CALL(x) \ #define CUDA_SAFE_CALL(x) \
do { \ do \
CUresult result = x; \ { \
if (result != CUDA_SUCCESS) { \ CUresult result = x; \
const char *msg; \ if (result != CUDA_SUCCESS) \
cuGetErrorName(result, &msg); \ { \
std::cerr << "\nerror: " #x " failed with error " \ const char* msg; \
<< msg << '\n'; \ cuGetErrorName(result, &msg); \
exit(1); \ std::cerr << "\nerror: " #x " failed with error " << msg << '\n'; \
} \ exit(1); \
} while(0) } \
} while (0)
runtime::gpu::GPU_CallFrame::GPU_CallFrame(std::shared_ptr<GPU_ExternalFunction> external_function, runtime::gpu::GPU_CallFrame::GPU_CallFrame(std::shared_ptr<GPU_ExternalFunction> external_function,
EntryPoint compiled_function) EntryPoint compiled_function)
: m_external_function(external_function) : m_external_function(external_function)
, m_compiled_function(compiled_function) , m_compiled_function(compiled_function)
{ {
CUdevice cuDevice; CUdevice cuDevice;
CUcontext context; CUcontext context;
CUmodule module; CUmodule module;
CUfunction cuda_op_abs_kernel; CUfunction cuda_op_abs_kernel;
CUDA_SAFE_CALL( cuInit(0)); CUDA_SAFE_CALL(cuInit(0));
CUDA_SAFE_CALL(cuDeviceGet(&cuDevice, 0)); CUDA_SAFE_CALL(cuDeviceGet(&cuDevice, 0));
CUDA_SAFE_CALL(cuCtxCreate(&context, 0, cuDevice)); CUDA_SAFE_CALL(cuCtxCreate(&context, 0, cuDevice));
cublasStatus_t cublasStatus = cublasCreate(&m_cublas_handle); cublasStatus_t cublasStatus = cublasCreate(&m_cublas_handle);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include "ngraph/runtime/gpu/gpu_util.hpp"
namespace ngraph namespace ngraph
{ {
...@@ -26,24 +27,20 @@ namespace ngraph ...@@ -26,24 +27,20 @@ namespace ngraph
{ {
class Cuda_context_manager class Cuda_context_manager
{ {
public: public:
static Cuda_context_manager& Instance() static Cuda_context_manager& Instance()
{ {
static Cuda_context_manager manager; static Cuda_context_manager manager;
return pool; return manager;
} }
Cuda_context_manager(Cuda_context_manager const&) = delete; Cuda_context_manager(Cuda_context_manager const&) = delete;
Cuda_context_manager(Cuda_context_manager&&) = delete; Cuda_context_manager(Cuda_context_manager&&) = delete;
Cuda_context_manager& operator=(Cuda_context_manager const&) = delete; Cuda_context_manager& operator=(Cuda_context_manager const&) = delete;
Cuda_context_manager& operator=(Cuda_context_manager &&) = delete; Cuda_context_manager& operator=(Cuda_context_manager&&) = delete;
std::shared_ptr<CUcontext> GetContext() std::shared_ptr<CUcontext> GetContext() { return context_ptr; }
{ protected:
return context_ptr;
}
protected:
Cuda_context_manager() Cuda_context_manager()
{ {
CUDA_SAFE_CALL(cuInit(0)); CUDA_SAFE_CALL(cuInit(0));
...@@ -51,11 +48,11 @@ namespace ngraph ...@@ -51,11 +48,11 @@ namespace ngraph
CUDA_SAFE_CALL(cuCtxCreate(&context, 0, cuDevice)); CUDA_SAFE_CALL(cuCtxCreate(&context, 0, cuDevice));
context_ptr = std::make_shared<CUcontext>(context); context_ptr = std::make_shared<CUcontext>(context);
} }
~Cuda_context_manager(){} ~Cuda_context_manager() {}
CUdevice cuDevice; CUdevice cuDevice;
CUcontext context; CUcontext context;
std::shared_ptr<CUcontext> context_ptr; std::shared_ptr<CUcontext> context_ptr;
} };
} }
} }
} }
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#include <string> #include <string>
#include "ngraph/runtime/gpu/gpu_util.hpp"
#include "ngraph/runtime/gpu/gpu_cuda_context_manager.hpp" #include "ngraph/runtime/gpu/gpu_cuda_context_manager.hpp"
#include "ngraph/runtime/gpu/gpu_util.hpp"
namespace ngraph namespace ngraph
{ {
...@@ -29,44 +29,49 @@ namespace ngraph ...@@ -29,44 +29,49 @@ namespace ngraph
{ {
class Cuda_function_builder class Cuda_function_builder
{ {
public: public:
static std::shared_ptr<CUfuction> get(std::string& kernel, std::string& name, int number_of_options, std::string options) static std::shared_ptr<CUfunction> Get(std::string& kernel,
std::string& name,
int number_of_options,
const char** options)
{ {
nvrtcProgram prog; nvrtcProgram prog;
NVRTC_SAFE_CALL(nvrtcCreateProgram(&prog, NVRTC_SAFE_CALL(nvrtcCreateProgram(&prog,
kernel.c_str(), kernel.c_str(),
"op.cu", "op.cu",
0, // numHeaders 0, // numHeaders
NULL, // headers NULL, // headers
NULL)); // includeNames NULL)); // includeNames
nvrtcResult compileResult =
nvrtcCompileProgram(prog, number_of_options, options);
nvrtcResult compileResult = nvrtcCompileProgram(prog, if (compileResult != NVRTC_SUCCESS)
number_of_options, {
options); // size_t logSize;
// NVRTC_SAFE_CALL(nvrtcGetProgramLogSize(prog, &logSize));
// char *log = new char[logSize];
// NVRTC_SAFE_CALL(nvrtcGetProgramLog(prog, log));
// std::cout << log << '\n';
// delete[] log;
throw std::runtime_error("compile error: \n" + kernel + "\n options");
}
if (compileResult != NVRTC_SUCCESS) { size_t ptxSize;
// size_t logSize; NVRTC_SAFE_CALL(nvrtcGetPTXSize(prog, &ptxSize));
// NVRTC_SAFE_CALL(nvrtcGetProgramLogSize(prog, &logSize)); char* ptx = new char[ptxSize];
// char *log = new char[logSize]; NVRTC_SAFE_CALL(nvrtcGetPTX(
// NVRTC_SAFE_CALL(nvrtcGetProgramLog(prog, log)); prog,
// std::cout << log << '\n'; ptx)); // Load the generated PTX and get a handle to the parent kernel.
// delete[] log; NVRTC_SAFE_CALL(nvrtcDestroyProgram(&prog)); // Destroy the program.
throw std::runtime_error("compile error: \n" + kernel + "\n options" + options);
}
size_t ptxSize; CUmodule module;
NVRTC_SAFE_CALL(nvrtcGetPTXSize(prog, &ptxSize)); CUfunction function;
char *ptx = new char[ptxSize]; CUDA_SAFE_CALL(cuModuleLoadDataEx(&module, ptx, 0, 0, 0));
NVRTC_SAFE_CALL(nvrtcGetPTX(prog, ptx)); // Load the generated PTX and get a handle to the parent kernel. CUDA_SAFE_CALL(cuModuleGetFunction(&function, module, name.c_str()));
NVRTC_SAFE_CALL(nvrtcDestroyProgram(&prog)); // Destroy the program. return std::make_shared<CUfunction>(function);
CUmodule module;
CUfunction function;
CUDA_SAFE_CALL(cuModuleLoadDataEx(&module, ptx, 0, 0, 0));
CUDA_SAFE_CALL(cuModuleGetFunction(&function, module, name));
return std::make_shared<CUfunction>(function);
} }
} };
} }
} }
} }
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#pragma once #pragma once
#include <string> #include <string>
#include <unordered_map>
#include "ngraph/runtime/gpu/gpu_util.hpp"
namespace ngraph namespace ngraph
{ {
...@@ -26,7 +29,7 @@ namespace ngraph ...@@ -26,7 +29,7 @@ namespace ngraph
{ {
class Cuda_function_pool class Cuda_function_pool
{ {
public: public:
static Cuda_function_pool& Instance() static Cuda_function_pool& Instance()
{ {
static Cuda_function_pool pool; static Cuda_function_pool pool;
...@@ -36,29 +39,28 @@ namespace ngraph ...@@ -36,29 +39,28 @@ namespace ngraph
Cuda_function_pool(Cuda_function_pool const&) = delete; Cuda_function_pool(Cuda_function_pool const&) = delete;
Cuda_function_pool(Cuda_function_pool&&) = delete; Cuda_function_pool(Cuda_function_pool&&) = delete;
Cuda_function_pool& operator=(Cuda_function_pool const&) = delete; Cuda_function_pool& operator=(Cuda_function_pool const&) = delete;
Cuda_function_pool& operator=(Cuda_function_pool &&) = delete; Cuda_function_pool& operator=(Cuda_function_pool&&) = delete;
void Set(std::string& name, std::shared_ptr<CUfunction> function) void Set(std::string& name, std::shared_ptr<CUfunction> function)
{ {
CUfunction_map.insert({name,function}); CUfunction_map.insert({name, function});
} }
std::shared_ptr<CUfunction> Get(std::string& name) std::shared_ptr<CUfunction> Get(std::string& name)
{ {
auto it = CUfunction_map.find(name); auto it = CUfunction_map.find(name);
if(it != CUfunction_map.end()) if (it != CUfunction_map.end())
{ {
return (*it).second; return (*it).second;
} }
return nullptr; return nullptr;
} }
protected: protected:
Cuda_function_pool(){} Cuda_function_pool() {}
~Cuda_function_pool(){} ~Cuda_function_pool() {}
std::unordered_map<std::string, std::shared_ptr<CUfunction>> CUfunction_map; std::unordered_map<std::string, std::shared_ptr<CUfunction>> CUfunction_map;
} };
} }
} }
} }
...@@ -26,12 +26,16 @@ namespace ngraph ...@@ -26,12 +26,16 @@ namespace ngraph
{ {
class Cuda_kernel_builder class Cuda_kernel_builder
{ {
static std::string get_1_element_op(std::string& name, std::string& data_type, std::string& op, std::string& kernel) public:
static void Get_1_element_op(const std::string& name,
const std::string& data_type,
const std::string& op,
std::string& kernel)
{ {
kernel = R"( kernel = R"(
extern "C" __global__ extern "C" __global__
void cuda_op_)" + name + "(" + data_type + "* in, " + data_type + "* out, size_t n)\n" void cuda_op_)" + name + "(" +
+R"({ data_type + "* in, " + data_type + "* out, size_t n)\n" + R"({
size_t tid = blockIdx.x * blockDim.x + threadIdx.x; size_t tid = blockIdx.x * blockDim.x + threadIdx.x;
if(tid < n) if(tid < n)
{ {
...@@ -41,27 +45,34 @@ out[tid] = " + op + "(in[tid]);\n" ...@@ -41,27 +45,34 @@ out[tid] = " + op + "(in[tid]);\n"
return; return;
} }
static std::string get_2_element_op(std::string& name, std::string& data_type, std::string op, std::string& kernel) static void Get_2_element_op(const std::string& name,
const std::string& data_type,
const std::string op,
std::string& kernel)
{ {
kernel = R"( kernel = R"(
extern "C" __global__ extern "C" __global__
void cuda_op_)" + name + "(" + data_type + "* in1, " + data_type + "* in2, " + data_type + "* out, size_t n)\n" void cuda_op_)" + name + "(" +
+R"({ data_type + "* in1, " + data_type + "* in2, " + data_type +
"* out, size_t n)\n" + R"({
size_t tid = blockIdx.x * blockDim.x + threadIdx.x; size_t tid = blockIdx.x * blockDim.x + threadIdx.x;
if(tid < n) if(tid < n)
{ {
out[tid] = in1[tid] )" + op + "in2[tid]\n" out[tid] = in1[tid] )" + op + "in2[tid]\n" +
+R"(} R"(}
})"; })";
return; return;
} }
static std::string get_n_element_op(std::string& name, std::string& data_type, std::vector<std::string> ops, std::string& kernel) static void Get_n_element_op(const std::string& name,
const std::string& data_type,
const std::vector<std::string> ops,
std::string& kernel)
{ {
kernel = ""; kernel = "";
return; return;
} }
} };
} }
} }
} }
...@@ -17,18 +17,16 @@ ...@@ -17,18 +17,16 @@
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include <cublas_v2.h>
#include <nvrtc.h>
#include <cuda.h> #include <cuda.h>
#include <cuda_runtime.h> #include <cuda_runtime.h>
#include <cublas_v2.h>
#include <cudnn_v7.h> #include <cudnn_v7.h>
#include <nvrtc.h>
#include "ngraph/runtime/gpu/gpu_cuda_kernel_emitters.hpp" #include "ngraph/runtime/gpu/gpu_cuda_kernel_emitters.hpp"
#include "ngraph/runtime/gpu/gpu_cude_kernel_builder.hpp" #include "ngraph/runtime/gpu/gpu_cuda_function_builder.hpp"
#include "ngraph/runtime/gpu/gpu_cude_function_builder.hpp" #include "ngraph/runtime/gpu/gpu_cuda_function_pool.hpp"
#include "ngraph/runtime/gpu/gpu_cude_function_pool.hpp" #include "ngraph/runtime/gpu/gpu_cuda_kernel_builder.hpp"
namespace ngraph namespace ngraph
{ {
...@@ -40,42 +38,48 @@ namespace ngraph ...@@ -40,42 +38,48 @@ namespace ngraph
{ {
namespace kernel namespace kernel
{ {
void emit_abs(void* in, void* out, size_t count) void emit_abs(void* in, void* out, size_t count)
{ {
std::string name = "abs"; std::string name = "abs";
// Create an instance of nvrtcProgram with the code string. // Create an instance of nvrtcProgram with the code string.
if(Cuda_function_pool::Instance().get(name) == nullptr) if (Cuda_function_pool::Instance().Get(name) == nullptr)
{ {
const char *opts[] = {"--gpu-architecture=compute_35", const char* opts[] = {"--gpu-architecture=compute_35",
"--relocatable-device-code=true"}; "--relocatable-device-code=true"};
std::string kernel; std::string kernel;
Cuda_kernel_builder::get_1_element_op(name, "float", "fabsf",kernel); Cuda_kernel_builder::Get_1_element_op(name, "float", "fabsf", kernel);
Cuda_function_pool::Instance().set(name, Cuda_function_builder(name, kernel, 2, opts)); Cuda_function_pool::Instance().Set(
name, Cuda_function_builder::Get(name, kernel, 2, opts));
} }
//convert runtime ptr to driver api ptr //convert runtime ptr to driver api ptr
CUdeviceptr dPtrIn, dPtrOut; CUdeviceptr dPtrIn, dPtrOut;
dPtrIn = (CUdeviceptr)in; dPtrIn = (CUdeviceptr)in;
dPtrOut = (CUdeviceptr)out; dPtrOut = (CUdeviceptr)out;
void *argsList[] = {&dPtrIn, &dPtrOut, &count}; void* argsList[] = {&dPtrIn, &dPtrOut, &count};
CUDA_SAFE_CALL( CUDA_SAFE_CALL(
cuLaunchKernel(cudCuda_function_pool::Instance().get(name).get(), cuLaunchKernel(*Cuda_function_pool::Instance().Get(name).get(),
count ,1, 1, // grid dim count,
1, 1, 1, // block dim 1,
0, NULL, // shared mem and stream 1, // grid dim
argsList, 0)); // arguments 1,
CUDA_SAFE_CALL(cuCtxSynchronize()); // Retrieve and print output. 1,
1, // block dim
0,
NULL, // shared mem and stream
argsList,
0)); // arguments
CUDA_SAFE_CALL(cuCtxSynchronize()); // Retrieve and print output.
} }
void emit_broadcast(codegen::CodeWriter& writer, void emit_broadcast(codegen::CodeWriter& writer,
const std::string& element_type, const std::string& element_type,
const std::string& arg0, // replacement context const std::string& arg0, // replacement context
const std::string& out, const std::string& out,
const Shape& arg0_shape, const Shape& arg0_shape,
const Shape& out_shape, const Shape& out_shape,
const AxisSet& broadcast_axes) const AxisSet& broadcast_axes)
{ {
} }
...@@ -83,61 +87,59 @@ namespace ngraph ...@@ -83,61 +87,59 @@ namespace ngraph
// For the reference kernel this is gpud on, see ngraph/runtime/kernel/concat.hpp. // For the reference kernel this is gpud on, see ngraph/runtime/kernel/concat.hpp.
// //
void emit_concat(codegen::CodeWriter& writer, void emit_concat(codegen::CodeWriter& writer,
const std::string& element_type, const std::string& element_type,
const std::vector<std::string>& args, const std::vector<std::string>& args,
const std::string& out, const std::string& out,
const std::vector<Shape>& in_shapes, const std::vector<Shape>& in_shapes,
const Shape& out_shape, const Shape& out_shape,
size_t concatenation_axis) size_t concatenation_axis)
{ {
} }
void emit_replace_slice( void emit_replace_slice(codegen::CodeWriter& writer,
codegen::CodeWriter& writer, const std::string& element_type,
const std::string& element_type, const std::string& arg0, // replacement context
const std::string& arg0, // replacement context const std::string& arg1, // replacement value
const std::string& arg1, // replacement value const std::string& out,
const std::string& out, const Shape& arg1_shape,
const Shape& arg1_shape, const Shape& out_shape,
const Shape& out_shape, const Coordinate& lower_bounds,
const Coordinate& lower_bounds, const Coordinate& upper_bounds,
const Coordinate& upper_bounds, const Strides& strides)
const Strides& strides)
{ {
} }
void emit_slice(codegen::CodeWriter& writer, void emit_slice(codegen::CodeWriter& writer,
const std::string& element_type, const std::string& element_type,
const std::string& arg0, // replacement context const std::string& arg0, // replacement context
const std::string& out, const std::string& out,
const Shape& arg0_shape, const Shape& arg0_shape,
const Shape& out_shape, const Shape& out_shape,
const Coordinate& lower_bounds, const Coordinate& lower_bounds,
const Coordinate& upper_bounds, const Coordinate& upper_bounds,
const Strides& strides) const Strides& strides)
{ {
} }
void emit_reshape(codegen::CodeWriter& writer, void emit_reshape(codegen::CodeWriter& writer,
const std::string& element_type, const std::string& element_type,
const std::string& arg0, // replacement context const std::string& arg0, // replacement context
const std::string& out, const std::string& out,
const Shape& arg0_shape, const Shape& arg0_shape,
const Shape& out_shape, const Shape& out_shape,
const AxisVector& arg0_axis_order) const AxisVector& arg0_axis_order)
{ {
} }
void emit_sum(codegen::CodeWriter& writer, void emit_sum(codegen::CodeWriter& writer,
const std::string& element_type, const std::string& element_type,
const std::string& arg0, // replacement context const std::string& arg0, // replacement context
const std::string& out, const std::string& out,
const Shape& arg0_shape, const Shape& arg0_shape,
const Shape& out_shape, const Shape& out_shape,
const AxisSet& reduction_axes) const AxisSet& reduction_axes)
{ {
} }
} }
} }
} }
......
...@@ -37,12 +37,12 @@ namespace ngraph ...@@ -37,12 +37,12 @@ namespace ngraph
const Shape& out_shape, const Shape& out_shape,
const AxisSet& broadcast_axes); const AxisSet& broadcast_axes);
void emit_concat(codegen::CodeWriter& writer, void emit_concat(codegen::CodeWriter& writer,
const std::string& element_type, const std::string& element_type,
const std::vector<std::string>& args, const std::vector<std::string>& args,
const std::string& out, const std::string& out,
const std::vector<Shape>& in_shapes, const std::vector<Shape>& in_shapes,
const Shape& out_shape, const Shape& out_shape,
const size_t concatenation_axis); const size_t concatenation_axis);
void emit_replace_slice(codegen::CodeWriter& writer, void emit_replace_slice(codegen::CodeWriter& writer,
const std::string& element_type, const std::string& element_type,
...@@ -64,19 +64,19 @@ namespace ngraph ...@@ -64,19 +64,19 @@ namespace ngraph
const Coordinate& upper_bounds, const Coordinate& upper_bounds,
const Strides& strides); const Strides& strides);
void emit_reshape(codegen::CodeWriter& writer, void emit_reshape(codegen::CodeWriter& writer,
const std::string& element_type, const std::string& element_type,
const std::string& arg0, // replacement context const std::string& arg0, // replacement context
const std::string& out, const std::string& out,
const Shape& arg0_shape, const Shape& arg0_shape,
const Shape& out_shape, const Shape& out_shape,
const AxisVector& arg0_axis_order); const AxisVector& arg0_axis_order);
void emit_sum(codegen::CodeWriter& writer, void emit_sum(codegen::CodeWriter& writer,
const std::string& element_type, const std::string& element_type,
const std::string& arg0, // replacement context const std::string& arg0, // replacement context
const std::string& out, const std::string& out,
const Shape& arg0_shape, const Shape& arg0_shape,
const Shape& out_shape, const Shape& out_shape,
const AxisSet& reduction_axes); const AxisSet& reduction_axes);
} }
} }
} }
......
This diff is collapsed.
...@@ -94,10 +94,10 @@ ...@@ -94,10 +94,10 @@
#include "ngraph/pass/memory_layout.hpp" #include "ngraph/pass/memory_layout.hpp"
#include "ngraph/runtime/gpu/gpu_backend.hpp" #include "ngraph/runtime/gpu/gpu_backend.hpp"
#include "ngraph/runtime/gpu/gpu_call_frame.hpp" #include "ngraph/runtime/gpu/gpu_call_frame.hpp"
#include "ngraph/runtime/gpu/gpu_cuda_kernel_emitters.hpp"
#include "ngraph/runtime/gpu/gpu_emitter.hpp" #include "ngraph/runtime/gpu/gpu_emitter.hpp"
#include "ngraph/runtime/gpu/gpu_external_function.hpp" #include "ngraph/runtime/gpu/gpu_external_function.hpp"
#include "ngraph/runtime/gpu/gpu_kernel_emitters.hpp" #include "ngraph/runtime/gpu/gpu_kernel_emitters.hpp"
#include "ngraph/runtime/gpu/gpu_cuda_kernel_emitters.hpp"
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
...@@ -249,17 +249,17 @@ void runtime::gpu::GPU_ExternalFunction::compile() ...@@ -249,17 +249,17 @@ void runtime::gpu::GPU_ExternalFunction::compile()
#include "ngraph/pass/manager.hpp" #include "ngraph/pass/manager.hpp"
#include "ngraph/pass/memory_layout.hpp" #include "ngraph/pass/memory_layout.hpp"
#include "ngraph/runtime/aligned_buffer.hpp" #include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/runtime/gpu/gpu_cuda_kernel_emitters.hpp"
#include "ngraph/runtime/gpu/gpu_util.hpp" #include "ngraph/runtime/gpu/gpu_util.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
#include "ngraph/runtime/gpu/gpu_cuda_kernel_emitters.hpp"
)"; )";
string pch_header_source = writer.get_code(); string pch_header_source = writer.get_code();
// writer += R"( // writer += R"(
// using namespace ngraph; // using namespace ngraph;
// using namespace std; // using namespace std;
//)"; //)";
if (m_emit_timing) if (m_emit_timing)
{ {
......
...@@ -16,27 +16,28 @@ ...@@ -16,27 +16,28 @@
#pragma once #pragma once
#define NVRTC_SAFE_CALL(x) \ #define NVRTC_SAFE_CALL(x) \
do { \ do \
nvrtcResult result = x; \ { \
if (result != NVRTC_SUCCESS) { \ nvrtcResult result = x; \
std::cerr << "\nerror: " #x " failed with error " \ if (result != NVRTC_SUCCESS) \
<< nvrtcGetErrorString(result) << '\n'; \ { \
exit(1); \ throw std::runtime_error("\nerror: " #x " failed with error " + \
} \ std::string(nvrtcGetErrorString(result))); \
} while(0) } \
} while (0)
#define CUDA_SAFE_CALL(x) \ #define CUDA_SAFE_CALL(x) \
do { \ do \
CUresult result = x; \ { \
if (result != CUDA_SUCCESS) { \ CUresult result = x; \
const char *msg; \ if (result != CUDA_SUCCESS) \
cuGetErrorName(result, &msg); \ { \
std::cerr << "\nerror: " #x " failed with error " \ const char* msg; \
<< msg << '\n'; \ cuGetErrorName(result, &msg); \
exit(1); \ throw std::runtime_error("\nerror: " #x " failed with error " + std::string(msg)); \
} \ } \
} while(0) } while (0)
namespace ngraph namespace ngraph
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment