Example #1
0
// I have not tested this!!!! Be careful!
triad ygo_to_srgb(criad ygo)
{
    if(ygo.y >= 1.0)
        return triad({1,1,1});
    if(ygo.y <= 0)
        return triad({0,0,0});
    if(ygo.g == 0.5 and ygo.o == 0.5)
        return triad({ygo.y,ygo.y,ygo.y});
    
    // Constraints!
    // Y 0~1
    // C -0.5~0.5
    //: G > -Y
    //: G+O < Y
    //: G-O < Y
    //: G < 1-Y
    //: G+O > Y-1
    //: G-O > Y-1
    
    /* The [C -0.5~0.5] case is handled incidentally by the combination of all six other restrictions!
       This is an example of what it would look like. Only the code for the G channel.
    if (ygo.g < -0.5)
        project(ygo.g, ygo.o, -0.5, -0.5, -0.5, 0.5, ygo.g, ygo.o);
    if (ygo.g > -0.5)
        project(ygo.g, ygo.o, 0.5, 0.5, -0.5, 0.5, ygo.g, ygo.o);
    */
    
    if(ygo.g > -ygo.y)
        project(ygo.g, ygo.o, -ygo.y, -0.5, -ygo.y,    0.5, ygo.g, ygo.o);
    if(ygo.g+ygo.o < ygo.y)
        project(ygo.g, ygo.o,  ygo.y,    0,      0,  ygo.y, ygo.g, ygo.o);
    if(ygo.g-ygo.o < ygo.y)
        project(ygo.g, ygo.o,  ygo.y,    0,      0, -ygo.y, ygo.g, ygo.o);
    
    if(ygo.g < 1-ygo.y)
        project(ygo.g, ygo.o,  ygo.y, 0.5, ygo.y,   -0.5, ygo.g, ygo.o);
    if(ygo.g+ygo.o > ygo.y-1)
        project(ygo.g, ygo.o, -ygo.y,   0,     0, -ygo.y, ygo.g, ygo.o);
    if(ygo.g-ygo.o > ygo.y-1)
        project(ygo.g, ygo.o, -ygo.y,   0,     0,  ygo.y, ygo.g, ygo.o);
    
    triad rgb;
    rgb.r = ygo.y - ygo.g + ygo.o;
    rgb.g = ygo.y + ygo.g;
    rgb.b = ygo.y - ygo.g - ygo.o;
    return rgb;
}
Example #2
0
int main(int argc, char** argv)
{
    if(argc != 6) {
        printf("Usage: binary <size> <input1_file> <input2_file> <output_file> <coefficient>\n");
        return -1;
    }
    unsigned int size = atoi(argv[1]);
    float coef = atof(argv[5]);
    float* a = loadMatrix(argv[2], 1, size);
    float* b = loadMatrix(argv[3], 1, size);
    float* m = (float*) malloc (sizeof(float)*size);

    triad(m, a, b, coef, size);

    saveMatrix(argv[4], m, 1, size);
    free(a);
    free(b);
    free(m);
    systamp();
    return 0;
}
Example #3
0
 void runTests()
 {
    int  i;
    
    for (i=0; i<repeats; i++)
    {
       // calculations in CPU
       if (section == 1)
       {
          triad(words, aval, xval, x_cpu);
       }
       if (section == 2)
       {
          triadplus(words, aval, bval, cval, dval, eval, fval, x_cpu);
       }
       if (section == 3)
       {
          triadplus2(words, aval, bval, cval, dval, eval, fval, gval, hval, jval, kval, lval, mval, oval, pval, qval, rval, sval, tval, uval, vval, wval, yval,  x_cpu);
       }   
 
    }
 }
Example #4
0
int main(ull id, ull argp, ull envp)
{
	unsigned int cmd;

	mfc_get(&args, argp, sizeof(args), TAG, 0, 0);
	mfc_write_tag_mask(1 << TAG);
	mfc_read_tag_status_all();

	while (1) {
		cmd = spu_read_in_mbox();

		if (unlikely(SPU2_MSG_PPU_TO_SPU_EXIT == cmd))
			break;

		switch (cmd) {
		case SPU2_MSG_PPU_TO_SPU_DO_COPY:
			copy();
			break;
		case SPU2_MSG_PPU_TO_SPU_DO_SCALE:
			scale();
			break;
		case SPU2_MSG_PPU_TO_SPU_DO_ADD:
			add();
			break;
		case SPU2_MSG_PPU_TO_SPU_DO_TRIAD:
			triad();
			break;
		default:
			fprintf(stderr, " [SPU]: Invalid command received in mailbox\n");
		}

		spu_write_out_mbox(SPU2_MSG_SPU_TO_PPU_DONE);
	}

	return 0;
}
Example #5
0
void 
main(int argc, char ** argv)
{
	double *a, *b, *c, xx=0.01, bw, avg_bw, best_bw=-1.0;
	char * buf1, *buf2, *buf3;
	int i,j,k,offset_a=0,offset_b=0,offset_c=0, mult=1,iter=100, c_val;
	int len,mem_level, level_size[4], cpu, cpu_run, bytes_per,scale;
	unsigned long long start, stop, run_time, call_start, call_stop, call_run_time,total_bytes=0;
	__pid_t pid=0;
	int cpu_setsize;
	cpu_set_t mask;


//	process input arguments

	if(argc < 3 ){
		printf("triad driver needs at least 3 arguments, cpu_init, cpu_run, cache_level, [call count multiplier  def = 1], [offset a, offset_b, offset_c  defaults = 0] \n");
		printf(" argc = %d\n",argc);
		usage();
		err(1, "bad arguments");
		}


	len = L4;
        while ((c_val = getopt(argc, argv, "i:r:l:m:a:b:c")) != -1) {
                switch(c_val) {
                case 'i':
                        cpu = atoi(optarg);
                        break;
                case 'r':
                        cpu_run = atoi(optarg);
                        break;
                case 'l':
                        mem_level = atoi(optarg);
                        break;
                case 'm':
                        mult = atoi(optarg);
                        break;
                case 'a':
                        offset_a = atoi(optarg);
                        break;
                case 'b':
                        offset_b = atoi(optarg);
                        break;
                case 'c':
                        offset_c = atoi(optarg);
                        break;
                default:
                        err(1, "unknown option %c", c_val);
                }
        }
        iter = iter*mult;



// pin core affinity for initialization
        if(pin_cpu(pid, cpu) == -1) {
                err(1,"failed to set affinity");
                }
        else{
                fprintf(stderr," process pinned to core %d for initialization\n",cpu);
                }


// set buffer sizes and loop tripcounts based on memory level
	level_size[0]=L1;
	level_size[1]=L2;
	level_size[2]=L3;
	level_size[3]=L4;
	fprintf(stderr, "len = %d, mem_level = %d, iter = %d, mult = %d\n",len, mem_level, iter,mult);
	len = level_size[mem_level]/32;
	fprintf(stderr, "len = %d, mem_level = %d, iter = %d, mult = %d\n",len, mem_level, iter,mult);
	scale = level_size[3]/(32*len);
	fprintf(stderr, "len = %d, mem_level = %d, iter = %d, mult = %d, scale = %d\n",len, mem_level, iter,mult,scale);
	iter =iter*scale*mult;
	
	fprintf(stderr, "len = %d, mem_level = %d, iter = %d, mult = %d\n",len, mem_level, iter,mult);

// malloc and initialize buffers
	buf1 = malloc(sizeof(double)*len + 4096 + 1024);
	fprintf(stderr," buf1 = %p\n",buf1);
	buf1 = buf1 + (0x1000 - (unsigned int)buf1 & 0xFFF) + offset_a;
	fprintf(stderr," buf1 = %p\n",buf1);
	a = (double *) buf1;
	buf2 = malloc(sizeof(double)*len + 4096 + 1024);
	fprintf(stderr," buf2 = %p\n",buf2);
	buf2 = buf2 + (0x1000 - (unsigned int)buf2 & 0xFFF) + offset_b;
	fprintf(stderr," buf2 = %p\n",buf2);
	b = (double *) buf2;
	buf3 = malloc(sizeof(double)*len + 4096 + 1024);
	fprintf(stderr," buf3 = %p\n",buf3);
	buf3 = buf3 + (0x1000 - (unsigned int)buf3 & 0xFFF) + offset_c;
	fprintf(stderr," buf3 = %p\n",buf3);
	c = (double *) buf3;

	for(i=0;i<len;i++){
		a[i] = 0.;
		b[i] = 10.;
		c[i] = 10.;
		}

// pin core affinity for triad run
        if(pin_cpu(pid, cpu_run) == -1) {
                err(1,"failed to set affinity");
                }
        else{
                fprintf(stderr," process pinned to core %d for triad run\n",cpu_run);
                }

// run the triad
	printf(" calling triad %d times with len = %d\n",iter,len);
	call_start = _rdtsc();
	for(i=0;i<iter;i++){
		start = _rdtsc();
		bytes_per = triad(len,xx,a,b,c);
		stop = _rdtsc();
		run_time = stop - start;
		xx+=0.01;
		total_bytes +=len*bytes_per;
		bw=(double)(len*bytes_per)/(double)run_time;
		if(bw > best_bw) best_bw = bw;
		}
	call_stop = _rdtsc();
	call_run_time = call_stop - call_start;
	avg_bw=(double)(total_bytes)/(double)call_run_time;
//  printout
	printf(" transfering %lld bytes from memory level %d took %lld cycles/call and a total of %lld\n",total_bytes,mem_level,run_time,call_run_time);
	printf(" average bytes/cycle = %f\n", avg_bw);
	printf(" best bytes/cycle = %f\n",best_bw);
}
Example #6
0
 image()
 {
     width = 1;
     height = 1;
     data = {triad()};
 }
Example #7
0
 triad operator*(float f)
 {
     return triad(r*f, g*f, b*f);
 }
Example #8
0
 triad operator+(triad o)
 {
     return triad(r+o.r, g+o.g, b+o.b);
 }
Example #9
0
void terrainManager::generateGraphMesh(bool all)
{
    vector<glm::vec3> marked;
    vector<int> indices;
    vector<int> group;
    vector<glm::vec2> explored = vector<glm::vec2> ();
    queue<glm::vec2> que;
    vector<glm::vec2> inque = vector<glm::vec2>();
    vector<vector<vector<bool>>> activeness;
    // figure out whos the largest
    // use this first element as the precursor to generate the mesh
    int index = -1;
    float largest = -199999;
    for(int i =0; i < terrains.size(); i++)
    {
        float val = abs(terrains[i].getWidth() * terrains[i].getHeight() * terrains[i].getXRes() * terrains[i].getYRes());
        if( val > largest)
        {
            largest = val;
            cout << terrains[i].getXRes() << terrains[i].getYRes()<< endl;
            index = i;
        }
        cout << terrains[i].getXRes() << " " << terrains[i].getStartX() << " " << terrains[i].getHeight() << " " << terrains[i].getWidth() << endl;
    }
    auto first = terrains[index].getWorldPoint(0,0);
    // range variables
    int upperi,upperj,loweri,lowerj;
    vector<vector<float>> vects2;
    int other;
    for(int i = 0; i < terrains.size(); i++)
    {
        if(i != index)
        {
            float k,l;
            vects2 = terrains[i].getData();
            terrains[index].getNearestIndex(terrains[i].getWorldPoint(terrains[i].getWidth()-1,terrains[i].getHeight()-1),k,l);
            upperj = floor(k);
            upperi = floor(l);
            terrains[index].getNearestIndex(terrains[i].getWorldPoint(0,0),k,l);
            loweri = floor(l);
            lowerj = floor(k);
            cout << "INDEX" << k << " " << l << endl;
            other = i;
        }
    }

    // Now to triangulate the two meshes --- for now
    vector<Point> vect;
    auto vects = terrains[index].getData();
    for(int i = 0; i < terrains[index].getWidth(); i++)
    {

        for (int j = 0; j < terrains[index].getHeight();j++)
        {
            // check if there are between indexes
            if ( i <= upperi && i > loweri && j <= upperj && j > lowerj)
            {
                // Iterate through other mesh
                int ci = i;
                int cip = i+1;
                float t,s;
                float v;
                vector<int> ranges = {};
                // Find the indexs to use
                terrains[other].getNearestIndex(terrains[index].getWorldPoint(i,j),t,s);

                for(int k = 0; k < terrains[other].getHeight(); k++ )
                {
                    terrains[other].getNearestIndex(terrains[index].getWorldPoint(i,j),t,s);
                    
                    //if(t < cip && t >= ci )
                    //{
                    cout << s << endl;
                    //exit(0);
                    glm::vec2 p = terrains[other].getWorldPoint(i,j);
                    Point p2 = Point(p.x,p.y);
                    vect.push_back(p2);
                    terrains[other].setactive(k,s,true);
                    terrains[index].getNearestIndex(terrains[other].getWorldPoint(s,k),t,s);
                    terrains[index].setactive(t,terrains[index].getWidth() - s,false);
                    //}
                }
                j = ceil(upperj);
            }
            else
            {
                //vects.push_back(terrains[index].getWorldPoint(j,i));
                glm::vec2 p = terrains[index].getWorldPoint(i,j);
                Point p2 = Point(p.x,p.y);
                vect.push_back(p2);
            }
        }


    }
    triad(vect);
}