| #include "ATen/CUDAGenerator.h" |
| #include "ATen/CPUGenerator.h" |
| static inline void errorHandler(const char * msg, void * data) { |
| throw std::runtime_error(msg); |
| static inline void argErrorHandler(int arg, const char * msg, void * data) { |
| std::stringstream new_error; |
| new_error << "invalid argument " << arg << ": " << msg; |
| throw std::runtime_error(new_error.str()); |
| THSetDefaultErrorHandler(errorHandler,nullptr); |
| THSetDefaultArgErrorHandler(argErrorHandler,nullptr); |
| generator_registry[static_cast<int>(Backend::CPU)] |
| .reset(new CPUGenerator(this)); |
| void Context::doInitCUDA() { |
| thc_state = THCState_alloc(); |
| THCState_setDeviceAllocator(thc_state, THCCachingAllocator_get()); |
| thc_state->cudaHostAllocator = &THCCachingHostAllocator; |
| generator_registry[static_cast<int>(Backend::CUDA)] |
| .reset(new CUDAGenerator(this)); |
| THCState_free(thc_state); |
| Context & globalContext() { |
| static Context globalContext_; |
| bool Context::hasCUDA() const { |