torch/csrc/cuda/Module.cpp
// Callback for python part. Used for additional initialization of python classes
Callback for python part. Used for additional initialization of python classes
Callback for python part . Used for additional initialization of python classes
static PyObject * THCPModule_initExtension(PyObject *self)
{
  HANDLE_TH_ERRORS
  state = at::globalContext().lazyInitCUDA();
  auto m = THPObjectPtr(PyImport_ImportModule("torch.cuda"));
  if (!m) throw python_error();
  THCPDoubleStorage_postInit(m);
  THCPFloatStorage_postInit(m);
  THCPHalfStorage_postInit(m);
  THCPLongStorage_postInit(m);
  THCPIntStorage_postInit(m);
  THCPShortStorage_postInit(m);
  THCPCharStorage_postInit(m);
  THCPByteStorage_postInit(m);
#ifdef USE_MAGMA
  THCMagma_init(state);
  bool has_magma = true;
#else
  bool has_magma = false;
#endif
#ifdef CUDA_HALF_TENSOR
  bool has_half = true;
#else
  bool has_half = false;
#endif
  auto set_module_attr = [&](const char* name, PyObject* v) {
    if (PyObject_SetAttrString(m, name, v) < 0) {
      throw python_error();
    }
  };
  set_module_attr("has_magma", has_magma ? Py_True : Py_False);
  set_module_attr("has_half", has_half ? Py_True : Py_False);
  auto _state_cdata = THPObjectPtr(PyLong_FromVoidPtr(state));
  if (!_state_cdata) throw python_error();
  set_module_attr("_state_cdata", _state_cdata.get());
  bindCudaDeviceProperties(m);
  Py_RETURN_NONE;
  END_HANDLE_TH_ERRORS
}
static PyObject * THCPModule_initExtension ( PyObject * self ) { HANDLE_TH_ERRORS state = at :: globalContext ( ) . lazyInitCUDA ( ) ; auto m = THPObjectPtr ( PyImport_ImportModule ( " " ) ) ; if ( ! m ) throw python_error ( ) ; THCPDoubleStorage_postInit ( m ) ; THCPFloatStorage_postInit ( m ) ; THCPHalfStorage_postInit ( m ) ; THCPLongStorage_postInit ( m ) ; THCPIntStorage_postInit ( m ) ; THCPShortStorage_postInit ( m ) ; THCPCharStorage_postInit ( m ) ; THCPByteStorage_postInit ( m ) ; #ifdef USE_MAGMA THCMagma_init ( state ) ; bool has_magma = true ; #else bool has_magma = false ; #endif #ifdef CUDA_HALF_TENSOR bool has_half = true ; #else bool has_half = false ; #endif auto set_module_attr = [ & ] ( const char * name , PyObject * v ) { if ( PyObject_SetAttrString ( m , name , v ) < 0 ) { throw python_error ( ) ; } } ; set_module_attr ( " " , has_magma ? Py_True : Py_False ) ; set_module_attr ( " " , has_half ? Py_True : Py_False ) ; auto _state_cdata = THPObjectPtr ( PyLong_FromVoidPtr ( state ) ) ; if ( ! _state_cdata ) throw python_error ( ) ; set_module_attr ( " " , _state_cdata . get ( ) ) ; bindCudaDeviceProperties ( m ) ; Py_RETURN_NONE ; END_HANDLE_TH_ERRORS }
Callback for python part.
Callback for python part .
// Register Storage Python objects with DynamicTypes.cpp