File size: 2,036 Bytes
be99550 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
__global__ void expert_kernel(uint32_t* vram, size_t size, int model_id) {
size_t idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx < size) {
uint32_t compressed_val = vram[idx];
float sum = 0.0f;
// μ μ§ν μ€μκ° 16x μμΆ ν΄μ (2-bit Unpacking) λ° 8-State 볡μ
#pragma unroll
for(int j=0; j<16; j++) {
uint32_t two_bits = (compressed_val >> (j * 2)) & 0x3;
// μν€ν
μ²(model_id)λ³ μμ΄ν κ°μ€μΉ κ°μ(Interference) μν λͺ¨μ¬
float decoded_weight = (float)two_bits - 1.5f + (model_id * 0.1f);
sum += decoded_weight;
}
vram[idx] = compressed_val ^ *((uint32_t*)&sum);
}
}
int main(int argc, char** argv) {
if (argc < 3) return -1;
int model_id = atoi(argv[1]);
char* model_name = argv[2];
size_t size = 10000000; // 40MB Holographic Slice
uint32_t* d_vram;
hipMalloc(&d_vram, size * 4);
LARGE_INTEGER freq, start, end;
QueryPerformanceFrequency(&freq);
// Warmup
hipLaunchKernelGGL(expert_kernel, dim3((size+255)/256), dim3(256), 0, 0, d_vram, size, model_id);
hipDeviceSynchronize();
int passes = 1000;
QueryPerformanceCounter(&start);
// λͺ¨λΈλ³ λ¨λ
μ€ν 루ν (Zero-Overhead)
for(int i=0; i<passes; i++) {
hipLaunchKernelGGL(expert_kernel, dim3((size+255)/256), dim3(256), 0, 0, d_vram, size, model_id);
}
hipDeviceSynchronize();
uint32_t check_val;
hipMemcpy(&check_val, &d_vram[size-1], 4, hipMemcpyDeviceToHost);
QueryPerformanceCounter(&end);
double elapsed = (double)(end.QuadPart - start.QuadPart) / freq.QuadPart;
double tps = 1000.0 / elapsed;
printf(" ββ π§ [%d] %-16s | β±οΈ Time: %.4f s | π TPS: %-8.2f | π¬ Sync: 0x%X\n", model_id, model_name, elapsed, tps, check_val);
hipFree(d_vram);
return 0;
}
|