12int main(
int argc,
char** argv) {
13 FILE *in_file, *out_file;
14 size_t in_size, out_size;
16 void *in_host = 0, *out_host = 0, *out_gpu = 0, *in_gpu = 0;
17 unsigned int * header;
18 cudaEvent_t event_begin, event_end;
23 usage(argv[0],
"Incorrect argument count.");
28 size_x = atoi(argv[1]);
29 size_y = atoi(argv[2]);
30 if(size_x <= 0 || (size_x & 3) || size_y == 0 || (
abs(size_y) & 3)) {
31 usage(argv[0],
"Image sizes must be positive numbers divisible by 4.");
37 usage(argv[0],
"Cannot set CUDA device #0.");
42 out_size = size_x *
abs(size_y);
43 in_size = out_size * 3;
44 cudaMallocHost(&in_host, in_size);
45 cudaMallocHost(&out_host, out_size);
48 if(!in_host || !out_host || !out_gpu || !in_gpu) {
49 usage(argv[0],
"Cannot allocate buffers.\n");
54 in_file = fopen(argv[3],
"r");
56 usage(argv[0],
"Could not open input file.");
62 fseek(in_file, 0, SEEK_END);
63 if(ftell(in_file) != (
long int)in_size) {
64 usage(argv[0],
"Input file size does not match.");
67 fseek(in_file, 0, SEEK_SET);
71 if(1 != fread(in_host, in_size, 1, in_file)) {
72 usage(argv[0],
"Could not read from input file.");
79 usage(argv[0],
"Could not copy input to GPU.");
84 cudaEventCreate(&event_end);
85 cudaEventCreate(&event_begin);
86 cudaEventRecord(event_begin, 0);
90 usage(argv[0],
"DXT Encoder error.");
95 cudaEventRecord(event_end, 0);
104 cudaEventElapsedTime(&kernel_time_ms, event_begin, event_end);
105 printf(
"DXT6 compression time: %.3f ms.\n", kernel_time_ms);
109 usage(argv[0],
"Could not copy output to host memory.");
114 out_file = fopen(argv[4],
"w");
116 usage(argv[0],
"Could not open output file for writing.");
121 if(1 != fwrite(out_host, out_size, 1, out_file)) {
122 usage(argv[0],
"Could not write into output file.");