Skip to content

[svm] Print both total and compute-only times #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions svm/CUDA/cuSVM/cuSVMSolver.cu
Original file line number Diff line number Diff line change
Expand Up @@ -549,25 +549,23 @@ void SVMTrain(float *mexalpha,float* beta,float*y,float *x ,float _C, float _ker

printf("_C %f\n", _C);

std::chrono::time_point<std::chrono::high_resolution_clock> start_ct1;
std::chrono::time_point<std::chrono::high_resolution_clock> stop_ct1;
std::chrono::time_point<std::chrono::steady_clock> start_clock_init;
std::chrono::time_point<std::chrono::steady_clock> start_clock_exec;
std::chrono::time_point<std::chrono::steady_clock> stop_clock;


start_ct1 = std::chrono::high_resolution_clock::now();
start_clock_init = std::chrono::steady_clock::now();

// Creating and recording an event implicitly initialises device queue
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start,0);


//cudaSetDevice(0);
start_clock_exec = std::chrono::steady_clock::now();

mxArray *mexelapsed =mxCreateNumericMatrix(1, 1,mxSINGLE_CLASS, mxREAL);
float * elapsed=(float *)mxGetData(mexelapsed);


cudaEventRecord(start,0);

int numBlocks=64;
dim3 ReduceGrid(numBlocks, 1, 1);
dim3 ReduceBlock(256, 1, 1);
Expand Down Expand Up @@ -831,11 +829,12 @@ void SVMTrain(float *mexalpha,float* beta,float*y,float *x ,float _C, float _ker
cudaEventElapsedTime(elapsed, start, stop);


stop_ct1 = std::chrono::high_resolution_clock::now();
stop_clock = std::chrono::steady_clock::now();

//stop.wait_and_throw();
float duration = std::chrono::duration<float, std::milli>(stop_ct1 - start_ct1).count();
printf("Total run time: %f seconds\n", duration/1000.00);
float duration_compute = std::chrono::duration<float, std::milli>(stop_clock - start_clock_exec).count();
float duration_total = std::chrono::duration<float, std::milli>(stop_clock - start_clock_init).count();
printf("Compute time: %f seconds\n", duration_compute/1000.00);
printf("Total run time: %f seconds\n", duration_total/1000.00);

printf("Iter:%i\n", iter);
printf("M:%i\n", m);
Expand Down
25 changes: 14 additions & 11 deletions svm/HIP/cuSVM/cuSVMSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,21 +522,23 @@ void SVMTrain(float *mexalpha,float* beta,float*y,float *x ,float _C, float _ker

printf("_C %f\n", _C);

std::chrono::time_point<std::chrono::steady_clock> start_clock_init;
std::chrono::time_point<std::chrono::steady_clock> start_clock_exec;
std::chrono::time_point<std::chrono::steady_clock> stop_clock;

start_clock_init = std::chrono::steady_clock::now();

// Creating and recording an event implicitly initialises device queue
hipEvent_t start, stop;
hipEventCreate(&start);
hipEventCreate(&stop);
hipEventRecord(start,0);

std::chrono::time_point<std::chrono::high_resolution_clock> start_ct1;
std::chrono::time_point<std::chrono::high_resolution_clock> stop_ct1;

start_ct1 = std::chrono::high_resolution_clock::now();
start_clock_exec = std::chrono::steady_clock::now();

mxArray *mexelapsed =mxCreateNumericMatrix(1, 1,mxSINGLE_CLASS, mxREAL);
float * elapsed=(float *)mxGetData(mexelapsed);


hipEventRecord(start,0);

int numBlocks=64;
dim3 ReduceGrid(numBlocks, 1, 1);
dim3 ReduceBlock(256, 1, 1);
Expand Down Expand Up @@ -800,11 +802,12 @@ void SVMTrain(float *mexalpha,float* beta,float*y,float *x ,float _C, float _ker
hipEventElapsedTime(elapsed, start, stop);


stop_ct1 = std::chrono::high_resolution_clock::now();
stop_clock = std::chrono::steady_clock::now();

//stop.wait_and_throw();
float duration = std::chrono::duration<float, std::milli>(stop_ct1 - start_ct1).count();
printf("Total run time: %f seconds\n", duration/1000.00);
float duration_compute = std::chrono::duration<float, std::milli>(stop_clock - start_clock_exec).count();
float duration_total = std::chrono::duration<float, std::milli>(stop_clock - start_clock_init).count();
printf("Compute time: %f seconds\n", duration_compute/1000.00);
printf("Total run time: %f seconds\n", duration_total/1000.00);

printf("Iter:%i\n", iter);
printf("M:%i\n", m);
Expand Down
23 changes: 11 additions & 12 deletions svm/SYCL/cuSVM/cuSVMSolver.dp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,25 +794,24 @@ extern "C" void SVMTrain(float *mexalpha, float *beta, float *y, float *x,
sycl::event queue_event;

sycl::event start, stop;
std::chrono::time_point<std::chrono::high_resolution_clock> start_ct1;
std::chrono::time_point<std::chrono::high_resolution_clock> stop_ct1;

start_ct1 = std::chrono::high_resolution_clock::now();
std::chrono::time_point<std::chrono::steady_clock> start_clock_init;
std::chrono::time_point<std::chrono::steady_clock> start_clock_exec;
std::chrono::time_point<std::chrono::steady_clock> stop_clock;

start_clock_init = std::chrono::steady_clock::now();

// Select device and initialise the queue
sycl::device selected_device = sycl::device(sycl::default_selector());
sycl::context context({selected_device});

auto max_wgroup_size = selected_device.get_info<sycl::info::device::max_work_group_size>();
printf("Workgroup Size: %lu\n", max_wgroup_size);

#if KERNEL_USE_PROFILE
auto propList = sycl::property_list{sycl::property::queue::enable_profiling()};
sycl::queue q_ct1(context, selected_device, propList);
#else
sycl::queue q_ct1(context, selected_device);
#endif

start_clock_exec = std::chrono::steady_clock::now();

mxArray *mexelapsed =mxCreateNumericMatrix(1, 1,mxSINGLE_CLASS, mxREAL);
float * elapsed=(float *)mxGetData(mexelapsed);
Expand Down Expand Up @@ -1280,12 +1279,12 @@ _kernelwidth*=-1;

q_ct1.memcpy(mexalpha, d_alpha, m * sizeof(float)).wait();

stop_ct1 = std::chrono::high_resolution_clock::now();
stop_clock = std::chrono::steady_clock::now();

//stop.wait_and_throw();
float duration = std::chrono::duration<float, std::milli>(stop_ct1 - start_ct1).count();
printf("Total run time: %f seconds\n", duration/1000.00);

float duration_compute = std::chrono::duration<float, std::milli>(stop_clock - start_clock_exec).count();
float duration_total = std::chrono::duration<float, std::milli>(stop_clock - start_clock_init).count();
printf("Compute time: %f seconds\n", duration_compute/1000.00);
printf("Total run time: %f seconds\n", duration_total/1000.00);

printf("Iter:%i\n", iter);
printf("M:%i\n", m);
Expand Down