Main execution function
(size)
| 130 | |
| 131 | |
| 132 | def 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"): |
no test coverage detected