Skip to content

Instantly share code, notes, and snippets.

View chadbrewbaker's full-sized avatar

Chad Brewbaker chadbrewbaker

View GitHub Profile
//Simple STL suffix array example
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int myints[] = {0,1,0,1,0,1,0,1};
int lu[] = {0,1,2,3,4,5,6,7};
int MY_STRING_LENGTH = 8;
@chadbrewbaker
chadbrewbaker / gist:1074578
Created July 10, 2011 14:20
Simple STL suffix array example v2
//Simple STL suffix array example
/*
crb002$ ./a.out
inv suffix array: 7 6 0 4 1 5 3 2
suffix array: 2 4 7 6 3 5 1 0
source: 0 0 1 1 0 1 0 0
The sort took 29 comparison operations.
*/
#include <iostream>
@chadbrewbaker
chadbrewbaker / gcc_goto_issue.cpp
Created July 23, 2011 06:20
Bug in GCC goto parsing or the C99 standard?
#define N 100
int perm[N];
void gcc_goto_issue(){
int i,start, current;
for(i=0;i<N;i++){
start = perm[i];
current = perm[start];
@chadbrewbaker
chadbrewbaker / gist:1101684
Created July 23, 2011 17:52
Cycle sizes of a pseudorandom permutation
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
long TEST_SIZE = 10000000;
//PRNG code from http://bedaux.net/mtrand/
class MTRand_int32 { // Mersenne Twister random number generator
@chadbrewbaker
chadbrewbaker / heap2stack.cpp
Created July 24, 2011 01:37
Compare memory transfer speeds between the stack and the heap.
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
long TEST_SIZE = 500000;
long SAMPLES = 60000;
void my_copy(uint64_t* a, uint64_t* b, long n){
memcpy(b, a, n*sizeof(uint64_t));
}
@chadbrewbaker
chadbrewbaker / timetest.cpp
Created July 25, 2011 01:50
Timer resolution and average behavior test
/*
timetest.cpp
A simple program to demonstrate the difference in timers on your platform.
Tue Dec 21 15:11:06 CST 2010
Chad Brewbaker
crb002@gmail.com
*/
@chadbrewbaker
chadbrewbaker / radix_histo.cpp
Created August 2, 2011 05:32
Simple radix histogram
//Simple radix histogram
//
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#define HIST_SIZE 2048
@chadbrewbaker
chadbrewbaker / radix32_11.cpp
Created August 3, 2011 05:18
32 bit 11 radix histogram
//Simple radix histogram
//
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#define HIST_SIZE 2048
@chadbrewbaker
chadbrewbaker / helloCL.html
Created September 1, 2011 20:26
Hellow world in WebCL
<input type="button" onclick="detectCL()" value="Run Lesson 1">
<script type="text/javascript">
function detectCL() {
// First check if the WebCL extension is installed at all
if (window.WebCL == undefined) {
alert("Unfortunately your system does not support WebCL. " +
"Make sure that you have both the OpenCL driver " +
"and the WebCL browser extension installed.");
return false;
}
@chadbrewbaker
chadbrewbaker / cltest.html
Created October 3, 2011 21:57
Simple WebCL benchmark on an array using the JavaScript timer
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Learning WebCL, lesson 3</title>
<meta name="keywords" content="webcl, webgl, gpu, opencl, opengl" />
<meta name="description" content="WebCL extension for Firefox, providing direct GPU access from JavaScript" />
<link href="/default.css" rel="stylesheet" type="text/css" />
</head>