SWDEV-298338 - Fix memory test failure on NV MGPUs (#2339)

1. Fix hipMallocManagedMultiChunkMultiDevice
Add device setting before kernel launching
Add stream sync

2. Fix hipMemcpyAtoH and hipMemcpyHtoA
Fix primary context initialization issue when device
is changed on cuda

Change-Id: I3fe6dbc35b7b24abb21ada297b7885df83d28152

[ROCm/hip commit: ae73179d40]
This commit is contained in:
TomSang
2021-09-14 04:07:46 -04:00
gecommit door GitHub
bovenliggende 588a6c250e
commit 40812160de
3 gewijzigde bestanden met toevoegingen van 31 en 1 verwijderingen
@@ -75,11 +75,17 @@ bool MultiChunkMultiDevice(int NumDevices) {
const unsigned threadsPerBlock = 256;
const unsigned blocks = (NUM_ELMS + 255)/256;
for (int Klaunch = 0; Klaunch < NumDevices; ++Klaunch) {
// If without setting device, Hmm value will be read as 0 in kernel on
// GPU where Hmm isn't allocated by hipMallocManaged(). This looks like
// a bug of cuda. The following line is to fix the bug on cuda only.
HIPCHECK(hipSetDevice(Klaunch));
vector_sum<float> <<<blocks, threadsPerBlock, 0, stream[Klaunch]>>>
(&Hmm[Klaunch * NUM_ELMS], Ad[Klaunch], NUM_ELMS);
}
HIPCHECK(hipDeviceSynchronize());
for (int m = 0; m < NumDevices; ++m) {
HIPCHECK(hipStreamSynchronize(stream[m]));
HIPCHECK(hipMemcpy(Ah, Ad[m], NUM_ELMS * sizeof(float),
hipMemcpyDeviceToHost));
for (int n = 0; n < NUM_ELMS; ++n) {