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;
}