Skip to content

Commit a0176a3

Browse files
committed
Correct P2P memory access section
Signed-off-by: Jan Stephan <[email protected]>
1 parent 4c765b2 commit a0176a3

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

docs/how-to/hip_runtime_api/multi_device.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ applications that require frequent data exchange between GPUs, as it eliminates
7373
the need to transfer data through the host memory.
7474

7575
By adding peer-to-peer access to the example referenced in
76-
:ref:`multi_device_selection`, data can be copied between devices:
76+
:ref:`multi_device_selection`, data can be efficiently copied between devices.
77+
If peer-to-peer access is not activated, the call to :cpp:func:`hipMemcpy`
78+
still works but internally uses a staging buffer in host memory, which incurs a
79+
performance penalty.
7780

7881
.. tab-set::
7982

@@ -82,13 +85,13 @@ By adding peer-to-peer access to the example referenced in
8285
.. literalinclude:: ../../tools/example_codes/p2p_memory_access.hip
8386
:start-after: // [sphinx-start]
8487
:end-before: // [sphinx-end]
85-
:emphasize-lines: 31-37, 51-55
88+
:emphasize-lines: 43-49, 63-67
8689
:language: cpp
8790

8891
.. tab-item:: without peer-to-peer
8992

90-
.. literalinclude:: ../../tools/example_codes/p2p_memory_access.hip
93+
.. literalinclude:: ../../tools/example_codes/p2p_memory_access_host_staging.hip
9194
:start-after: // [sphinx-start]
9295
:end-before: // [sphinx-end]
93-
:emphasize-lines: 43-49, 53, 58
96+
:emphasize-lines: 55-57
9497
:language: cpp

docs/tools/example_codes/p2p_memory_access_failed.hip renamed to docs/tools/example_codes/p2p_memory_access_host_staging.hip

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int main()
5353
if(deviceCount < 2)
5454
{
5555
std::cout << "This example requires at least two HIP devices." << std::endl;
56-
return EXIT_FAILURE;
56+
return EXIT_SUCCESS;
5757
}
5858

5959
double* deviceData0;
@@ -75,13 +75,9 @@ int main()
7575
simpleKernel<<<1000, 128>>>(deviceData1); // Launch kernel on device 1
7676
HIP_CHECK(hipDeviceSynchronize());
7777

78-
// Attempt to use deviceData0 on device 1 (This will not work as deviceData0 is allocated on device 0)
78+
// Use deviceData0 on device 1. This works but incurs a performance penalty.
7979
HIP_CHECK(hipSetDevice(deviceId1));
80-
hipError_t err = hipMemcpy(deviceData1, deviceData0, size, hipMemcpyDeviceToDevice); // This should fail
81-
if (err != hipSuccess)
82-
{
83-
std::cout << "Error: Cannot access deviceData0 from device 1, deviceData0 is on device 0" << std::endl;
84-
}
80+
HIP_CHECK(hipMemcpy(deviceData1, deviceData0, size, hipMemcpyDeviceToDevice));
8581

8682
// Copy result from device 0
8783
double hostData0[1024];

docs/tools/update_example_codes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@
264264
"docs/tools/example_codes/p2p_memory_access.hip"
265265
)
266266
urllib.request.urlretrieve(
267-
"https://raw.githubusercontent.com/ROCm/rocm-examples/amd-staging/HIP-Doc/Programming-Guide/Using-HIP-Runtime-API/Multi-Device-Management/p2p_memory_access_failed/main.hip",
268-
"docs/tools/example_codes/p2p_memory_access_failed.hip"
267+
"https://raw.githubusercontent.com/ROCm/rocm-examples/amd-staging/HIP-Doc/Programming-Guide/Using-HIP-Runtime-API/Multi-Device-Management/p2p_memory_access_host_staging/main.hip",
268+
"docs/tools/example_codes/p2p_memory_access_host_staging.hip"
269269
)
270270

271271
# Reference examples from HIP-Doc / Reference

0 commit comments

Comments
 (0)