forked from jvhs0706/zkllm-ccs2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathioutils.cu
46 lines (35 loc) · 989 Bytes
/
ioutils.cu
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
#include "ioutils.cuh"
void savebin(const string& filename, const void* gpudata, uint size)
{
// Copy data from GPU to CPU
void* data = malloc(size);
cudaMemcpy(data, gpudata, size, cudaMemcpyDeviceToHost);
// Write data to file
FILE* file = fopen(filename.c_str(), "wb");
fwrite(data, 1, size, file);
fclose(file);
// Free memory
free(data);
}
uint findsize(const string& filename)
{
// Read data from file
FILE* file = fopen(filename.c_str(), "rb");
fseek(file, 0, SEEK_END);
uint size = ftell(file);
fclose(file);
return size;
}
void loadbin(const string& filename, void* gpudata, uint size)
{
// Allocate memory
void* data = malloc(size);
// Read data from file
FILE* file = fopen(filename.c_str(), "rb");
fread(data, 1, size, file);
fclose(file);
// Copy data from CPU to GPU
cudaMemcpy(gpudata, data, size, cudaMemcpyHostToDevice);
// Free memory
free(data);
}