2023-02-01 22:30:00 +09:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-02-02 19:02:36 +09:00
|
|
|
#include "uNet.h"
|
2023-02-01 22:30:00 +09:00
|
|
|
#include "util.h"
|
2023-02-06 15:07:20 +09:00
|
|
|
#include <cuda_runtime.h>
|
|
|
|
|
|
|
|
const int WARM_UP = 2;
|
|
|
|
const int MEASURE = 3;
|
2023-02-01 22:30:00 +09:00
|
|
|
|
|
|
|
// Global variables
|
|
|
|
int N = 1;
|
|
|
|
char *parameter_fname;
|
|
|
|
char *output_fname;
|
2023-02-04 17:43:29 +09:00
|
|
|
char *input_fname;
|
2023-02-01 22:30:00 +09:00
|
|
|
|
|
|
|
|
2023-02-06 15:07:20 +09:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
2023-02-01 22:30:00 +09:00
|
|
|
check_and_parse_args(argc, argv);
|
2023-02-06 01:38:42 +09:00
|
|
|
print_model();
|
2023-02-01 22:30:00 +09:00
|
|
|
|
|
|
|
// Initialize model
|
2023-02-06 01:38:42 +09:00
|
|
|
uNet_initialize(N, parameter_fname);
|
2023-02-01 22:30:00 +09:00
|
|
|
|
2023-02-06 15:07:20 +09:00
|
|
|
Tensor *input = new Tensor({N, 3, 640, 959});
|
|
|
|
Tensor *output = new Tensor({N, 2, 640, 959});
|
2023-02-06 01:38:42 +09:00
|
|
|
|
|
|
|
size_t input_size = 0;
|
2023-02-06 15:07:20 +09:00
|
|
|
read_binary((void*)input->buf, input_fname, &input_size);
|
2023-02-03 01:25:19 +09:00
|
|
|
|
2023-02-06 15:07:20 +09:00
|
|
|
printf(" process %d image(s)...", N);
|
2023-02-01 22:30:00 +09:00
|
|
|
fflush(stdout);
|
|
|
|
|
2023-02-06 15:07:20 +09:00
|
|
|
// warm_up
|
2023-02-06 15:21:16 +09:00
|
|
|
printf("\nWarmimg up.");
|
|
|
|
for(int i = 0 ; i < WARM_UP ; ++i){
|
2023-02-06 15:07:20 +09:00
|
|
|
uNet(input, output, N);
|
2023-02-06 15:21:16 +09:00
|
|
|
printf(".");
|
|
|
|
}
|
|
|
|
cudaDeviceSynchronize();
|
|
|
|
printf("\n");
|
2023-02-06 15:07:20 +09:00
|
|
|
|
2023-02-03 01:25:19 +09:00
|
|
|
// run uNet and measure time
|
2023-02-06 15:21:16 +09:00
|
|
|
printf("\nProcess.");
|
2023-02-02 23:37:40 +09:00
|
|
|
double uNet_st = get_time();
|
2023-02-06 15:21:16 +09:00
|
|
|
for(int j = 0 ; j < MEASURE ; ++j){
|
|
|
|
uNet(input, output, N);
|
|
|
|
printf(".");
|
|
|
|
}
|
2023-02-06 15:07:20 +09:00
|
|
|
cudaDeviceSynchronize();
|
2023-02-02 23:37:40 +09:00
|
|
|
double uNet_en = get_time();
|
2023-02-06 15:21:16 +09:00
|
|
|
printf("\n");
|
2023-02-02 23:37:40 +09:00
|
|
|
double elapsed_time = uNet_en - uNet_st;
|
2023-02-06 15:07:20 +09:00
|
|
|
printf("Done! (%lf img/sec)\n", N/elapsed_time/MEASURE);
|
|
|
|
|
|
|
|
write_binary((void*)output->buf, output_fname, (size_t)(N * 2 * 640 * 959));
|
2023-02-06 01:38:42 +09:00
|
|
|
|
|
|
|
printf(" Writing to %s ...", output_fname);
|
|
|
|
fflush(stdout);
|
2023-02-06 15:07:20 +09:00
|
|
|
|
2023-02-06 01:38:42 +09:00
|
|
|
printf("Done!\n\n");
|
2023-02-01 22:30:00 +09:00
|
|
|
|
|
|
|
// Finalize program
|
2023-02-02 23:37:40 +09:00
|
|
|
uNet_finalize();
|
2023-02-01 22:30:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|