Commit c69b572f authored by Sabrina Templeton's avatar Sabrina Templeton
Browse files

added timing for the GPU (maybe incorrect) and the ability to write results to a file

parent 2d701625
......@@ -20,6 +20,10 @@
#include <time.h>
#include <iostream>
#include <fstream>
using namespace avro;
UT_TEST_SUITE( voronoi_toy )
......@@ -74,6 +78,10 @@ UT_TEST_CASE( test1 )
graphics::ShaderProgram shader("voronoi",false,{"#version 410"});
shader.use();
// graphics::ShaderProgram points_shader("points",false,{"#version 410"});
// points_shader.use();
graphics::gl_index vertex_array;
GL_CALL( glGenVertexArrays( 1, &vertex_array ) );
GL_CALL( glBindVertexArray(vertex_array) );
......@@ -103,7 +111,7 @@ if (DEBUG == 0){
};
// //std::cout << "Test Print!!!!!!!!!!!!!";
//std::cout << "Test Print!!!!!!!!!!!!!";
}
else{
float dx = 1 / (sqrt(num_points) + 1); //delta y is the same if we're going for a grid
......@@ -294,7 +302,7 @@ else{
// grey-ish (almost white) background color
float col = 0.9;
glClearColor (col,col,col, 0.0);
glClearColor (col,col, col, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mvp = perspective_matrix * mv;
......@@ -323,33 +331,66 @@ else{
clock_t TIME2 = clock();
GL_CALL( glBindBuffer(GL_ARRAY_BUFFER, points_buffer ) ); // it doesn't really matter which buffer we bind here since it isn't used
int points_remaining = num_points;
int first_point_to_draw = 0;
int call_size = 1e6;
while (points_remaining > 0){
//std::cout << "one iteration" << std::endl;
std::cout << points_remaining << std::endl;
// std::cout << first_point_to_draw << std::endl;
if (points_remaining < call_size){
// std::cout << "if statement" << std::endl;
// std::cout << first_point_to_draw << std::endl;
// std::cout << first_point_to_draw + points_remaining << std::endl;
GL_CALL( glDrawArrays(GL_POINTS, first_point_to_draw , points_remaining ) );
points_remaining = 0;
}
else{
//std::cout << "test" << std::endl;
GL_CALL( glDrawArrays(GL_POINTS, first_point_to_draw , call_size ) );
points_remaining -= call_size;
first_point_to_draw += call_size;
}
}
//GL_CALL( glDrawArrays(GL_POINTS, 0, points_remaining ) );
clock_t TIME3 = clock();
printf("--> GPU run time = %g seconds\n",real_t(TIME3-TIME2)/real_t(CLOCKS_PER_SEC));
// int points_remaining = num_points;
// int first_point_to_draw = 0;
// int call_size = 1e5;
// while (points_remaining > 0){
// //std::cout << "one iteration" << std::endl;
// std::cout << points_remaining << std::endl;
// // std::cout << first_point_to_draw << std::endl;
// if (points_remaining < call_size){
// // std::cout << "if statement" << std::endl;
// // std::cout << first_point_to_draw << std::endl;
// // std::cout << first_point_to_draw + points_remaining << std::endl;
// GL_CALL( glDrawArrays(GL_POINTS, first_point_to_draw , points_remaining ) );
// points_remaining = 0;
// }
// else{
// //std::cout << "test" << std::endl;
// GL_CALL( glDrawArrays(GL_POINTS, first_point_to_draw , call_size ) );
// points_remaining -= call_size;
// first_point_to_draw += call_size;
// }
GLuint query;
//GLuint64 elapsed_time;
glGenQueries(1, &query);
glBeginQuery(GL_TIME_ELAPSED,query);
// call some OpenGL commands
//code borrowed from https://www.lighthouse3d.com/tutorials/opengl-timer-query/
GL_CALL( glDrawArrays(GL_POINTS, 0, num_points) );
glEndQuery(GL_TIME_ELAPSED);
GLuint64 time;
glGetQueryObjectui64v(query, GL_QUERY_RESULT, &time);
//GL_CALL( glDrawArrays (GL_POINTS, 0, num_points) );
clock_t TIME3 = clock();
//std::cout << time;
FILE * pFile;
printf("--> GPU run time = %f seconds\n", time/1e9 );//real_t(TIME3-TIME2)/real_t(CLOCKS_PER_SEC));
std::ofstream myfile;
pFile = fopen ("results.txt", "a");
//fprintf(pFile, "--> nearest neighbor calculation time = %g seconds\n",real_t(TIME1-TIME0)/real_t(CLOCKS_PER_SEC));
//fprintf(pFile, "--> GPU run time = %f seconds\n", time/1e9 );
fprintf(pFile, "1e6 & %.2g & %.2f \\\\ \n", real_t(TIME1-TIME0)/real_t(CLOCKS_PER_SEC), time/1e9 );
std::cout << "should have written to a file.";
myfile.close();
//points_shader.use();
//points_shader.setUniform("u_ModelViewProjectionMatrix", mvp );
glfwSwapBuffers(window);
while (true) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment