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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <cuda_runtime.h>
|
| 2 |
+
|
| 3 |
+
#include <math.h>
|
| 4 |
+
#include <stdint.h>
|
| 5 |
+
#include <stdio.h>
|
| 6 |
+
#include <stdlib.h>
|
| 7 |
+
|
| 8 |
+
#define PYC_ADA_BLOCK_M 64
|
| 9 |
+
#define PYC_ADA_BLOCK_N 64
|
| 10 |
+
#define PYC_ADA_BLOCK_K 16
|
| 11 |
+
#define PYC_ADA_THREADS_X 16
|
| 12 |
+
#define PYC_ADA_THREADS_Y 16
|
| 13 |
+
#define PYC_ADA_THREAD_TILE_M 4
|
| 14 |
+
#define PYC_ADA_THREAD_TILE_N 4
|
| 15 |
+
|
| 16 |
+
typedef struct {
|
| 17 |
+
int m;
|
| 18 |
+
int n;
|
| 19 |
+
int k;
|
| 20 |
+
int warmup;
|
| 21 |
+
int iters;
|
| 22 |
+
} ada_gemm_config;
|
| 23 |
+
|
| 24 |
+
static int check_cuda(cudaError_t status, const char* what) {
|
| 25 |
+
if (status != cudaSuccess) {
|
| 26 |
+
fprintf(stderr, "%s failed: %s\n", what, cudaGetErrorString(status));
|
| 27 |
+
return -1;
|
| 28 |
+
}
|
| 29 |
+
return 0;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
static void fill_matrix(float* data, int rows, int cols, float scale) {
|
| 33 |
+
int i;
|
| 34 |
+
for (i = 0; i < rows * cols; ++i) {
|
| 35 |
+
int pattern = (i * 17 + rows * 13 + cols * 7) % 31;
|
| 36 |
+
data[i] = ((float)pattern - 15.0f) * scale;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
static void reference_gemm(
|
| 41 |
+
const float* a,
|
| 42 |
+
const float* b,
|
| 43 |
+
float* c,
|
| 44 |
+
int m,
|
| 45 |
+
int n,
|
| 46 |
+
int k) {
|
| 47 |
+
int row;
|
| 48 |
+
for (row = 0; row < m; ++row) {
|
| 49 |
+
int col;
|
| 50 |
+
for (col = 0; col < n; ++col) {
|
| 51 |
+
float acc = 0.0f;
|
| 52 |
+
int kk;
|
| 53 |
+
for (kk = 0; kk < k; ++kk) {
|
| 54 |
+
acc += a[row * k + kk] * b[kk * n + col];
|
| 55 |
+
}
|
| 56 |
+
c[row * n + col] = acc;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
__launch_bounds__(PYC_ADA_THREADS_X * PYC_ADA_THREADS_Y, 2)
|
| 62 |
+
__global__ void ada_fp32_tiled_gemm(
|
| 63 |
+
const float* __restrict__ a,
|
| 64 |
+
const float* __restrict__ b,
|
| 65 |
+
float* __restrict__ c,
|
| 66 |
+
int m,
|
| 67 |
+
int n,
|
| 68 |
+
int k) {
|
| 69 |
+
__shared__ float a_tile[PYC_ADA_BLOCK_M][PYC_ADA_BLOCK_K];
|
| 70 |
+
__shared__ float b_tile[PYC_ADA_BLOCK_K][PYC_ADA_BLOCK_N];
|
| 71 |
+
|
| 72 |
+
const int thread_row = threadIdx.y;
|
| 73 |
+
const int thread_col = threadIdx.x;
|
| 74 |
+
const int block_row = blockIdx.y * PYC_ADA_BLOCK_M;
|
| 75 |
+
const int block_col = blockIdx.x * PYC_ADA_BLOCK_N;
|
| 76 |
+
const int lane_linear = thread_row * blockDim.x + thread_col;
|
| 77 |
+
const int a_loads_per_thread = (PYC_ADA_BLOCK_M * PYC_ADA_BLOCK_K) / (PYC_ADA_THREADS_X * PYC_ADA_THREADS_Y);
|
| 78 |
+
const int b_loads_per_thread = (PYC_ADA_BLOCK_K * PYC_ADA_BLOCK_N) / (PYC_ADA_THREADS_X * PYC_ADA_THREADS_Y);
|
| 79 |
+
float accum[PYC_ADA_THREAD_TILE_M][PYC_ADA_THREAD_TILE_N];
|
| 80 |
+
int row_fragment = thread_row * PYC_ADA_THREAD_TILE_M;
|
| 81 |
+
int col_fragment = thread_col * PYC_ADA_THREAD_TILE_N;
|
| 82 |
+
int kk_base;
|
| 83 |
+
int i;
|
| 84 |
+
int j;
|
| 85 |
+
|
| 86 |
+
for (i = 0; i < PYC_ADA_THREAD_TILE_M; ++i) {
|
| 87 |
+
for (j = 0; j < PYC_ADA_THREAD_TILE_N; ++j) {
|
| 88 |
+
accum[i][j] = 0.0f;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
for (kk_base = 0; kk_base < k; kk_base += PYC_ADA_BLOCK_K) {
|
| 93 |
+
for (i = 0; i < a_loads_per_thread; ++i) {
|
| 94 |
+
int linear = lane_linear * a_loads_per_thread + i;
|
| 95 |
+
int tile_row = linear / PYC_ADA_BLOCK_K;
|
| 96 |
+
int tile_col = linear % PYC_ADA_BLOCK_K;
|
| 97 |
+
int global_row = block_row + tile_row;
|
| 98 |
+
int global_col = kk_base + tile_col;
|
| 99 |
+
float value = 0.0f;
|
| 100 |
+
if (global_row < m && global_col < k) {
|
| 101 |
+
value = a[global_row * k + global_col];
|
| 102 |
+
}
|
| 103 |
+
a_tile[tile_row][tile_col] = value;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
for (i = 0; i < b_loads_per_thread; ++i) {
|
| 107 |
+
int linear = lane_linear * b_loads_per_thread + i;
|
| 108 |
+
int tile_row = linear / PYC_ADA_BLOCK_N;
|
| 109 |
+
int tile_col = linear % PYC_ADA_BLOCK_N;
|
| 110 |
+
int global_row = kk_base + tile_row;
|
| 111 |
+
int global_col = block_col + tile_col;
|
| 112 |
+
float value = 0.0f;
|
| 113 |
+
if (global_row < k && global_col < n) {
|
| 114 |
+
value = b[global_row * n + global_col];
|
| 115 |
+
}
|
| 116 |
+
b_tile[tile_row][tile_col] = value;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
__syncthreads();
|
| 120 |
+
|
| 121 |
+
#pragma unroll
|
| 122 |
+
for (i = 0; i < PYC_ADA_BLOCK_K; ++i) {
|
| 123 |
+
float a_frag[PYC_ADA_THREAD_TILE_M];
|
| 124 |
+
float b_frag[PYC_ADA_THREAD_TILE_N];
|
| 125 |
+
|
| 126 |
+
#pragma unroll
|
| 127 |
+
for (j = 0; j < PYC_ADA_THREAD_TILE_M; ++j) {
|
| 128 |
+
a_frag[j] = a_tile[row_fragment + j][i];
|
| 129 |
+
}
|
| 130 |
+
#pragma unroll
|
| 131 |
+
for (j = 0; j < PYC_ADA_THREAD_TILE_N; ++j) {
|
| 132 |
+
b_frag[j] = b_tile[i][col_fragment + j];
|
| 133 |
+
}
|
| 134 |
+
#pragma unroll
|
| 135 |
+
for (j = 0; j < PYC_ADA_THREAD_TILE_M; ++j) {
|
| 136 |
+
int jj;
|
| 137 |
+
#pragma unroll
|
| 138 |
+
for (jj = 0; jj < PYC_ADA_THREAD_TILE_N; ++jj) {
|
| 139 |
+
accum[j][jj] += a_frag[j] * b_frag[jj];
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
__syncthreads();
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
for (i = 0; i < PYC_ADA_THREAD_TILE_M; ++i) {
|
| 148 |
+
int out_row = block_row + row_fragment + i;
|
| 149 |
+
if (out_row >= m) {
|
| 150 |
+
continue;
|
| 151 |
+
}
|
| 152 |
+
for (j = 0; j < PYC_ADA_THREAD_TILE_N; ++j) {
|
| 153 |
+
int out_col = block_col + col_fragment + j;
|
| 154 |
+
if (out_col < n) {
|
| 155 |
+
c[out_row * n + out_col] = accum[i][j];
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
static int configure_ada_kernel(void) {
|
| 162 |
+
cudaError_t status;
|
| 163 |
+
|
| 164 |
+
status = cudaFuncSetAttribute(
|
| 165 |
+
ada_fp32_tiled_gemm,
|
| 166 |
+
cudaFuncAttributePreferredSharedMemoryCarveout,
|
| 167 |
+
100);
|
| 168 |
+
if (status != cudaSuccess && status != cudaErrorNotSupported) {
|
| 169 |
+
fprintf(stderr, "cudaFuncSetAttribute failed: %s\n", cudaGetErrorString(status));
|
| 170 |
+
return -1;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
return 0;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
static int parse_int_arg(const char* text, int* out) {
|
| 177 |
+
char* end = NULL;
|
| 178 |
+
long value;
|
| 179 |
+
|
| 180 |
+
if (!text || !out) {
|
| 181 |
+
return -1;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
value = strtol(text, &end, 10);
|
| 185 |
+
if (*text == '\0' || !end || *end != '\0' || value <= 0 || value > 1 << 20) {
|
| 186 |
+
return -1;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
*out = (int)value;
|
| 190 |
+
return 0;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
static int parse_config(int argc, char** argv, ada_gemm_config* cfg) {
|
| 194 |
+
if (!cfg) {
|
| 195 |
+
return -1;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
cfg->m = 1024;
|
| 199 |
+
cfg->n = 1024;
|
| 200 |
+
cfg->k = 1024;
|
| 201 |
+
cfg->warmup = 10;
|
| 202 |
+
cfg->iters = 50;
|
| 203 |
+
|
| 204 |
+
if (argc > 1 && parse_int_arg(argv[1], &cfg->m) != 0) return -1;
|
| 205 |
+
if (argc > 2 && parse_int_arg(argv[2], &cfg->n) != 0) return -1;
|
| 206 |
+
if (argc > 3 && parse_int_arg(argv[3], &cfg->k) != 0) return -1;
|
| 207 |
+
if (argc > 4 && parse_int_arg(argv[4], &cfg->warmup) != 0) return -1;
|
| 208 |
+
if (argc > 5 && parse_int_arg(argv[5], &cfg->iters) != 0) return -1;
|
| 209 |
+
|
| 210 |
+
return 0;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
int main(int argc, char** argv) {
|
| 214 |
+
ada_gemm_config cfg;
|
| 215 |
+
cudaDeviceProp props;
|
| 216 |
+
float* host_a = NULL;
|
| 217 |
+
float* host_b = NULL;
|
| 218 |
+
float* host_c = NULL;
|
| 219 |
+
float* ref_c = NULL;
|
| 220 |
+
float* dev_a = NULL;
|
| 221 |
+
float* dev_b = NULL;
|
| 222 |
+
float* dev_c = NULL;
|
| 223 |
+
cudaEvent_t start = NULL;
|
| 224 |
+
cudaEvent_t stop = NULL;
|
| 225 |
+
size_t a_bytes;
|
| 226 |
+
size_t b_bytes;
|
| 227 |
+
size_t c_bytes;
|
| 228 |
+
dim3 block;
|
| 229 |
+
dim3 grid;
|
| 230 |
+
float elapsed_ms = 0.0f;
|
| 231 |
+
double best_ms = 0.0;
|
| 232 |
+
int iter;
|
| 233 |
+
double max_abs_diff = 0.0;
|
| 234 |
+
int device = 0;
|
| 235 |
+
|
| 236 |
+
if (parse_config(argc, argv, &cfg) != 0) {
|
| 237 |
+
fprintf(stderr, "usage: %s [m] [n] [k] [warmup] [iters]\n", argv[0]);
|
| 238 |
+
return 2;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
if (check_cuda(cudaGetDevice(&device), "cudaGetDevice") != 0) return 1;
|
| 242 |
+
if (check_cuda(cudaGetDeviceProperties(&props, device), "cudaGetDeviceProperties") != 0) return 1;
|
| 243 |
+
|
| 244 |
+
printf("device=%s cc=%d.%d\n", props.name, props.major, props.minor);
|
| 245 |
+
if (!(props.major == 8 && props.minor == 9)) {
|
| 246 |
+
printf("note=prototype tuned for Ada (sm_89); running on a different architecture\n");
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
a_bytes = (size_t)cfg.m * (size_t)cfg.k * sizeof(float);
|
| 250 |
+
b_bytes = (size_t)cfg.k * (size_t)cfg.n * sizeof(float);
|
| 251 |
+
c_bytes = (size_t)cfg.m * (size_t)cfg.n * sizeof(float);
|
| 252 |
+
|
| 253 |
+
host_a = (float*)malloc(a_bytes);
|
| 254 |
+
host_b = (float*)malloc(b_bytes);
|
| 255 |
+
host_c = (float*)malloc(c_bytes);
|
| 256 |
+
ref_c = (float*)malloc(c_bytes);
|
| 257 |
+
if (!host_a || !host_b || !host_c || !ref_c) {
|
| 258 |
+
fprintf(stderr, "host allocation failed\n");
|
| 259 |
+
return 1;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
fill_matrix(host_a, cfg.m, cfg.k, 0.03125f);
|
| 263 |
+
fill_matrix(host_b, cfg.k, cfg.n, 0.0625f);
|
| 264 |
+
reference_gemm(host_a, host_b, ref_c, cfg.m, cfg.n, cfg.k);
|
| 265 |
+
|
| 266 |
+
if (check_cuda(cudaMalloc((void**)&dev_a, a_bytes), "cudaMalloc(a)") != 0) return 1;
|
| 267 |
+
if (check_cuda(cudaMalloc((void**)&dev_b, b_bytes), "cudaMalloc(b)") != 0) return 1;
|
| 268 |
+
if (check_cuda(cudaMalloc((void**)&dev_c, c_bytes), "cudaMalloc(c)") != 0) return 1;
|
| 269 |
+
|
| 270 |
+
if (check_cuda(cudaMemcpy(dev_a, host_a, a_bytes, cudaMemcpyHostToDevice), "cudaMemcpy(a)") != 0) return 1;
|
| 271 |
+
if (check_cuda(cudaMemcpy(dev_b, host_b, b_bytes, cudaMemcpyHostToDevice), "cudaMemcpy(b)") != 0) return 1;
|
| 272 |
+
|
| 273 |
+
if (configure_ada_kernel() != 0) return 1;
|
| 274 |
+
|
| 275 |
+
block = dim3(PYC_ADA_THREADS_X, PYC_ADA_THREADS_Y, 1);
|
| 276 |
+
grid = dim3(
|
| 277 |
+
(unsigned int)((cfg.n + PYC_ADA_BLOCK_N - 1) / PYC_ADA_BLOCK_N),
|
| 278 |
+
(unsigned int)((cfg.m + PYC_ADA_BLOCK_M - 1) / PYC_ADA_BLOCK_M),
|
| 279 |
+
1);
|
| 280 |
+
|
| 281 |
+
if (check_cuda(cudaEventCreate(&start), "cudaEventCreate(start)") != 0) return 1;
|
| 282 |
+
if (check_cuda(cudaEventCreate(&stop), "cudaEventCreate(stop)") != 0) return 1;
|
| 283 |
+
|
| 284 |
+
for (iter = 0; iter < cfg.warmup; ++iter) {
|
| 285 |
+
ada_fp32_tiled_gemm<<<grid, block>>>(dev_a, dev_b, dev_c, cfg.m, cfg.n, cfg.k);
|
| 286 |
+
}
|
| 287 |
+
if (check_cuda(cudaGetLastError(), "kernel launch warmup") != 0) return 1;
|
| 288 |
+
if (check_cuda(cudaDeviceSynchronize(), "cudaDeviceSynchronize warmup") != 0) return 1;
|
| 289 |
+
|
| 290 |
+
best_ms = 0.0;
|
| 291 |
+
for (iter = 0; iter < cfg.iters; ++iter) {
|
| 292 |
+
if (check_cuda(cudaEventRecord(start), "cudaEventRecord(start)") != 0) return 1;
|
| 293 |
+
ada_fp32_tiled_gemm<<<grid, block>>>(dev_a, dev_b, dev_c, cfg.m, cfg.n, cfg.k);
|
| 294 |
+
if (check_cuda(cudaEventRecord(stop), "cudaEventRecord(stop)") != 0) return 1;
|
| 295 |
+
if (check_cuda(cudaEventSynchronize(stop), "cudaEventSynchronize(stop)") != 0) return 1;
|
| 296 |
+
if (check_cuda(cudaEventElapsedTime(&elapsed_ms, start, stop), "cudaEventElapsedTime") != 0) return 1;
|
| 297 |
+
if (iter == 0 || elapsed_ms < (float)best_ms) {
|
| 298 |
+
best_ms = elapsed_ms;
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
if (check_cuda(cudaMemcpy(host_c, dev_c, c_bytes, cudaMemcpyDeviceToHost), "cudaMemcpy(c)") != 0) return 1;
|
| 303 |
+
|
| 304 |
+
for (iter = 0; iter < cfg.m * cfg.n; ++iter) {
|
| 305 |
+
double diff = fabs((double)host_c[iter] - (double)ref_c[iter]);
|
| 306 |
+
if (diff > max_abs_diff) {
|
| 307 |
+
max_abs_diff = diff;
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
printf("shape=%dx%dx%d\n", cfg.m, cfg.n, cfg.k);
|
| 312 |
+
printf("tile=%dx%dx%d threads=%dx%d\n",
|
| 313 |
+
PYC_ADA_BLOCK_M,
|
| 314 |
+
PYC_ADA_BLOCK_N,
|
| 315 |
+
PYC_ADA_BLOCK_K,
|
| 316 |
+
PYC_ADA_THREADS_X,
|
| 317 |
+
PYC_ADA_THREADS_Y);
|
| 318 |
+
printf("best_ms=%.3f\n", best_ms);
|
| 319 |
+
printf("max_abs_diff=%.6f\n", max_abs_diff);
|
| 320 |
+
if (best_ms > 0.0) {
|
| 321 |
+
double flops = 2.0 * (double)cfg.m * (double)cfg.n * (double)cfg.k;
|
| 322 |
+
double gflops = flops / (best_ms * 1.0e6);
|
| 323 |
+
printf("gflops=%.3f\n", gflops);
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
cudaEventDestroy(start);
|
| 327 |
+
cudaEventDestroy(stop);
|
| 328 |
+
cudaFree(dev_a);
|
| 329 |
+
cudaFree(dev_b);
|
| 330 |
+
cudaFree(dev_c);
|
| 331 |
+
free(host_a);
|
| 332 |
+
free(host_b);
|
| 333 |
+
free(host_c);
|
| 334 |
+
free(ref_c);
|
| 335 |
+
return max_abs_diff <= 1e-2 ? 0 : 1;
|
| 336 |
+
}
|