Skip to content

Commit 1f879f6

Browse files
committed
add compile guard
1 parent 07c7572 commit 1f879f6

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

paddle/fluid/pybind/imperative.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,12 +1207,14 @@ void BindImperative(py::module *m_ptr) {
12071207
auto p = obj.cast<platform::CUDAPlace *>();
12081208
self.SetExpectedPlace(*p);
12091209

1210-
// NOTE(zhiqiu): When switching cuda place, we need to set the
1211-
// cuda device id.
1212-
// Otherwise, some cuda API may be launched at other cuda place,
1213-
// which may cost hundreds of MB of GPU memory due to the cuda
1214-
// lib.
1210+
// NOTE(zhiqiu): When switching cuda place, we need to set the
1211+
// cuda device id.
1212+
// Otherwise, some cuda API may be launched at other cuda place,
1213+
// which may cost hundreds of MB of GPU memory due to the cuda
1214+
// lib.
1215+
#ifdef PADDLE_WITH_CUDA
12151216
platform::SetDeviceId(p->device);
1217+
#endif
12161218
VLOG(4) << "Tracer(" << &self << ")"
12171219
<< " set expected place " << *p;
12181220
} else if (py::isinstance<platform::XPUPlace>(obj)) {
@@ -1234,9 +1236,11 @@ void BindImperative(py::module *m_ptr) {
12341236
auto p = obj.cast<platform::Place *>();
12351237
self.SetExpectedPlace(*p);
12361238
if (platform::is_gpu_place(*p)) {
1237-
// NOTE(zhiqu): same as obj is CUDAPlace.
1239+
// NOTE(zhiqu): same as obj is CUDAPlace.
1240+
#ifdef PADDLE_WITH_CUDA
12381241
platform::SetDeviceId(
12391242
BOOST_GET_CONST(platform::CUDAPlace, *p).device);
1243+
#endif
12401244
}
12411245
VLOG(4) << "Tracer(" << &self << ")"
12421246
<< " set expected place " << *p;

0 commit comments

Comments
 (0)