Skip to content

Commit 0f86397

Browse files
committed
fix build
1 parent 17009d0 commit 0f86397

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

paddle/fluid/operators/detail/sendrecvop_utils.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ limitations under the License. */
1414

1515
#include "paddle/fluid/operators/detail/sendrecvop_utils.h"
1616

17+
#ifdef PADDLE_WITH_CUDA
1718
#include <nccl.h>
19+
#endif
1820
#include <sys/time.h>
1921
#include <thread> // NOLINT
2022

@@ -51,10 +53,12 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
5153
e.WriteUint64(VarMsg::kTypeFieldNumber, 0);
5254
} else if (var->IsType<framework::SelectedRows>()) {
5355
e.WriteUint64(VarMsg::kTypeFieldNumber, 1);
56+
#ifdef PADDLE_WITH_CUDA
5457
} else if (var->IsType<ncclUniqueId>()) {
5558
// NOTE: sendrecv only support RAW type for NCCL_ID
5659
VLOG(3) << "serilizing: setting var type nccl id";
5760
e.WriteUint64(VarMsg::kTypeFieldNumber, 2);
61+
#endif
5862
}
5963

6064
if (!out_name.empty()) {
@@ -141,17 +145,19 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
141145
}
142146
payload_size = tensor->numel() * framework::SizeOfType(tensor->type());
143147
e.WriteVarlengthBeginning(VarMsg::kSerializedFieldNumber, payload_size);
148+
#ifdef PADDLE_WITH_CUDA
144149
} else if (var->IsType<ncclUniqueId>()) {
145150
// ===========================NCCL ID==================================
146151
e.WriteVarlengthBeginning(VarMsg::kSerializedFieldNumber,
147152
NCCL_UNIQUE_ID_BYTES);
148153
ncclUniqueId* uid = var->GetMutable<ncclUniqueId>();
149154
e.WriteRawBytes(std::string(uid->internal, NCCL_UNIQUE_ID_BYTES));
155+
#endif
150156
} else {
151157
PADDLE_THROW("Serialize does not support type: %s",
152158
typeid(var->Type()).name());
153159
}
154-
160+
#ifdef PADDLE_WITH_CUDA
155161
if (var->IsType<ncclUniqueId>()) {
156162
// for serialize NCCL_ID
157163
::grpc::Slice slices(e.size());
@@ -160,7 +166,7 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
160166
msg->Swap(&tmp);
161167
return;
162168
}
163-
169+
#endif
164170
// steal reference of tensor data
165171
::grpc::Slice slices[4]; // metadata, tensor, rows meta, rows
166172
int num_slices = 2; // only SelectedRows have rows buffer

paddle/fluid/operators/detail/variable_response.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include <string>
1818
#include <utility>
1919
#include <vector>
20+
#ifdef PADDLE_WITH_CUDA
21+
#include <nccl.h>
22+
#endif
2023

2124
#include "paddle/fluid/operators/detail/send_recv.pb.h"
2225
#include "paddle/fluid/operators/detail/sendrecvop_utils.h"
@@ -378,19 +381,19 @@ int VariableResponse::Parse(Source* source) {
378381
}
379382

380383
if (meta_.type() == sendrecv::NCCL_ID) {
381-
VLOG(3) << "parse nccl id request";
384+
#ifdef PADDLE_WITH_CUDA
382385
auto* var = scope_->FindVar(meta_.varname());
383386
if (var != nullptr) {
384-
VLOG(3) << "parse nccl id: length " << length;
385387
ncclUniqueId* id = var->GetMutable<ncclUniqueId>();
386388
if (!ReadRaw(&input, *dev_ctx_, platform::CPUPlace(), id->internal,
387389
length)) {
388390
return tag;
389391
}
390-
// memcpy(id->internal, meta_.serialized().c_str(),
391-
// meta_.serialized().size());
392392
}
393393
break;
394+
#else
395+
PADDLE_THROW("Not compiled with CUDA!");
396+
#endif
394397
}
395398

396399
framework::DDim dims = GetDims(meta_.dims());

0 commit comments

Comments
 (0)