@@ -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(" " )" 
12171219                      << "  set expected place " 
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(" " )" 
12421246                      << "  set expected place " 
0 commit comments