OK, turing.

<- leave blank

Fri Sep 23 00:24:18 EDT 2022

test


Thu Sep 22 22:23:06 EDT 2022
Hi my name is Mike, you can 5x your copy or article output and boost sales with
this tool.  Try it out today for free with 10,000 credits.

Get unlimited graphic designs for your business.  You think it and Jasper will
create it and you will never pay a graphic designer again.

 Jasperwrite.com

Note: Check features tab for image creation and more.

Regards,
Mike

Do not want to save money and time?  Email:optout@jasperwrite.com

Thu Sep 22 20:46:43 EDT 2022
From tuhs.org!tuhs-bounces Wed Sep 21 20:33:34 -0400 2022
From: Rob Pike <robpike@gmail.com>
Date: Thu, 22 Sep 2022 10:32:15 +1000
To: The Eunuchs Hysterical Society <tuhs@tuhs.org>
Message-ID-Hash: ORPNGSPQ3JXFW3Q62P4ZCCYT7H5XRRIP
Subject: [TUHS] Re: Early BSD license thread
Archived-At:
<https://www.tuhs.org/mailman3/hyperkitty/list/tuhs@tuhs.org/message/ORPNGSPQ3JXFW3Q62P4ZCCYT7H5XRRIP/>

Around 1977 I was working/volunteering/studying at the Dynamic Graphics Lab
at the University of Toronto, where Unix ran on an 11/45 and we had a bunch
of graphics hardware.  Doing graphics on a PDP-11 was a challenge, but we
managed.  (For reference: later Dave Tennenhouse made a 256x256x8bit frame
buffer, and that was the size of entire PDP-11 data address space.)

Everyone was jealous of the C/A/T phototypesetter that Bell Labs Research
used to print their documentation.  One Friday evening I had the idea to use
our stinky but effective Versatec plotter as an output device for nroff.  In
just a few hours - our libraries were already pretty good - I had something
tolerable running.  Tom Duff dropped by and helped make it faster by coding
what we would now call the character blitter in assembler.  Then Bill Reeves
joined in, and Mike Tilson, and by the end of the weekend we had pretty
good efficient output.  (Still nroff; troff came later, mostly due to Bill I
think, who did a lot of work on the character set.) It was grey and blotchy
and smelly, but after a Xerox copy it looked pretty good for the time.

Ron Baecker, who ran the lab and was the graduate advisor for everyone else
- I was just an undergraduate physics student having fun - stopped by on
Monday morning and was furious to see us all hammering on the code.
Everyone was supposed to be working on their thesis and we had spent the
weekend hacking.  I was about to be in serious trouble for distracting the
graduate students.  But then he saw the output and completely changed his
tune: "Can I use this to print out my new grant proposal?"

For context, consider this: I used the system for my 4th year optics
project report.  The professor was furious with me for copying someone's
work.  He did not believe it possible to create output like that (and to be
fair, it wasn't possible almost anywhere else).  I had to take him to the
lab and show him how I did it before he would let me pass the course.  Until
then, no one had seen a student capable of making text look good.

The software went on the Toronto tape, with a top-of-file comment crediting
me, Bill, Tom, and Mike.  It emerged again from Berkeley with that comment
replaced by the Regents' rankling rewrite.

When I interviewed at Bell Labs, Dennis Ritchie saw on my resume that I
claimed to have worked on the Versatec text output system.  He asked why I
had bothered, when Berkeley had already done it.  "Because we wrote it
first, and Berkeley took the credit," I said.  Berkeley did tweak it, but
honestly it was mostly our work.

I didn't care so much about losing credit for the code, but the idea was
100% mine, and for a young punk the loss of credit was upsetting.  Later
Henry Spencer, another Toronto graduate, explained the story on Usenet.  I
don't know if he was believed, and through the 1980s it remained the
"Berkeley typesetting software."

It was all long ago, but seeing that "Regents" comment is, as we say today,
triggering.

But to be fair to Dennis, he believed me, and maybe that helped me get
hired.

-rob




Thu Sep 22 20:46:37 EDT 2022
From: Rob Pike <robpike@gmail.com>
Date: Wed, 21 Sep 2022 22:36:04 +1000
To: Warner Losh <imp@bsdimp.com>
Message-ID-Hash: B5MLR5IFZH6A3HQXKJXJBFCOOK2AMAMQ
CC: The Eunuchs Hysterical Society <tuhs@tuhs.org>
Subject: [TUHS] Re: Early BSD license thread
Archived-At:
<https://www.tuhs.org/mailman3/hyperkitty/list/tuhs@tuhs.org/message/B5MLR5IFZH6A3HQXKJXJBFCOOK2AMAMQ/>

It was a long time ago but it rankled at the time (and even came up in my
Bell Labs interview): that copyright notice replaced whatever was there
before.  Code written and copyrighted by other institutions was absorbed
into the Berkeley distribution and reattributed without credit.  Joy told me
later that the lawyers made them do it.  He was probably telling the truth,
but that didn't make it OK.

-rob


On Wed, Sep 21, 2022 at 8:12 PM Warner Losh <imp@bsdimp.com> wrote:

> I hate myself a little bit, but I posted an answer to the 'BSD license
> origin' in this twitter thread
> https://twitter.com/bsdimp/status/1572521676268802049
> that people might find interesting.
>
> Please note the caveats at the end of the thread: This is a bare outline
> hitting the high points taking only data from release files with no behind
> the scenes confirmation about why things changed, nor in-depth exploration
> of variations that I know are present, nor do I got into examples from
> various USENET postings from the time that stole the license for people's
> own different uses.
>
> Nonetheless, I hope it's useful...
>
> Warner
>




Thu Sep 22 19:19:05 EDT 2022
Hey, you're awesome!  Are you accepting volunteers?  I have a TON of experience
working with local businesses and building websites.  I've found that one of the
best ways to get to know people is by volunteering, so I'd like to donate my time
to you.  Please give me a call or text 929-209-5577.  Look forward to speaking
with you and showing you how I can help!  - Nick

Thu Sep 22 19:12:04 EDT 2022
Hello are you the owner of this business?
I was just on your website and I have a question about your business.




Thu Sep 22 19:01:20 EDT 2022
Hi,

Have you ever wondered how the big influencers on Instagram make so much money?
If the answer is "yes", then this eBook is exactly what you've been looking for.
We go over everything you need to know about gaining real followers and earning
real money.

With over 200 pages of strategies, growth methods and secrets - it's an Instagram
goldmine!  We have helped thousands of people to radically grow their profiles,
businesses and income.

Want to know more?  Visit: https://bit.ly/3c9M062

Regards,
Edmundo

Thu Sep 22 18:48:48 EDT 2022
A student from Australia earned $ 30,000,000 in 1.5 months
https://telegra.ph/Interesting-news-a-student-from-Australia-earned--30000000-in-15-months-09-22?news-id-819619

Thu Sep 22 10:53:29 EDT 2022
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GLES3/gl31.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <gbm.h>

static const char* sumShader =
	"#version 310 es\n"
	"precision lowp float;\n"
	"layout(local_size_x = %d) in;\n"
	"layout(std430) buffer;\n"
	"layout(binding = 0) buffer Input0\n"
	"{\n"
	" float elements[];\n"
	"} input_data0;\n"
	"layout(binding = 1) readonly buffer Input1\n"
	"{\n"
	" float elements[];\n"
	"} input_data1;\n"
	"layout(binding = 2) writeonly buffer Output\n"
	"{\n"
	" float elements[];\n"
	"} output_data;\n"
	"void main()\n"
	"{\n"
	" int idx = int(gl_LocalInvocationID.x);\n"
	" int i, j, k, l, m, n, o, p, q;\n"
	" m = %d;\n"
	" l = input_data0.elements.length();\n"
	" i = 0;\n"
	" while ((j = (i * m + idx)) < l) {\n"
	" input_data0.elements[j] = input_data0.elements[j] *
	input_data1.elements[j];\n"
	" i++;\n"
	" }\n"
	" barrier();\n"
	" j = 1;\n"
	" k = 2;\n"
	" while (j < l) {\n"
	" i = 0;\n"
	" p = idx * k;\n"
	" q = m * k;\n"
	" n = p;\n"
	" o = n + j;\n"
	" while (o < l) {\n"
	" input_data0.elements[n] = input_data0.elements[n] +
	input_data0.elements[o];\n"
	" i = i + q;\n"
	" n = i + p;\n"
	" o = n + j;\n"
	" }\n"
	" j = k;\n"
	" k = k * 2;\n"
	" barrier();\n"
	" }\n"
	" if (idx == 0)\n"
	" output_data.elements[0] = input_data0.elements[0];\n"
	"}\n";

int
main(int argc, char **argv) {
	float *A;
	float *B;
	float *C;
	float sum;
	int i, j, k;
	struct timeval now;
	double a, b;
	GLint status;
	GLint length;
	char *log;
	GLuint BO[3];
	float *data;
	char *sumShaderString;
	int threads;

	int32_t fd = open ("/dev/dri/renderD128", O_RDWR);
	if (fd <= 0)
		return -3;

	struct gbm_device *gbm = gbm_create_device (fd);
	if (gbm == NULL)
		return -4;

	EGLDisplay dpy = eglGetPlatformDisplay (EGL_PLATFORM_GBM_MESA, gbm, NULL);
	if (dpy == NULL)
		return -5;

	EGLBoolean returnValue = eglInitialize(dpy, NULL, NULL);
	if (returnValue != EGL_TRUE) {
		printf("eglInitialize failed\n");
		return 0;
	}

	EGLConfig cfg;
	EGLint count;
	EGLint s_configAttribs[] = {
		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
		EGL_NONE };
	if (eglChooseConfig(dpy, s_configAttribs, &cfg, 1, &count) == EGL_FALSE) {
		printf("eglChooseConfig failed\n");
		return 0;
	}

	EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
	EGLContext context = eglCreateContext(dpy, cfg, EGL_NO_CONTEXT,
	context_attribs);
	if (context == EGL_NO_CONTEXT) {
		printf("eglCreateContext failed\n");
		return 0;
	}
	returnValue = eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
	context);
	if (returnValue != EGL_TRUE) {
		printf("eglMakeCurrent failed returned %d\n", returnValue);
		return 0;
	}

	GLuint sumShaderID = glCreateShader(GL_COMPUTE_SHADER);
	if (sumShaderID == 0) {
		printf("glGetError %d\n", glGetError());
		return -2;
	}

	glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &threads);
	fprintf(stderr, "GL_MAX_COMPUTE_WORK_GROUP_SIZE: %d\n", threads);

	sumShaderString = malloc(strlen(sumShader) + 256);
	snprintf(sumShaderString, strlen(sumShader) + 256 - 1, sumShader, threads,
	threads);
	glShaderSource(sumShaderID, 1, (const char**)&sumShaderString, NULL);
	glCompileShader(sumShaderID);
	glGetShaderiv(sumShaderID, GL_COMPILE_STATUS, &status);
	if (status == GL_FALSE) {
		fprintf(stderr, "COMPUTE\n");
		glGetShaderiv(sumShaderID, GL_INFO_LOG_LENGTH, &length);
		log = malloc(length+1);
		glGetShaderInfoLog(sumShaderID, length, &length, log);
		write(2, log, length);
		return -1;
	}

	GLuint sumShaderProgram = glCreateProgram();
	glAttachShader(sumShaderProgram, sumShaderID);
	glLinkProgram(sumShaderProgram);
	glGetShaderiv(sumShaderID, GL_LINK_STATUS, &status);
	if (status == GL_FALSE) {
		fprintf(stderr, "LINK\n");
		glGetProgramiv(sumShaderID, GL_INFO_LOG_LENGTH, &length);
		log = malloc(length+1);
		glGetProgramInfoLog(sumShaderID, length, &length, log);
		write(2, log, length);
		return -1;
	}

	srand(time(NULL));

	for (i = 10; i < 50; i++) {
		j = i * 1000;

		A = malloc(j * sizeof(float));
		B = malloc(j * sizeof(float));
		C = malloc(1 * sizeof(float));

		for (k = 0; k < j; k++) {
			A[k] = 0.125; //((float)rand() / RAND_MAX) - 0.5;
			B[k] = 8.0; //((float)rand() / RAND_MAX) - 0.5;
		}

		sum = 0;

		gettimeofday(&now, NULL);
		a = now.tv_sec * 1000000;
		a += now.tv_usec;
		for (k = 0; k < j; k++)
			sum += A[k] * B[k];
		gettimeofday(&now, NULL);
		b = now.tv_sec * 1000000;
		b += now.tv_usec;

		printf("CPU: %f, %f microseconds\n", sum, b - a);

		gettimeofday(&now, NULL);
		a = now.tv_sec * 1000000;
		a += now.tv_usec;

		glGenBuffers(3, BO);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[0]);
		glBufferData(GL_SHADER_STORAGE_BUFFER, j * sizeof(GLfloat), A,
		GL_STATIC_DRAW);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, BO[0]);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[1]);
		glBufferData(GL_SHADER_STORAGE_BUFFER, j * sizeof(GLfloat), B,
		GL_STATIC_DRAW);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, BO[1]);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[2]);
		glBufferData(GL_SHADER_STORAGE_BUFFER, 1 * sizeof(GLfloat), C,
		GL_STATIC_DRAW);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, BO[2]);

		glUseProgram(sumShaderProgram);
		glDispatchCompute(1, 1, 1);
		glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[2]);
		float *out = (float*)glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0,
		1 * sizeof(float), GL_MAP_READ_BIT);
		sum = out[0];
		glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
		glDeleteProgram(sumShaderProgram);

		glDeleteBuffers(3, BO);

		gettimeofday(&now, NULL);
		b = now.tv_sec * 1000000;
		b += now.tv_usec;

		printf("GPU: %f, %f microseconds\n", sum, b - a);

		free(A);
		free(B);
		free(C);
	}

	return 0;
}




Thu Sep 22 02:02:44 EDT 2022
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GLES3/gl31.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <gbm.h>

static const char* sumShader =
	"#version 310 es\n"
	"layout(local_size_x = %d) in;\n"
	"layout(std430) buffer;\n"
	"layout(binding = 0) buffer Input0\n"
	"{\n"
	" float elements[];\n"
	"} input_data0;\n"
	"layout(binding = 1) readonly buffer Input1\n"
	"{\n"
	" float elements[];\n"
	"} input_data1;\n"
	"layout(binding = 2) writeonly buffer Output\n"
	"{\n"
	" float elements[];\n"
	"} output_data;\n"
	"void main()\n"
	"{\n"
	" int idx = int(gl_LocalInvocationID.x);\n"
	" int i, j, k, l, m, n, o, p, q;\n"
	" m = %d;\n"
	" l = input_data0.elements.length();\n"
	" i = 0;\n"
	" while ((j = (i * m + idx)) < l) {\n"
	" input_data0.elements[j] = input_data0.elements[j] *
	input_data1.elements[j];\n"
	" i++;\n"
	" }\n"
	" barrier();\n"
	" j = 1;\n"
	" k = 2;\n"
	" while (j < l) {\n"
	" i = 0;\n"
	" p = idx * k;\n"
	" q = m * k;\n"
	" n = p;\n"
	" o = n + j;\n"
	" while (o < l) {\n"
	" input_data0.elements[n] = input_data0.elements[n] +
	input_data0.elements[o];\n"
	" i = i + q;\n"
	" n = i + p;\n"
	" o = n + j;\n"
	" }\n"
	" j = k;\n"
	" k = k * 2;\n"
	" barrier();\n"
	" }\n"
	" if (idx == 0)\n"
	" output_data.elements[0] = input_data0.elements[0];\n"
	"}\n";

int
main(int argc, char **argv) {
	float *A;
	float *B;
	float *C;
	float sum;
	int i, j, k;
	struct timeval now;
	double a, b;
	GLint status;
	GLint length;
	char *log;
	GLuint BO[3];
	float *data;
	char *sumShaderString;
	int threads;

	int32_t fd = open ("/dev/dri/renderD128", O_RDWR);
	if (fd <= 0)
		return -3;

	struct gbm_device *gbm = gbm_create_device (fd);
	if (gbm == NULL)
		return -4;

	EGLDisplay dpy = eglGetPlatformDisplay (EGL_PLATFORM_GBM_MESA, gbm, NULL);
	if (dpy == NULL)
		return -5;

	EGLBoolean returnValue = eglInitialize(dpy, NULL, NULL);
	if (returnValue != EGL_TRUE) {
		printf("eglInitialize failed\n");
		return 0;
	}

	EGLConfig cfg;
	EGLint count;
	EGLint s_configAttribs[] = {
		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
		EGL_NONE };
	if (eglChooseConfig(dpy, s_configAttribs, &cfg, 1, &count) == EGL_FALSE) {
		printf("eglChooseConfig failed\n");
		return 0;
	}

	EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
	EGLContext context = eglCreateContext(dpy, cfg, EGL_NO_CONTEXT,
	context_attribs);
	if (context == EGL_NO_CONTEXT) {
		printf("eglCreateContext failed\n");
		return 0;
	}
	returnValue = eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
	context);
	if (returnValue != EGL_TRUE) {
		printf("eglMakeCurrent failed returned %d\n", returnValue);
		return 0;
	}

	GLuint sumShaderID = glCreateShader(GL_COMPUTE_SHADER);
	if (sumShaderID == 0) {
		printf("glGetError %d\n", glGetError());
		return -2;
	}

	glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &threads);
	fprintf(stderr, "GL_MAX_COMPUTE_WORK_GROUP_SIZE: %d\n", threads);

	sumShaderString = malloc(strlen(sumShader) + 256);
	snprintf(sumShaderString, strlen(sumShader) + 256 - 1, sumShader, threads,
	threads);
	glShaderSource(sumShaderID, 1, (const char**)&sumShaderString, NULL);
	glCompileShader(sumShaderID);
	glGetShaderiv(sumShaderID, GL_COMPILE_STATUS, &status);
	if (status == GL_FALSE) {
		fprintf(stderr, "COMPUTE\n");
		glGetShaderiv(sumShaderID, GL_INFO_LOG_LENGTH, &length);
		log = malloc(length+1);
		glGetShaderInfoLog(sumShaderID, length, &length, log);
		write(2, log, length);
		return -1;
	}

	GLuint sumShaderProgram = glCreateProgram();
	glAttachShader(sumShaderProgram, sumShaderID);
	glLinkProgram(sumShaderProgram);
	glGetShaderiv(sumShaderID, GL_LINK_STATUS, &status);
	if (status == GL_FALSE) {
		fprintf(stderr, "LINK\n");
		glGetProgramiv(sumShaderID, GL_INFO_LOG_LENGTH, &length);
		log = malloc(length+1);
		glGetProgramInfoLog(sumShaderID, length, &length, log);
		write(2, log, length);
		return -1;
	}

	srand(time(NULL));

	for (i = 10; i < 1000; i++) {
		j = i * 1000;

		A = malloc(j * sizeof(float));
		B = malloc(j * sizeof(float));
		C = malloc(1 * sizeof(float));

		for (k = 0; k < j; k++) {
			A[k] = 0.125; //((float)rand() / RAND_MAX) - 0.5;
			B[k] = 8.0; //((float)rand() / RAND_MAX) - 0.5;
		}

		sum = 0;

		gettimeofday(&now, NULL);
		a = now.tv_sec * 1000000;
		a += now.tv_usec;
		for (k = 0; k < j; k++)
			sum += A[k] * B[k];
		gettimeofday(&now, NULL);
		b = now.tv_sec * 1000000;
		b += now.tv_usec;

		printf("CPU: %f, %f microseconds\n", sum, b - a);

		gettimeofday(&now, NULL);
		a = now.tv_sec * 1000000;
		a += now.tv_usec;

		glGenBuffers(3, BO);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[0]);
		glBufferData(GL_SHADER_STORAGE_BUFFER, j * sizeof(GLfloat), A,
		GL_STATIC_DRAW);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, BO[0]);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[1]);
		glBufferData(GL_SHADER_STORAGE_BUFFER, j * sizeof(GLfloat), B,
		GL_STATIC_DRAW);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, BO[1]);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[2]);
		glBufferData(GL_SHADER_STORAGE_BUFFER, 1 * sizeof(GLfloat), C,
		GL_STATIC_DRAW);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, BO[2]);

		glUseProgram(sumShaderProgram);
		glDispatchCompute(1, 1, 1);
		glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[2]);
		float *out = (float*)glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0,
		1 * sizeof(float), GL_MAP_READ_BIT);
		sum = out[0];
		glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
		glDeleteProgram(sumShaderProgram);

		glDeleteBuffers(3, BO);

		gettimeofday(&now, NULL);
		b = now.tv_sec * 1000000;
		b += now.tv_usec;

		printf("GPU: %f, %f microseconds\n", sum, b - a);

		free(A);
		free(B);
		free(C);
	}

	return 0;
}




Wed Sep 21 17:51:58 EDT 2022
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GLES3/gl31.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <gbm.h>

static const char* sumShader =
	"#version 310 es\n"
	"layout(local_size_x = %d) in;\n"
	"layout(std430) buffer;\n"
	"layout(binding = 0) buffer Input0\n"
	"{\n"
	" float elements[];\n"
	"} input_data0;\n"
	"layout(binding = 1) readonly buffer Input1\n"
	"{\n"
	" float elements[];\n"
	"} input_data1;\n"
	"layout(binding = 2) writeonly buffer Output\n"
	"{\n"
	" float elements[];\n"
	"} output_data;\n"
	"void main()\n"
	"{\n"
	" int idx = int(gl_LocalInvocationID.x);\n"
	" int i, j, k, l, m, n, o;\n"
	" m = %d;\n"
	" l = input_data0.elements.length();\n"
	" i = 0;\n"
	" while ((j = (i * m + idx)) < l) {\n"
	" input_data0.elements[j] = input_data0.elements[j] *
	input_data1.elements[j];\n"
	" i++;\n"
	" }\n"
	" barrier();\n"
	" j = 1;\n"
	" k = 2;\n"
	" while (j < l) {\n"
	" i = 0;\n"
	" n = i + idx * k;\n"
	" o = n + j;\n"
	" while (o < l) {\n"
	" input_data0.elements[n] = input_data0.elements[n] +
	input_data0.elements[o];\n"
	" i = i + m * k;\n"
	" n = i + idx * k;\n"
	" o = n + j;\n"
	" }\n"
	" j = k;\n"
	" k = k * 2;\n"
	" barrier();\n"
	" }\n"
	" if (idx == 0)\n"
	" output_data.elements[0] = input_data0.elements[0];\n"
	"}\n";

int
main(int argc, char **argv) {
	float *A;
	float *B;
	float *C;
	float sum;
	int i, j, k;
	struct timeval now;
	double a, b;
	GLint status;
	GLint length;
	char *log;
	GLuint BO[3];
	float *data;
	char *sumShaderString;
	int threads;

	int32_t fd = open ("/dev/dri/renderD128", O_RDWR);
	if (fd <= 0)
		return -3;

	struct gbm_device *gbm = gbm_create_device (fd);
	if (gbm == NULL)
		return -4;

	EGLDisplay dpy = eglGetPlatformDisplay (EGL_PLATFORM_GBM_MESA, gbm, NULL);
	if (dpy == NULL)
		return -5;

	EGLBoolean returnValue = eglInitialize(dpy, NULL, NULL);
	if (returnValue != EGL_TRUE) {
		printf("eglInitialize failed\n");
		return 0;
	}

	EGLConfig cfg;
	EGLint count;
	EGLint s_configAttribs[] = {
		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
		EGL_NONE };
	if (eglChooseConfig(dpy, s_configAttribs, &cfg, 1, &count) == EGL_FALSE) {
		printf("eglChooseConfig failed\n");
		return 0;
	}

	EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
	EGLContext context = eglCreateContext(dpy, cfg, EGL_NO_CONTEXT,
	context_attribs);
	if (context == EGL_NO_CONTEXT) {
		printf("eglCreateContext failed\n");
		return 0;
	}
	returnValue = eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
	context);
	if (returnValue != EGL_TRUE) {
		printf("eglMakeCurrent failed returned %d\n", returnValue);
		return 0;
	}

	GLuint sumShaderID = glCreateShader(GL_COMPUTE_SHADER);
	if (sumShaderID == 0) {
		printf("glGetError %d\n", glGetError());
		return -2;
	}

	glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &threads);
	fprintf(stderr, "GL_MAX_COMPUTE_WORK_GROUP_SIZE: %d\n", threads);

	sumShaderString = malloc(strlen(sumShader) + 256);
	snprintf(sumShaderString, strlen(sumShader) + 256 - 1, sumShader, threads,
	threads);
	glShaderSource(sumShaderID, 1, (const char**)&sumShaderString, NULL);
	glCompileShader(sumShaderID);
	glGetShaderiv(sumShaderID, GL_COMPILE_STATUS, &status);
	if (status == GL_FALSE) {
		fprintf(stderr, "COMPUTE\n");
		glGetShaderiv(sumShaderID, GL_INFO_LOG_LENGTH, &length);
		log = malloc(length+1);
		glGetShaderInfoLog(sumShaderID, length, &length, log);
		write(2, log, length);
		return -1;
	}

	GLuint sumShaderProgram = glCreateProgram();
	glAttachShader(sumShaderProgram, sumShaderID);
	glLinkProgram(sumShaderProgram);
	glGetShaderiv(sumShaderID, GL_LINK_STATUS, &status);
	if (status == GL_FALSE) {
		fprintf(stderr, "LINK\n");
		glGetProgramiv(sumShaderID, GL_INFO_LOG_LENGTH, &length);
		log = malloc(length+1);
		glGetProgramInfoLog(sumShaderID, length, &length, log);
		write(2, log, length);
		return -1;
	}

	srand(time(NULL));

	for (i = 10; i < 11; i++) {
		j = i * 1000;

		A = malloc(j * sizeof(float));
		B = malloc(j * sizeof(float));
		C = malloc(1 * sizeof(float));

		for (k = 0; k < j; k++) {
			A[k] = ((float)rand() / RAND_MAX) - 0.5;
			B[k] = ((float)rand() / RAND_MAX) - 0.5;
		}

		sum = 0;

		gettimeofday(&now, NULL);
		a = now.tv_sec * 1000000;
		a += now.tv_usec;
		for (k = 0; k < j; k++)
			sum += A[k] * B[k];
		gettimeofday(&now, NULL);
		b = now.tv_sec * 1000000;
		b += now.tv_usec;

		printf("CPU: %f, %f microseconds\n", sum, b - a);

		gettimeofday(&now, NULL);
		a = now.tv_sec * 1000000;
		a += now.tv_usec;

		glGenBuffers(3, BO);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[0]);
		glBufferData(GL_SHADER_STORAGE_BUFFER, j * sizeof(GLfloat), A,
		GL_STATIC_DRAW);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, BO[0]);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[1]);
		glBufferData(GL_SHADER_STORAGE_BUFFER, j * sizeof(GLfloat), B,
		GL_STATIC_DRAW);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, BO[1]);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[2]);
		glBufferData(GL_SHADER_STORAGE_BUFFER, 1 * sizeof(GLfloat), C,
		GL_STATIC_DRAW);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, BO[2]);

		glUseProgram(sumShaderProgram);
		glDispatchCompute(1, 1, 1);
		glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);

		glBindBuffer(GL_SHADER_STORAGE_BUFFER, BO[2]);
		float *out = (float*)glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0,
		1 * sizeof(float), GL_MAP_READ_BIT);
		sum = out[0];
		glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
		glDeleteProgram(sumShaderProgram);

		glDeleteBuffers(3, BO);

		gettimeofday(&now, NULL);
		b = now.tv_sec * 1000000;
		b += now.tv_usec;

		printf("GPU: %f, %f microseconds\n", sum, b - a);

		free(A);
		free(B);
		free(C);
	}

	return 0;
}




prev | next