import paramiko

HIP_CODE = '''#include <hip/hip_runtime.h>
#include <stdio.h>
__global__ void vectorAdd(float *a, float *b, float *c, int n) {
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    if (i < n) c[i] = a[i] + b[i];
}
int main() {
    const int N = 1024;
    size_t sz = N * sizeof(float);
    float *h_a = (float*)malloc(sz), *h_b = (float*)malloc(sz), *h_c = (float*)malloc(sz);
    float *d_a, *d_b, *d_c;
    for (int i = 0; i < N; i++) { h_a[i] = i; h_b[i] = i * 2; }
    hipMalloc(&d_a, sz); hipMalloc(&d_b, sz); hipMalloc(&d_c, sz);
    hipMemcpy(d_a, h_a, sz, hipMemcpyHostToDevice);
    hipMemcpy(d_b, h_b, sz, hipMemcpyHostToDevice);
    vectorAdd<<<(N+255)/256, 256>>>(d_a, d_b, d_c, N);
    hipMemcpy(h_c, d_c, sz, hipMemcpyDeviceToHost);
    hipDeviceSynchronize();
    hipError_t err = hipGetLastError();
    if (err != hipSuccess) { printf("HIP ERROR: %s\\n", hipGetErrorString(err)); return 1; }
    int ok = 1;
    for (int i = 0; i < N; i++) {
        if (h_c[i] != h_a[i] + h_b[i]) { ok = 0; printf("MISMATCH at %d\\n", i); break; }
    }
    if (ok) printf("HIP COMPUTE TEST PASSED: %d elements verified\\n", N);
    hipFree(d_a); hipFree(d_b); hipFree(d_c);
    free(h_a); free(h_b); free(h_c);
    return 0;
}
'''

c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('192.168.178.150', username='fabian', key_filename=r'C:\Users\fabia\.ssh\id_ed25519')
sftp = c.open_sftp()
with sftp.open('/tmp/hip_test.cpp', 'w') as f:
    f.write(HIP_CODE)
sftp.close()
c.close()
print('HIP test file uploaded via SFTP')
