Skip to content

Commit 08da4c9

Browse files
apakbinjeffdaily
authored andcommitted
[rocm6.5_internal_testing] MIOpen: Get current device from Torch rather than HIP in handle creation (pytorch#154549) (#2223)
(This is a cherry-pick of pytorch#154549) Get current device from Torch rather than HIP in MIOpen handle creation. The device may have already been set from torch side, otherwise device is set to 0 for handle. Additional audits of cudnn vs miopen Handle.cpp file. Pull Request resolved: pytorch#154549 Approved by: https://github.com/jeffdaily, https://github.com/cyyever Co-authored-by: Jeff Daily <[email protected]>
1 parent 9e184c1 commit 08da4c9

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

aten/src/ATen/miopen/Handle.cpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
1-
#include <ATen/miopen/Exceptions.h>
2-
#include <ATen/miopen/Handle.h>
31
#include <ATen/hip/detail/DeviceThreadHandles.h>
2+
#include <ATen/miopen/Handle.h>
43
#include <c10/hip/HIPStream.h>
54

6-
namespace at { namespace native {
5+
#include <ATen/hip/Exceptions.h>
6+
#include <ATen/miopen/Exceptions.h>
7+
8+
namespace at::native {
79
namespace {
810

911
void createMIOpenHandle(miopenHandle_t *handle) {
1012
MIOPEN_CHECK(miopenCreate(handle));
1113
}
1214

1315
void destroyMIOpenHandle(miopenHandle_t handle) {
14-
// this is because of something dumb in the ordering of
15-
// destruction. Sometimes atexit, the cuda context (or something)
16-
// would already be destroyed by the time this gets destroyed. It
17-
// happens in fbcode setting. @colesbury and I decided to not destroy
18-
// the handle as a workaround.
19-
// - @soumith
20-
//
21-
// Further note: this is now disabled globally, because we are seeing
22-
// the same issue as mentioned above in CUDA 11 CI.
23-
// - @zasdfgbnm
24-
//
25-
// #ifdef NO_MIOPEN_DESTROY_HANDLE
26-
// #else
27-
// miopenDestroy(handle);
28-
// #endif
16+
// this is because of something dumb in the ordering of
17+
// destruction. Sometimes atexit, the cuda context (or something)
18+
// would already be destroyed by the time this gets destroyed. It
19+
// happens in fbcode setting. @colesbury and I decided to not destroy
20+
// the handle as a workaround.
21+
// - @soumith
22+
//
23+
// Further note: this is now disabled globally, because we are seeing
24+
// the same issue as mentioned above in CUDA 11 CI.
25+
// - @zasdfgbnm
26+
//
27+
// #ifdef NO_MIOPEN_DESTROY_HANDLE
28+
// #else
29+
// miopenDestroy(handle);
30+
// #endif
2931
}
3032

31-
using MIOpenPoolType = at::cuda::DeviceThreadHandlePool<miopenHandle_t, createMIOpenHandle, destroyMIOpenHandle>;
33+
using MIOpenPoolType = at::cuda::DeviceThreadHandlePool<
34+
miopenHandle_t,
35+
createMIOpenHandle,
36+
destroyMIOpenHandle>;
3237

3338
} // namespace
3439

3540
miopenHandle_t getMiopenHandle() {
36-
int device;
37-
HIP_CHECK(hipGetDevice(&device));
41+
c10::DeviceIndex device = 0;
42+
AT_CUDA_CHECK(c10::hip::GetDevice(&device));
3843

3944
// Thread local PoolWindows are lazily-initialized
4045
// to avoid initialization issues that caused hangs on Windows.
@@ -46,8 +51,8 @@ miopenHandle_t getMiopenHandle() {
4651
pool->newPoolWindow());
4752

4853
auto handle = myPoolWindow->reserve(device);
49-
MIOPEN_CHECK(miopenSetStream(handle, at::hip::getCurrentHIPStream()));
54+
MIOPEN_CHECK(miopenSetStream(handle, c10::hip::getCurrentHIPStream()));
5055
return handle;
5156
}
5257

53-
}} // namespace at::native
58+
} // namespace at::native

0 commit comments

Comments
 (0)