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

Method AsynchronousMemcpyD2D

tensorflow/stream_executor/cuda/cuda_driver.cc:1140–1197  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

1138}
1139
1140/* static */ bool GpuDriver::AsynchronousMemcpyD2D(GpuContext* context,
1141 CUdeviceptr gpu_dst,
1142 CUdeviceptr gpu_src,
1143 uint64 size,
1144 CUstream stream) {
1145 ScopedActivateContext activation(context);
1146 if (size > 0) {
1147 CheckPointerIsValid(gpu_src, "src");
1148 CheckPointerIsValid(gpu_dst, "dst");
1149 }
1150
1151 CUresult result;
1152 // CreatedContexts::GetAnyContext() doesn't works when ptr == 0.
1153 // This happens when the size is 0.
1154 if(gpu_dst == 0 || gpu_src == 0 || !UseCudaMallocAsyncAllocator()){
1155 result = cuMemcpyDtoDAsync(gpu_dst, gpu_src, size, stream);
1156 } else {
1157 // Any context work here.
1158 CUcontext dstContext = CreatedContexts::GetAnyContext(
1159 absl::bit_cast<void*>(gpu_dst));
1160 CUcontext srcContext = CreatedContexts::GetAnyContext(
1161 absl::bit_cast<void*>(gpu_src));
1162
1163 if ((void*)dstContext == nullptr) {
1164 port::StatusOr<GpuContext*> context = GetPointerContext(gpu_dst);
1165 if (context.ok()) {
1166 dstContext = context.ValueOrDie()->context();
1167 }
1168 }
1169
1170 if ((void*)srcContext == nullptr) {
1171 port::StatusOr<GpuContext*> context = GetPointerContext(gpu_src);
1172 if (context.ok()) {
1173 srcContext = context.ValueOrDie()->context();
1174 }
1175 }
1176
1177 result = cuMemcpyPeerAsync(gpu_dst, dstContext, gpu_src, srcContext, size, stream);
1178 }
1179
1180 if (result != CUDA_SUCCESS) {
1181 LOG(ERROR) << absl::StrFormat(
1182 "failed to enqueue async memcpy from device to device: %s"
1183 "; GPU dst: %p on %s %s"
1184 "; GPU src: %p on %s %s"
1185 "; can access? %s; size: %u=0x%x",
1186 ToString(result), absl::bit_cast<void*>(gpu_dst),
1187 CUDAPointerToMemorySpaceString(gpu_dst),
1188 CUDAPointerToDeviceString(gpu_dst), absl::bit_cast<void*>(gpu_src),
1189 CUDAPointerToMemorySpaceString(gpu_src),
1190 CUDAPointerToDeviceString(gpu_src),
1191 CUDAPointersToCanAccessString(gpu_src, gpu_dst), size, size);
1192
1193 return false;
1194 }
1195 VLOG(2) << "successfully enqueued async memcpy d2d of " << size << " bytes";
1196 return true;
1197}

Callers

nothing calls this directly

Calls 8

CheckPointerIsValidFunction · 0.85
ToStringFunction · 0.70
okMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected