From d1576765658fc866bed806cbde969d39cc6a8dd8 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Mon, 26 Feb 2024 20:33:25 -0500 Subject: Add gl_copies benchmark and make target => Uploads a large texture to the GPU on every frame => Requires the freeglut library (freeglut3-dev on Ubuntu) => Due to special requirements, not built by default => Written for Anderson and Bakita RTAS'24 paper --- .gitignore | 1 + copy_experiments/Makefile | 6 ++- copy_experiments/gl_copies.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 copy_experiments/gl_copies.c diff --git a/.gitignore b/.gitignore index 7cfda47..ec15392 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ constant_cycles_kernel measure_launch_oh copy_experiments/copy_contender copy_experiments/mon_cross_ctx_copies +copy_experiments/gl_copies diff --git a/copy_experiments/Makefile b/copy_experiments/Makefile index ede22dc..5adda53 100644 --- a/copy_experiments/Makefile +++ b/copy_experiments/Makefile @@ -1,5 +1,6 @@ .PHONY: all clean NVCC ?= nvcc +CC ?= gcc all: copy_contender mon_cross_ctx_copies @@ -9,5 +10,8 @@ copy_contender: copy_contender.cu copy_testbench.h ../testbench.h mon_cross_ctx_copies: mon_cross_ctx_copies.cu copy_testbench.h ../testbench.h $(NVCC) mon_cross_ctx_copies.cu -o $@ -lcuda -lpthread -g +gl_copies: gl_copies.c + $(CC) gl_copies.c -o $@ -lGL -lglut -g + clean: - rm -f copy_contender mon_cross_ctx_copies + rm -f copy_contender mon_cross_ctx_copies gl_copies diff --git a/copy_experiments/gl_copies.c b/copy_experiments/gl_copies.c new file mode 100644 index 0000000..4d6de1f --- /dev/null +++ b/copy_experiments/gl_copies.c @@ -0,0 +1,92 @@ +// Built off the Triangle and Checkered Triangle OpenGL examples by Ray Toal +// (https://cs.lmu.edu/~ray/notes/openglexamples/) +#include + +#include + +#define red {0xff, 0x00, 0x00} +#define yellow {0xff, 0xff, 0x00} +#define magenta {0xff, 0, 0xff} + +GLubyte* texture; + +const unsigned side = 1024*10; // 30 MiB + +// Clears the current window and draws a triangle. +void display() { + + // Set every pixel in the frame buffer to the current clear color. + glClear(GL_COLOR_BUFFER_BIT); + + // Re-upload the texture on every frame + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, side, side, GL_RGB, GL_UNSIGNED_BYTE, texture); + + // Drawing is done by specifying a sequence of vertices. The way these + // vertices are connected (or not connected) depends on the argument to + // glBegin. GL_POLYGON constructs a filled polygon. + glBegin(GL_POLYGON); + glTexCoord2f(0.5, side); glVertex3f(-0.6, -0.75, 0.5); + glTexCoord2f(0.0, 0.0); glVertex3f(0.6, -0.75, 0); + glTexCoord2f(side, 0.0); glVertex3f(0, 0.75, 0); + glEnd(); + + // Flush drawing command buffer to make drawing happen as soon as possible. + glFlush(); + + // Request a redraw on the next loop + glutPostRedisplay(); +} + +// Initializes GLUT, the display mode, and main window; registers callbacks; +// enters the main event loop. +int main(int argc, char** argv) { + // No arguments are accepted + if (argc != 1) { + fprintf(stderr, "Usage: %s\n", argv[0]); + return 1; + } + + // 30 MiB image + texture = malloc(side*side*3u); + + // Add a checkered pattern to the texture + for (unsigned i = 0; i < side*side; i++) { + if (i % 2 == 0) { // Yellow + texture[i*3] = 0xff; + texture[i*3+1] = 0xff; + } else // Red + texture[i*3] = 0xff; + } + + // Use a single buffered window in RGB mode (as opposed to a double-buffered + // window or color-index mode). + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); + + // Position window at (80,80)-(480,380) and give it a title. + glutInitWindowPosition(80, 80); + glutInitWindowSize(400, 300); + glutCreateWindow("A Simple Triangle"); + + // Tell GLUT that whenever the main window needs to be repainted that it + // should call the function display(). + glutDisplayFunc(display); + + glEnable(GL_TEXTURE_2D); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, + 0, // level 0 + 3, // use only R, G, and B components + side, side, // texture has 2x2 texels + 0, // no border + GL_RGB, // texels are in RGB format + GL_UNSIGNED_BYTE, // color components are unsigned bytes + texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + // Tell GLUT to start reading and processing events. This function + // never returns; the program only exits when the user closes the main + // window or kills the process. + glutMainLoop(); +} -- cgit v1.2.2