MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / HandleImpl

Method HandleImpl

dnn/src/rocm/handle.cpp:69–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67namespace rocm {
68
69HandleImpl::HandleImpl(megcoreComputingHandle_t comp_handle)
70 : HandleImplHelper(comp_handle, HandleType::ROCM) {
71 // Get megcore device handle
72 megcoreDeviceHandle_t dev_handle;
73 megcoreGetDeviceHandle(comp_handle, &dev_handle);
74 int dev_id;
75 megcoreGetDeviceID(dev_handle, &dev_id);
76 if (dev_id < 0) {
77 hip_check(hipGetDevice(&dev_id));
78 }
79 m_device_id = dev_id;
80 hip_check(hipGetDeviceProperties(&m_device_prop, dev_id));
81 // Get stream from MegCore computing handle.
82 //! no version check
83 megcore::getROCMContext(comp_handle, &m_megcore_context);
84 rocblas_check(rocblas_create_handle(&m_rocblas_handle));
85 //! must call miopenCreateWithStream() to create miopen handle, then the
86 //! rocblas_handle of miopen will set to be the same stream , otherwise
87 //! miopen create rocblas_handle with default stream
88 miopen_check(miopenCreateWithStream(&m_miopen_handle, stream()));
89
90 // Set stream for miopen and rocblas handles.
91 rocblas_check(rocblas_set_stream(m_rocblas_handle, stream()));
92
93 // Note that all rocblas scalars (alpha, beta) and scalar results such as
94 // dot output resides at device side.
95 rocblas_check(
96 rocblas_set_pointer_mode(m_rocblas_handle, rocblas_pointer_mode_device));
97
98 // init const scalars
99 hip_check(hipMalloc(&m_const_scalars, sizeof(ConstScalars)));
100 ConstScalars const_scalars_val;
101 const_scalars_val.init();
102 hip_check(hipMemcpyAsync(
103 m_const_scalars, &const_scalars_val, sizeof(ConstScalars),
104 hipMemcpyHostToDevice, stream()));
105 hip_check(hipStreamSynchronize(stream()));
106}
107
108HandleImpl::~HandleImpl() noexcept {
109 miopen_check(miopenDestroy(m_miopen_handle));

Callers

nothing calls this directly

Calls 4

megcoreGetDeviceHandleFunction · 0.85
megcoreGetDeviceIDFunction · 0.85
streamFunction · 0.85
initMethod · 0.45

Tested by

no test coverage detected