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

Function run

python/1_GettingStarted/kernelNsysProfile/kernelNsysProfile.py:132–305  ·  view source on GitHub ↗

Main execution function

(size)

Source from the content-addressed store, hash-verified

130
131
132def run(size):
133 """Main execution function"""
134
135 # =================================================================
136 # Device Initialization using cuda.core
137 # =================================================================
138 with nvtx.annotate("Device Initialization", color="green"):
139 try:
140 # Create device object (defaults to device 0)
141 dev = Device()
142 dev.set_current()
143
144 print()
145 print(f"Device: {dev.name}")
146 print(f"Compute Capability: sm_{dev.arch}")
147 print()
148
149 # Synchronize device
150 dev.sync()
151
152 except Exception as e:
153 print("ERROR: CUDA initialization failed!")
154 print(f"Error: {e}")
155 sys.exit(1)
156
157 print("Profiling cuda.core Custom Kernels")
158 print(f"Array size: {size:,}\n")
159
160 # Constant for SAXPY operation
161 alpha = 2.5
162
163 # Initialize random seed
164 rng = cp.random.default_rng(42)
165
166 # =================================================================
167 # Phase 1: Create GPU Arrays with CuPy
168 # =================================================================
169 with nvtx.annotate("Create GPU Arrays", color="yellow"):
170 a_gpu = rng.standard_normal(size, dtype=cp.float32)
171 b_gpu = rng.standard_normal(size, dtype=cp.float32)
172 dev.sync()
173
174 print("Phase 1: Created arrays on GPU with CuPy")
175 print(f" Array shape: {a_gpu.shape}")
176 print(f" Array dtype: {a_gpu.dtype}")
177 print(
178 f" Array a - Mean: {float(cp.mean(a_gpu)):.4f}, "
179 f"Std: {float(cp.std(a_gpu)):.4f}"
180 )
181 print(
182 f" Array b - Mean: {float(cp.mean(b_gpu)):.4f}, "
183 f"Std: {float(cp.std(b_gpu)):.4f}\n"
184 )
185
186 # =================================================================
187 # Phase 2: cuda.core Custom Kernels on GPU
188 # =================================================================
189 with nvtx.annotate("cuda.core Custom Kernels", color="purple"):

Callers 1

mainFunction · 0.70

Calls 3

verify_array_resultFunction · 0.90
get_cuda_core_kernelsFunction · 0.85
copyMethod · 0.80

Tested by

no test coverage detected