summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Bakita <jbakita@cs.unc.edu>2024-02-26 20:33:25 -0500
committerJoshua Bakita <jbakita@cs.unc.edu>2024-02-26 20:33:25 -0500
commitd1576765658fc866bed806cbde969d39cc6a8dd8 (patch)
tree0235aa2cf81fb58f4d0137ffdfafac008408b2ad
parent340457bd5dae3624d4c92a02b84fb8206c0348a9 (diff)
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
-rw-r--r--.gitignore1
-rw-r--r--copy_experiments/Makefile6
-rw-r--r--copy_experiments/gl_copies.c92
3 files changed, 98 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 7cfda47..ec15392 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ constant_cycles_kernel
4measure_launch_oh 4measure_launch_oh
5copy_experiments/copy_contender 5copy_experiments/copy_contender
6copy_experiments/mon_cross_ctx_copies 6copy_experiments/mon_cross_ctx_copies
7copy_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 @@
1.PHONY: all clean 1.PHONY: all clean
2NVCC ?= nvcc 2NVCC ?= nvcc
3CC ?= gcc
3 4
4all: copy_contender mon_cross_ctx_copies 5all: copy_contender mon_cross_ctx_copies
5 6
@@ -9,5 +10,8 @@ copy_contender: copy_contender.cu copy_testbench.h ../testbench.h
9mon_cross_ctx_copies: mon_cross_ctx_copies.cu copy_testbench.h ../testbench.h 10mon_cross_ctx_copies: mon_cross_ctx_copies.cu copy_testbench.h ../testbench.h
10 $(NVCC) mon_cross_ctx_copies.cu -o $@ -lcuda -lpthread -g 11 $(NVCC) mon_cross_ctx_copies.cu -o $@ -lcuda -lpthread -g
11 12
13gl_copies: gl_copies.c
14 $(CC) gl_copies.c -o $@ -lGL -lglut -g
15
12clean: 16clean:
13 rm -f copy_contender mon_cross_ctx_copies 17 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 @@
1// Built off the Triangle and Checkered Triangle OpenGL examples by Ray Toal
2// (https://cs.lmu.edu/~ray/notes/openglexamples/)
3#include <stdio.h>
4
5#include <GL/glut.h>
6
7#define red {0xff, 0x00, 0x00}
8#define yellow {0xff, 0xff, 0x00}
9#define magenta {0xff, 0, 0xff}
10
11GLubyte* texture;
12
13const unsigned side = 1024*10; // 30 MiB
14
15// Clears the current window and draws a triangle.
16void display() {
17
18 // Set every pixel in the frame buffer to the current clear color.
19 glClear(GL_COLOR_BUFFER_BIT);
20
21 // Re-upload the texture on every frame
22 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, side, side, GL_RGB, GL_UNSIGNED_BYTE, texture);
23
24 // Drawing is done by specifying a sequence of vertices. The way these
25 // vertices are connected (or not connected) depends on the argument to
26 // glBegin. GL_POLYGON constructs a filled polygon.
27 glBegin(GL_POLYGON);
28 glTexCoord2f(0.5, side); glVertex3f(-0.6, -0.75, 0.5);
29 glTexCoord2f(0.0, 0.0); glVertex3f(0.6, -0.75, 0);
30 glTexCoord2f(side, 0.0); glVertex3f(0, 0.75, 0);
31 glEnd();
32
33 // Flush drawing command buffer to make drawing happen as soon as possible.
34 glFlush();
35
36 // Request a redraw on the next loop
37 glutPostRedisplay();
38}
39
40// Initializes GLUT, the display mode, and main window; registers callbacks;
41// enters the main event loop.
42int main(int argc, char** argv) {
43 // No arguments are accepted
44 if (argc != 1) {
45 fprintf(stderr, "Usage: %s\n", argv[0]);
46 return 1;
47 }
48
49 // 30 MiB image
50 texture = malloc(side*side*3u);
51
52 // Add a checkered pattern to the texture
53 for (unsigned i = 0; i < side*side; i++) {
54 if (i % 2 == 0) { // Yellow
55 texture[i*3] = 0xff;
56 texture[i*3+1] = 0xff;
57 } else // Red
58 texture[i*3] = 0xff;
59 }
60
61 // Use a single buffered window in RGB mode (as opposed to a double-buffered
62 // window or color-index mode).
63 glutInit(&argc, argv);
64 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
65
66 // Position window at (80,80)-(480,380) and give it a title.
67 glutInitWindowPosition(80, 80);
68 glutInitWindowSize(400, 300);
69 glutCreateWindow("A Simple Triangle");
70
71 // Tell GLUT that whenever the main window needs to be repainted that it
72 // should call the function display().
73 glutDisplayFunc(display);
74
75 glEnable(GL_TEXTURE_2D);
76 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
77 glTexImage2D(GL_TEXTURE_2D,
78 0, // level 0
79 3, // use only R, G, and B components
80 side, side, // texture has 2x2 texels
81 0, // no border
82 GL_RGB, // texels are in RGB format
83 GL_UNSIGNED_BYTE, // color components are unsigned bytes
84 texture);
85 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
86 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
87
88 // Tell GLUT to start reading and processing events. This function
89 // never returns; the program only exits when the user closes the main
90 // window or kills the process.
91 glutMainLoop();
92}