2023-02-15 01:33:28 +09:00
|
|
|
#include <cuda_runtime.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-02-01 22:30:00 +09:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
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
|
|
|
|
2023-02-20 17:05:39 +09:00
|
|
|
int WARMUP = 0;
|
|
|
|
int MEASURE = 1;
|
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-20 17:05:39 +09:00
|
|
|
/*
|
|
|
|
Execute Parameters
|
|
|
|
argv[1] = unet model parameters path
|
|
|
|
argv[2] = input image path
|
|
|
|
argv[3] = output save path
|
|
|
|
argv[4] = the number of images to inference
|
|
|
|
|
|
|
|
// optional
|
|
|
|
argv[5] = warming up count
|
|
|
|
argv[6] = performance measuring count
|
|
|
|
|
|
|
|
*/
|
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-12 03:06:22 +09:00
|
|
|
Tensor *input = new Tensor({N, 3, 128, 191});
|
|
|
|
Tensor *output = new Tensor({N, 2, 128, 191});
|
2023-02-15 01:33:28 +09:00
|
|
|
|
2023-02-06 01:38:42 +09:00
|
|
|
size_t input_size = 0;
|
2023-02-15 01:33:28 +09:00
|
|
|
read_binary((void *) input->buf, input_fname, &input_size);
|
2023-02-03 01:25:19 +09:00
|
|
|
|
2023-02-20 17:05:39 +09:00
|
|
|
if (argc > 5){
|
|
|
|
WARMUP = atoi(argv[5]);
|
|
|
|
MEASURE = atoi(argv[6]);
|
|
|
|
}
|
|
|
|
|
2023-02-06 15:07:20 +09:00
|
|
|
printf(" process %d image(s)...", N);
|
2023-02-20 17:05:39 +09:00
|
|
|
printf(" Warm up [%d], Performance measure [%d]\n",WARMUP, MEASURE);
|
2023-02-15 01:33:28 +09:00
|
|
|
fflush(stdout);
|
2023-02-01 22:30:00 +09:00
|
|
|
|
2023-02-20 17:05:39 +09:00
|
|
|
// warming up
|
2023-02-06 15:21:16 +09:00
|
|
|
printf("\nWarmimg up.");
|
2023-02-14 17:45:28 +09:00
|
|
|
fflush(stdout);
|
2023-02-20 17:05:39 +09:00
|
|
|
for (int i = 0; i < WARMUP; ++i) {
|
2023-02-06 15:07:20 +09:00
|
|
|
uNet(input, output, N);
|
2023-02-14 17:45:28 +09:00
|
|
|
fflush(stdout);
|
2023-02-06 15:21:16 +09:00
|
|
|
printf(".");
|
|
|
|
}
|
|
|
|
cudaDeviceSynchronize();
|
|
|
|
printf("\n");
|
2023-02-06 15:07:20 +09:00
|
|
|
|
2023-02-20 17:05:39 +09:00
|
|
|
// performance measure
|
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-15 01:33:28 +09:00
|
|
|
for (int j = 0; j < MEASURE; ++j) {
|
2023-02-06 15:21:16 +09:00
|
|
|
uNet(input, output, N);
|
|
|
|
printf(".");
|
|
|
|
}
|
2023-02-06 15:07:20 +09:00
|
|
|
cudaDeviceSynchronize();
|
2023-02-15 01:33:28 +09:00
|
|
|
double uNet_en = get_time();
|
2023-02-06 15:21:16 +09:00
|
|
|
printf("\n");
|
2023-02-15 01:33:28 +09:00
|
|
|
double elapsed_time = uNet_en - uNet_st;
|
|
|
|
elapsed_time = elapsed_time / MEASURE;
|
|
|
|
printf("%lfsec (%lf img/sec)\n", elapsed_time, N / elapsed_time);
|
2023-02-06 15:07:20 +09:00
|
|
|
|
2023-02-15 01:33:28 +09:00
|
|
|
write_binary((void *) output->buf, output_fname, (size_t)(N * 2 * 128 * 191));
|
2023-02-06 01:38:42 +09:00
|
|
|
|
2023-02-20 17:05:39 +09:00
|
|
|
printf("Writing final result to %s ...", output_fname);
|
2023-02-06 01:38:42 +09:00
|
|
|
fflush(stdout);
|
2023-02-15 01:33:28 +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
|
|
|
}
|