|
1 | | -## Simple introduction example to CuPY for AMD GPUs |
| 1 | +## CuPY Examples |
| 2 | + |
| 3 | +### Simple introduction example to CuPY for AMD GPUs |
2 | 4 |
|
3 | 5 | To run this example, |
4 | 6 |
|
5 | 7 | ``` |
6 | 8 | module load cupy |
7 | 9 | python intro.py |
8 | 10 | ``` |
| 11 | + |
| 12 | +The output should look like the following: |
| 13 | + |
| 14 | +``` |
| 15 | +CuPy Array: [1 2 3 4 5] |
| 16 | +Squared CuPy Array: [ 1 4 9 16 25] |
| 17 | +NumPy Array: [5 6 7 8 9] |
| 18 | +CuPy Array from NumPy: [5 6 7 8 9] |
| 19 | +Addition Result on GPU: [ 6 8 10 12 14] |
| 20 | +Result on CPU: [ 6 8 10 12 14] |
| 21 | +``` |
| 22 | + |
| 23 | +What is actually happening here? What is on the GPU and what is on the CPU? |
| 24 | +Let's try and see more. |
| 25 | + |
| 26 | +``` |
| 27 | +export AMD_LOG_LEVEL=1 |
| 28 | +python intro.py |
| 29 | +``` |
| 30 | + |
| 31 | +Now our output is: |
| 32 | + |
| 33 | +``` |
| 34 | +:1:hip_memory.cpp :3721: 1083559518128d us: Cannot get amd_mem_obj for ptr: 0x46b8a5f0 |
| 35 | +CuPy Array: [1 2 3 4 5] |
| 36 | +Squared CuPy Array: [ 1 4 9 16 25] |
| 37 | +NumPy Array: [5 6 7 8 9] |
| 38 | +:1:hip_memory.cpp :3721: 1083560370823d us: Cannot get amd_mem_obj for ptr: 0x483ba890 |
| 39 | +CuPy Array from NumPy: [5 6 7 8 9] |
| 40 | +Addition Result on GPU: [ 6 8 10 12 14] |
| 41 | +Result on CPU: [ 6 8 10 12 14] |
| 42 | +``` |
| 43 | + |
| 44 | +The warning is from the AMD logging functions and doesn't impact the run. Now let's increase the log level for the run. |
| 45 | + |
| 46 | +``` |
| 47 | +export AMD_LOG_LEVEL=3 |
| 48 | +python intro.py |
| 49 | +``` |
| 50 | + |
| 51 | +Now we see lots of output that shows the hip calls and the operations on the GPU. |
| 52 | + |
| 53 | +``` |
| 54 | +.... |
| 55 | +hipMemcpyAsync ( 0x559ea98f65f0, 0x7f4556800000, 40, hipMemcpyDeviceToHost, stream:<null> ) |
| 56 | +Signal = (0x7f4d5efff280), Translated start/end = 1083534945452078 / 1083534945453358, Elapsed = 1280 ns, ticks start/end = 27091222405615 / 27091222405647, Ticks elapsed = 32 |
| 57 | +Host active wait for Signal = (0x7f4d5efff200) for -1 ns |
| 58 | +Set Handler: handle(0x7f4d5efff180), timestamp(0x559eaabead90) |
| 59 | +Host active wait for Signal = (0x7f4d5efff180) for -1 ns |
| 60 | +hipMemcpyAsync: Returned hipSuccess : : duration: 5948d us |
| 61 | +hipStreamSynchronize ( stream:<null> ) |
| 62 | +Handler: value(0), timestamp(0x559eaa7e7350), handle(0x7f4d5efff180) |
| 63 | +hipStreamSynchronize: Returned hipSuccess : |
| 64 | +hipSetDevice ( 0 ) |
| 65 | +hipSetDevice: Returned hipSuccess : |
| 66 | +CuPy Array: [1 2 3 4 5] |
| 67 | +.... |
| 68 | +``` |