Skip to content

Commit e7706fa

Browse files
committed
[CI] Gate c10::DeviceGuard by torch version
1 parent 29c652e commit e7706fa

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

csrc/fast_hadamard_transform.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ fast_hadamard_transform(at::Tensor &x, float scale) {
105105

106106
// Otherwise the kernel will be launched from cuda:0 device
107107
// Cast to char to avoid compiler warning about narrowing
108-
at::cuda::CUDAGuard device_guard{(char)x.get_device()};
108+
#if TORCH_VERSION_MAJOR > 2 || (TORCH_VERSION_MAJOR == 2 && TORCH_VERSION_MINOR >= 6)
109+
c10::DeviceGuard device_guard(x.device());
110+
#else
111+
at::cuda::CUDAGuard device_guard{x.device()};
112+
#endif
109113
auto stream = at::cuda::getCurrentCUDAStream().stream();
110114
DISPATCH_ITYPE_FLOAT_AND_HALF_AND_BF16(x.scalar_type(), "fast_hadamard_transform", [&] {
111115
fast_hadamard_transform_cuda<input_t>(params, stream);
@@ -148,7 +152,11 @@ fast_hadamard_transform_12N(at::Tensor &x, float scale) {
148152

149153
// Otherwise the kernel will be launched from cuda:0 device
150154
// Cast to char to avoid compiler warning about narrowing
151-
at::cuda::CUDAGuard device_guard{(char)x.get_device()};
155+
#if TORCH_VERSION_MAJOR > 2 || (TORCH_VERSION_MAJOR == 2 && TORCH_VERSION_MINOR >= 6)
156+
c10::DeviceGuard device_guard(x.device());
157+
#else
158+
at::cuda::CUDAGuard device_guard{x.device()};
159+
#endif
152160
auto stream = at::cuda::getCurrentCUDAStream().stream();
153161
DISPATCH_ITYPE_FLOAT_AND_HALF_AND_BF16(x.scalar_type(), "fast_hadamard_transform", [&] {
154162
fast_hadamard_transform_12N_cuda<input_t>(params, stream);
@@ -191,7 +199,11 @@ fast_hadamard_transform_20N(at::Tensor &x, float scale) {
191199

192200
// Otherwise the kernel will be launched from cuda:0 device
193201
// Cast to char to avoid compiler warning about narrowing
194-
at::cuda::CUDAGuard device_guard{(char)x.get_device()};
202+
#if TORCH_VERSION_MAJOR > 2 || (TORCH_VERSION_MAJOR == 2 && TORCH_VERSION_MINOR >= 6)
203+
c10::DeviceGuard device_guard(x.device());
204+
#else
205+
at::cuda::CUDAGuard device_guard{x.device()};
206+
#endif
195207
auto stream = at::cuda::getCurrentCUDAStream().stream();
196208
DISPATCH_ITYPE_FLOAT_AND_HALF_AND_BF16(x.scalar_type(), "fast_hadamard_transform", [&] {
197209
fast_hadamard_transform_20N_cuda<input_t>(params, stream);
@@ -234,7 +246,11 @@ fast_hadamard_transform_28N(at::Tensor &x, float scale) {
234246

235247
// Otherwise the kernel will be launched from cuda:0 device
236248
// Cast to char to avoid compiler warning about narrowing
237-
at::cuda::CUDAGuard device_guard{(char)x.get_device()};
249+
#if TORCH_VERSION_MAJOR > 2 || (TORCH_VERSION_MAJOR == 2 && TORCH_VERSION_MINOR >= 6)
250+
c10::DeviceGuard device_guard(x.device());
251+
#else
252+
at::cuda::CUDAGuard device_guard{x.device()};
253+
#endif
238254
auto stream = at::cuda::getCurrentCUDAStream().stream();
239255
DISPATCH_ITYPE_FLOAT_AND_HALF_AND_BF16(x.scalar_type(), "fast_hadamard_transform", [&] {
240256
fast_hadamard_transform_28N_cuda<input_t>(params, stream);
@@ -277,7 +293,11 @@ fast_hadamard_transform_40N(at::Tensor &x, float scale) {
277293

278294
// Otherwise the kernel will be launched from cuda:0 device
279295
// Cast to char to avoid compiler warning about narrowing
280-
at::cuda::CUDAGuard device_guard{(char)x.get_device()};
296+
#if TORCH_VERSION_MAJOR > 2 || (TORCH_VERSION_MAJOR == 2 && TORCH_VERSION_MINOR >= 6)
297+
c10::DeviceGuard device_guard(x.device());
298+
#else
299+
at::cuda::CUDAGuard device_guard{x.device()};
300+
#endif
281301
auto stream = at::cuda::getCurrentCUDAStream().stream();
282302
DISPATCH_ITYPE_FLOAT_AND_HALF_AND_BF16(x.scalar_type(), "fast_hadamard_transform", [&] {
283303
fast_hadamard_transform_40N_cuda<input_t>(params, stream);

0 commit comments

Comments
 (0)