Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit 9b42cc5

Browse files
SWDEV-383056 - Don't sync with dst device for hipMemcpyAsync.
Change-Id: I28530e6bd870d617507592576295fc9e7eed1475
1 parent 2483f2c commit 9b42cc5

File tree

6 files changed

+16
-22
lines changed

6 files changed

+16
-22
lines changed

src/hip_code_object.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ THE SOFTWARE.
3131
#include "platform/program.hpp"
3232
#include <elf/elf.hpp>
3333

34-
hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind,
35-
hip::Stream& stream, bool isAsync = false);
3634
hipError_t ihipFree(void* ptr);
3735
// forward declaration of methods required for managed variables
3836
hipError_t ihipMallocManaged(void** ptr, size_t size, unsigned int align = 0);

src/hip_internal.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ extern hipError_t ihipGetDeviceProperties(hipDeviceProp_t* props, hipDevice_t de
565565
extern hipError_t ihipDeviceGet(hipDevice_t* device, int deviceId);
566566
extern hipError_t ihipStreamOperation(hipStream_t stream, cl_command_type cmdType, void* ptr,
567567
uint64_t value, uint64_t mask, unsigned int flags, size_t sizeBytes);
568-
568+
hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind,
569+
hip::Stream& stream, bool isHostAsync = false, bool isGPUAsync = true);
569570
constexpr bool kOptionChangeable = true;
570571
constexpr bool kNewDevProg = false;
571572

src/hip_memory.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ void ihipHtoHMemcpy(void* dst, const void* src, size_t sizeBytes, hip::Stream& s
451451
}
452452
// ================================================================================================
453453
hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind,
454-
hip::Stream& stream, bool isAsync = false) {
454+
hip::Stream& stream, bool isHostAsync, bool isGPUAsync) {
455455
hipError_t status;
456456
if (sizeBytes == 0) {
457457
// Skip if nothing needs writing.
@@ -464,7 +464,6 @@ hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKin
464464
if (src == dst && kind == hipMemcpyDefault) {
465465
return hipSuccess;
466466
}
467-
bool isP2P = false;
468467
size_t sOffset = 0;
469468
amd::Memory* srcMemory = getMemoryObject(src, sOffset);
470469
size_t dOffset = 0;
@@ -473,24 +472,20 @@ hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKin
473472
ihipHtoHMemcpy(dst, src, sizeBytes, stream);
474473
return hipSuccess;
475474
} else if ((srcMemory == nullptr) && (dstMemory != nullptr)) {
476-
isAsync = false;
475+
isHostAsync = false;
477476
} else if ((srcMemory != nullptr) && (dstMemory == nullptr)) {
478-
isAsync = false;
479-
} else if ((srcMemory->getContext().devices()[0] != dstMemory->getContext().devices()[0]) &&
480-
(srcMemory->getContext().devices().size() == 1) &&
481-
(dstMemory->getContext().devices().size() == 1)) {
482-
isAsync = true;
483-
isP2P = true;
477+
isHostAsync = false;
484478
}
479+
485480
amd::Command* command = nullptr;
486-
status = ihipMemcpyCommand(command, dst, src, sizeBytes, kind, stream, isAsync);
481+
status = ihipMemcpyCommand(command, dst, src, sizeBytes, kind, stream, isHostAsync);
487482
if (status != hipSuccess) {
488483
return status;
489484
}
490485
command->enqueue();
491-
if (!isAsync) {
486+
if (!isHostAsync) {
492487
command->awaitCompletion();
493-
} else if (isP2P) {
488+
} else if (!isGPUAsync) {
494489
hip::Stream* pStream = hip::getNullStream(dstMemory->getContext());
495490
amd::Command::EventWaitList waitList;
496491
waitList.push_back(command);

src/hip_peer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ hipError_t hipMemcpyPeer(void* dst, int dstDevice, const void* src, int srcDevic
220220
HIP_RETURN(hipErrorInvalidDevice);
221221
}
222222

223-
HIP_RETURN(hipMemcpy(dst, src, sizeBytes, hipMemcpyDeviceToDevice));
223+
HIP_RETURN(ihipMemcpy(dst, src, sizeBytes, hipMemcpyDeviceToDevice, *hip::getNullStream(),
224+
true, false));
224225
}
225226

226227
hipError_t hipMemcpyPeerAsync(void* dst, int dstDevice, const void* src, int srcDevice,
@@ -235,7 +236,11 @@ hipError_t hipMemcpyPeerAsync(void* dst, int dstDevice, const void* src, int src
235236
if (!hip::isValid(stream)) {
236237
return hipErrorContextIsDestroyed;
237238
}
238-
HIP_RETURN(hipMemcpyAsync(dst, src, sizeBytes, hipMemcpyDeviceToDevice, stream));
239+
hip::Stream* hip_stream = hip::getStream(stream);
240+
if (hip_stream == nullptr) {
241+
return hipErrorInvalidValue;
242+
}
243+
HIP_RETURN(ihipMemcpy(dst, src, sizeBytes, hipMemcpyDeviceToDevice, *hip_stream, true, true));
239244
}
240245

241246
hipError_t hipCtxEnablePeerAccess(hipCtx_t peerCtx, unsigned int flags) {

src/hip_platform.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ PlatformState* PlatformState::platform_; // Initiaized as nullptr by default
3333

3434
// forward declaration of methods required for __hipRegisrterManagedVar
3535
hipError_t ihipMallocManaged(void** ptr, size_t size, unsigned int align = 0);
36-
hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind,
37-
hip::Stream& stream, bool isAsync = false);
3836

3937
struct __CudaFatBinaryWrapper {
4038
unsigned int magic;

src/hip_texture.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
#include "hip_conversions.hpp"
2626
#include "platform/sampler.hpp"
2727

28-
hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind,
29-
hip::Stream& stream, bool isAsync = false);
30-
3128
hipError_t ihipFree(void* ptr);
3229

3330
struct __hip_texture {

0 commit comments

Comments
 (0)