|
14 | 14 | ProgramOptions, |
15 | 15 | launch, |
16 | 16 | ) |
17 | | -from cuda.core.experimental._dlpack import DLDeviceType |
18 | 17 |
|
19 | 18 | # Kernel for memory operations |
20 | 19 | code = """ |
|
36 | 35 | dev = Device() |
37 | 36 | dev.set_current() |
38 | 37 | stream = dev.create_stream() |
| 38 | +# tell CuPy to use our stream as the current stream: |
| 39 | +cp.cuda.ExternalStream(int(stream.handle)).use() |
39 | 40 |
|
40 | 41 | # Compile kernel |
41 | 42 | arch = "".join(f"{i}" for i in dev.compute_capability) |
|
106 | 107 | # Verify the copy operation |
107 | 108 | assert cp.allclose(new_device_array, pinned_array), "Pinned to device copy failed" |
108 | 109 |
|
109 | | -# Demonstrate DLPack integration |
110 | | -print("\nDLPack device information:") |
111 | | -print(f"Device buffer DLPack device: {device_buffer.__dlpack_device__()}") |
112 | | -print(f"Pinned buffer DLPack device: {pinned_buffer.__dlpack_device__()}") |
113 | | - |
114 | | -# Assert DLPack device types |
115 | | -device_dlpack = device_buffer.__dlpack_device__() |
116 | | -pinned_dlpack = pinned_buffer.__dlpack_device__() |
117 | | - |
118 | | -assert device_dlpack[0] == DLDeviceType.kDLCUDA, "Device buffer should have CUDA device type" |
119 | | -assert pinned_dlpack[0] == DLDeviceType.kDLCUDAHost, "Pinned buffer should have CUDA host device type" |
120 | | - |
121 | 110 | # Clean up |
122 | 111 | device_buffer.close(stream) |
123 | 112 | pinned_buffer.close(stream) |
124 | 113 | new_device_buffer.close(stream) |
125 | 114 | stream.close() |
| 115 | +cp.cuda.Stream.null.use() # reset CuPy's current stream to the null stream |
126 | 116 |
|
127 | 117 | # Verify buffers are properly closed |
128 | 118 | assert device_buffer.handle == 0, "Device buffer should be closed" |
|
0 commit comments