MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / SynchronousMemcpyD2D

Method SynchronousMemcpyD2D

tensorflow/stream_executor/cuda/cuda_driver.cc:1043–1091  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

1041}
1042
1043/* static */ port::Status GpuDriver::SynchronousMemcpyD2D(GpuContext* context,
1044 CUdeviceptr gpu_dst,
1045 CUdeviceptr gpu_src,
1046 uint64 size) {
1047 ScopedActivateContext activation(context);
1048 if (size > 0) {
1049 CheckPointerIsValid(gpu_src, "src");
1050 CheckPointerIsValid(gpu_dst, "dst");
1051 }
1052
1053 CUresult result;
1054 // CreatedContexts::GetAnyContext() doesn't works when ptr == 0.
1055 // This happens when the size is 0.
1056 if(gpu_dst == 0 || gpu_src == 0 || !UseCudaMallocAsyncAllocator()){
1057 result = cuMemcpyDtoD(gpu_dst, gpu_src, size);
1058 } else {
1059 // Any context work here.
1060 CUcontext dstContext = CreatedContexts::GetAnyContext(
1061 absl::bit_cast<void*>(gpu_dst));
1062 CUcontext srcContext = CreatedContexts::GetAnyContext(
1063 absl::bit_cast<void*>(gpu_src));
1064
1065 if ((void*)dstContext == nullptr) {
1066 port::StatusOr<GpuContext*> context = GetPointerContext(gpu_dst);
1067 if (context.ok()) {
1068 dstContext = context.ValueOrDie()->context();
1069 }
1070 }
1071
1072 if ((void*)srcContext == nullptr) {
1073 port::StatusOr<GpuContext*> context = GetPointerContext(gpu_src);
1074 if (context.ok()) {
1075 srcContext = context.ValueOrDie()->context();
1076 }
1077 }
1078
1079 result = cuMemcpyPeer(gpu_dst, dstContext, gpu_src, srcContext, size);
1080 }
1081
1082 RETURN_IF_CUDA_RES_ERROR(
1083 result,
1084 absl::StrFormat(
1085 "failed to synchronous memcpy from host to device: GPU dst: %p; "
1086 "GPU src: %p; size: %u=0x%x",
1087 absl::bit_cast<void*>(gpu_dst), absl::bit_cast<void*>(gpu_src), size,
1088 size));
1089 VLOG(2) << "successfully sync memcpy'd d2d of " << size << " bytes";
1090 return port::Status::OK();
1091}
1092
1093/* static */ bool GpuDriver::AsynchronousMemcpyD2H(GpuContext* context,
1094 void* host_dst,

Callers

nothing calls this directly

Calls 4

CheckPointerIsValidFunction · 0.85
okMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected