MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / main

Function main

python/2_CoreConcepts/memoryResources/memoryResources.py:210–257  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

208
209
210def main():
211 import argparse
212
213 parser = argparse.ArgumentParser(
214 description="Demonstrate cuda.core memory resources (Buffer + MR)"
215 )
216 parser.add_argument(
217 "--elements",
218 type=int,
219 default=1 << 16,
220 help="Number of float32 elements per buffer (default: 65536)",
221 )
222 parser.add_argument("--device", type=int, default=0, help="CUDA device id")
223 args = parser.parse_args()
224
225 device = Device(args.device)
226 device.set_current()
227 print_gpu_info(device)
228
229 # PinnedMemoryResource is backed by a host memory pool, which is not
230 # available on every device.
231 if not device.properties.host_memory_pools_supported:
232 print("Host pinned memory pools are not supported on this platform.")
233 return 2
234
235 # This sample builds host NumPy views over managed memory. Devices without
236 # concurrent managed access keep managed allocations GPU-exclusive while
237 # the GPU is active, so those host views fault.
238 if not device.properties.concurrent_managed_access:
239 print("Concurrent managed memory access is not supported on this platform.")
240 return 2
241
242 stream = device.create_stream()
243
244 try:
245 program_options = ProgramOptions(std="c++17", arch=f"sm_{device.arch}")
246 program = Program(SCALE_BIAS_KERNEL, code_type="c++", options=program_options)
247 module = program.compile("cubin")
248 kernel = module.get_kernel("scale_and_bias")
249
250 demo_device_and_pinned(device, stream, kernel, args.elements)
251 demo_managed(device, stream, kernel, args.elements)
252 demo_explicit_device_pool(device, stream, kernel, args.elements)
253
254 print("\nDone")
255 return 0
256 finally:
257 stream.close()
258
259
260if __name__ == "__main__":

Callers 1

memoryResources.pyFile · 0.70

Calls 4

print_gpu_infoFunction · 0.90
demo_device_and_pinnedFunction · 0.85
demo_managedFunction · 0.85

Tested by

no test coverage detected