double daxpy(size_t N, size_t iterations = 1){ value_type* a = new value_type[N]; value_type* b = new value_type[N]; double c = 3; vinit(N, a); vinit(N, b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); for(size_t i = 0; i < N; ++i){ b[i] += a[i]*c; } auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } delete [] a; delete [] b; double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); // check to see if nothing happened during run to invalidate the times if(variance(tavg, times) > max_variance){ std::cerr << "clike kernel 'daxpy': Time deviation too large! \n"; } return tavg; }
/* initialise new fire particle */ static void setnewpart(firestruct * fs, part * p) { float a, vi[3], *c; p->age = 0; a = vrnd() * M_PI * 2.0; vinit(vi, sin(a) * fs->eject_r * vrnd(), 0.15, cos(a) * fs->eject_r * vrnd()); vinit(p->p[0], vi[0] + vrnd() * fs->ridtri, vi[1] + vrnd() * fs->ridtri, vi[2] + vrnd() * fs->ridtri); vinit(p->p[1], vi[0] + vrnd() * fs->ridtri, vi[1] + vrnd() * fs->ridtri, vi[2] + vrnd() * fs->ridtri); vinit(p->p[2], vi[0] + vrnd() * fs->ridtri, vi[1] + vrnd() * fs->ridtri, vi[2] + vrnd() * fs->ridtri); vinit(p->v, vi[0] * fs->eject_vl / (fs->eject_r / 2), vrnd() * fs->eject_vy + fs->eject_vy / 2, vi[2] * fs->eject_vl / (fs->eject_r / 2)); c = partcol1; vinit4(p->c[0], c[0] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), c[1] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), c[2] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), 1.0); vinit4(p->c[1], c[0] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), c[1] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), c[2] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), 1.0); vinit4(p->c[2], c[0] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), c[1] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), c[2] * ((1.0 - RIDCOL) + vrnd() * RIDCOL), 1.0); }
double gemv2(size_t N, size_t iterations = 1){ blaze::DynamicMatrix<value_type, blaze::rowMajor> A(N, N); blaze::DynamicVector<value_type, blaze::columnVector> a(N), b(N); value_type c = 3, d = 5; vinit(N, a); vinit(N, b); minit(N, A); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); b = c * blaze::trans(A) * a + d * b; auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); // check to see if anything happened during run to invalidate the times if(variance(tavg, times) > max_variance){ std::cerr << "blaze kernel 'gemv2': Time deviation too large! \n"; } return tavg; }
double vecvecadd(size_t N, size_t iterations = 1) { Eigen::VectorXd a(N), b(N), c(N); vinit(a.rows(), a); vinit(b.rows(), b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i) { auto start = std::chrono::steady_clock::now(); c = a + b; auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); // check to see if nothing happened during run to invalidate the times if(variance(tavg, times) > max_variance) { std::cerr << "eigen kernel 'vecvecadd': Time deviation too large! \n"; } return tavg; }
double dotproduct(size_t N, size_t iterations = 1){ blaze::DynamicVector<value_type> a(N), b(N); double c = 0; vinit(a.size(), a); vinit(b.size(), b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); c = (a, b); auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); // check to see if anything happened during run to invalidate the times if(variance(tavg, times) > max_variance){ std::cerr << "blaze kernel 'dotproduct': Time deviation too large! \n"; } return tavg; }
int mainCPU(int argc, char **argv) { amiSmallptCPU = 1; //fprintf(stderr, "Usage: %s\n", argv[0]); //fprintf(stderr, "Usage: %s <window width> <window height> <scene file>\n", argv[0]); /* if (argc == 4) { width = atoi(argv[1]); height = atoi(argv[2]); ReadScene(argv[3]); } else if (argc == 1) { */ spheres = CornellSpheres; sphereCount = sizeof(CornellSpheres) / sizeof(Sphere); vinit(camera.orig, 50.f, 45.f, 205.6f); vinit(camera.target, 50.f, 45 - 0.042612f, 204.6); /* } else exit(-1); */ UpdateCamera(); /*------------------------------------------------------------------------*/ AllocateBuffers(); /*------------------------------------------------------------------------*/ InitGlut(argc, argv, "SmallPT CPU V1.6 (Written by David Bucciarelli)"); glutMainLoop( ); return 0; }
static void setnewpart(part *p) { float a,v[3],*c; p->age=0; a=vrnd()*3.14159265359*2.0; vinit(v,sin(a)*eject_r*vrnd(),0.15,cos(a)*eject_r*vrnd()); vinit(p->p[0],v[0]+vrnd()*ridtri,v[1]+vrnd()*ridtri,v[2]+vrnd()*ridtri); vinit(p->p[1],v[0]+vrnd()*ridtri,v[1]+vrnd()*ridtri,v[2]+vrnd()*ridtri); vinit(p->p[2],v[0]+vrnd()*ridtri,v[1]+vrnd()*ridtri,v[2]+vrnd()*ridtri); vinit(p->v,v[0]*eject_vl/(eject_r/2),vrnd()*eject_vy+eject_vy/2,v[2]*eject_vl/(eject_r/2)); c=blu; vinit4(p->c[0],c[0]*((1.0-RIDCOL)+vrnd()*RIDCOL), c[1]*((1.0-RIDCOL)+vrnd()*RIDCOL), c[2]*((1.0-RIDCOL)+vrnd()*RIDCOL), 1.0); vinit4(p->c[1],c[0]*((1.0-RIDCOL)+vrnd()*RIDCOL), c[1]*((1.0-RIDCOL)+vrnd()*RIDCOL), c[2]*((1.0-RIDCOL)+vrnd()*RIDCOL), 1.0); vinit4(p->c[2],c[0]*((1.0-RIDCOL)+vrnd()*RIDCOL), c[1]*((1.0-RIDCOL)+vrnd()*RIDCOL), c[2]*((1.0-RIDCOL)+vrnd()*RIDCOL), 1.0); }
static Bool Init(ModeInfo * mi) { int i; firestruct *fs = &fire[MI_SCREEN(mi)]; /* default settings */ fs->eject_r = 0.1 + NRAND(10) * 0.03; fs->dt = 0.015; fs->eject_vy = 4; fs->eject_vl = 1; fs->ridtri = 0.1 + NRAND(10) * 0.005; fs->maxage = 1.0 / fs->dt; vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]); fs->v = 0.0; fs->alpha = DEF_ALPHA; fs->beta = DEF_BETA; /* initialise texture stuff */ if (do_texture) inittextures(mi); else { fs->ttexture = (XImage*) NULL; fs->gtexture = (XImage*) NULL; } if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n", MI_NAME(mi), fs->np, fs->num_trees, fs->fog ? "on" : "off", fs->shadows ? "on" : "off", fs->eject_r, fs->ridtri); } /* initialise particles and trees */ for (i = 0; i < fs->np; i++) { setnewpart(fs, &(fs->p[i])); } if (fs->num_trees) if (!inittree(mi)) { return False; } /* if no fire particles then initialise rain particles */ if (!fs->np) { vinit(fs->min,-7.0f,-0.2f,-7.0f); vinit(fs->max,7.0f,8.0f,7.0f); for (i = 0; i < NUMPART; i++) { setnewrain(fs, &(fs->r[i])); } } return True; }
// gcopnames creates opnames.h from go.h. // It finds the OXXX enum, pulls out all the constants // from OXXX to OEND, and writes a table mapping // op to string. void gcopnames(char *dir, char *file) { char *p, *q; int i, j, end; Buf in, b, out; Vec lines, fields; binit(&in); binit(&b); binit(&out); vinit(&lines); vinit(&fields); bwritestr(&out, bprintf(&b, "// auto generated by go tool dist\n")); bwritestr(&out, bprintf(&b, "static char *opnames[] = {\n")); readfile(&in, bprintf(&b, "%s/go.h", dir)); splitlines(&lines, bstr(&in)); i = 0; while(i<lines.len && !contains(lines.p[i], "OXXX")) i++; end = 0; for(; i<lines.len && !end; i++) { p = xstrstr(lines.p[i], "//"); if(p != nil) *p = '\0'; end = contains(lines.p[i], "OEND"); splitfields(&fields, lines.p[i]); for(j=0; j<fields.len; j++) { q = fields.p[j]; if(*q == 'O') q++; p = q+xstrlen(q)-1; if(*p == ',') *p = '\0'; bwritestr(&out, bprintf(&b, " [O%s] = \"%s\",\n", q, q)); } } bwritestr(&out, bprintf(&b, "};\n")); writefile(&out, file, 0); bfree(&in); bfree(&b); bfree(&out); vfree(&lines); vfree(&fields); }
double smatsvecmult(size_t N, size_t iterations = 1) { mtl::compressed2D<value_type> a(N, N); mtl::dense_vector<value_type> b(N), c(N); // sparse not fully implemented yet sminit(N, a); vinit(N, b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); c = a * b; auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); // check to see if nothing happened during run to invalidate the times if(variance(tavg, times) > max_variance){ std::cerr << "mtl kernel 'smatsvecmult': Time deviation too large! \n"; } return tavg; }
ENTRYPOINT void change_fire(ModeInfo * mi) { firestruct *fs = &fire[MI_SCREEN(mi)]; if (!fs->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(fs->glx_context)); /* if available, randomly change some values */ if (do_fog) fs->fog = LRAND() & 1; if (do_shadows) fs->shadows = LRAND() & 1; /* reset observer position */ frame = 0; vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]); fs->v = 0.0; /* particle randomisation */ fs->eject_r = 0.1 + NRAND(10) * 0.03; fs->ridtri = 0.1 + NRAND(10) * 0.005; if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n", MI_NAME(mi), fs->np, fs->num_trees, fs->fog ? "on" : "off", fs->shadows ? "on" : "off", fs->eject_r, fs->ridtri); } }
void vbgfx_set_res(vga_card* v, int64_t w, int64_t h, uint8_t bpp) { if(!v) return; if(!v->data[0]) return; if(w * h > 1440000) return; uint32_t iobase = v->data[0]; outw(iobase + VBGFX_IO_INDEX, VBGFX_INDEX_ENABLE); outw(iobase + VBGFX_IO_DATA, 0); //disable VBE extensions //write resolution outw(iobase + VBGFX_IO_INDEX, VBGFX_INDEX_XRES); outw(iobase + VBGFX_IO_DATA, w); outw(iobase + VBGFX_IO_INDEX, VBGFX_INDEX_YRES); outw(iobase + VBGFX_IO_DATA, h); //write bpp outw(iobase + VBGFX_IO_INDEX, VBGFX_INDEX_BPP); outw(iobase + VBGFX_IO_DATA, bpp); //reset video module vdestroy(); //enable VBE extensions and LFB outw(iobase + VBGFX_IO_INDEX, VBGFX_INDEX_ENABLE); outw(iobase + VBGFX_IO_DATA, 1 | 0x40); //init video module int64_t width, height, bppix; uint32_t lfb_addr = pci_config_read_dword(v->bus, v->slot, 0, 0x10) & ~0xF; outw(iobase + VBGFX_IO_INDEX, VBGFX_INDEX_XRES); width = inw(iobase + VBGFX_IO_DATA); outw(iobase + VBGFX_IO_INDEX, VBGFX_INDEX_YRES); height = inw(iobase + VBGFX_IO_DATA); outw(iobase + VBGFX_IO_INDEX, VBGFX_INDEX_BPP); bppix = inl(iobase + VBGFX_IO_DATA); vinit(width, height, bppix, w * 4, lfb_addr); }
void initBitlash(unsigned long baud) { #if defined(TINY_BUILD) beginSerial(9600); #else beginSerial(baud); #endif #if defined(ARM_BUILD) eeinit(); #endif initTaskList(); vinit(); displayBanner(); #if !defined(TINY_BUILD) // Run the script named "startup" if there is one strncpy_P(lbuf, getmsg(M_startup), STRVALLEN); // get the name "startup" in our cmd buf //if (findKey(lbuf) >= 0) doCommand(lbuf); // look it up. exists? call it. if (findscript(lbuf)) doCommand(lbuf); // look it up. exists? call it. #endif initlbuf(); }
double rmajordmvmult(size_t N, size_t iterations = 1){ Eigen::Matrix<value_type, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> A(N, N); Eigen::Matrix<value_type, Eigen::Dynamic, 1> b(N), c(N); minit(N, A); vinit(N, b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); c.noalias() = A * b; auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); // check to see if nothing happened during run to invalidate the times if(variance(tavg, times) > max_variance){ std::cerr << "eigen kernel 'rmajordmvmult': Time deviation too large! \n"; } return tavg; }
// xremoveall removes the file or directory tree rooted at p. void xremoveall(char *p) { int i; Buf b; Vec dir; binit(&b); vinit(&dir); if(isdir(p)) { xreaddir(&dir, p); for(i=0; i<dir.len; i++) { bprintf(&b, "%s/%s", p, dir.p[i]); xremoveall(bstr(&b)); } if(vflag > 2) xprintf("rm %s\n", p); rmdir(p); } else { if(vflag > 2) xprintf("rm %s\n", p); unlink(p); } bfree(&b); vfree(&dir); }
double dmatvecmult(size_t N, size_t iterations = 1) { boost::numeric::ublas::matrix<double> a(N, N); boost::numeric::ublas::vector<double> b(N), c(N); minit(a.size1(), a); vinit(b.size(), b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); boost::numeric::ublas::axpy_prod(a, b, c, false); auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); /* // check to see if nothing happened during rum to invalidate the times if(tmin*(1.0 + deviation*0.01) < tavg){ std::cerr << "uBLAS kernel 'dmatvecmult': Time deviation too large!!!" << std::endl; } */ return tavg; }
// vfree frees the storage associated with the vector. void vfree(Vec *v) { vreset(v); xfree(v->p); vinit(v); }
double cmajordmvmult(size_t N, size_t iterations = 1){ typedef mtl::tag::col_major col_major; typedef mtl::mat::parameters<col_major> parameters; typedef mtl::dense2D<value_type, parameters> dense2D; typedef mtl::dense_vector<value_type> dense_vector; dense2D A(N, N); dense_vector b(N), c(N); minit(N, A); vinit(N, b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); c = A * b; auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); // check to see if nothing happened during run to invalidate the times if(variance(tavg, times) > max_variance){ std::cerr << "mtl kernel 'cmajordmvmult': Time deviation too large! \n"; } return tavg; }
double vecvscalaradd(size_t N, size_t iterations = 1) { boost::numeric::ublas::vector<double> a(N), b(N); double c = 3; vinit(b.size(), b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); noalias(a) = b + boost::numeric::ublas::scalar_vector<double>(N, c); auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); /* // check to see if nothing happened during rum to invalidate the times if(tmin*(1.0 + deviation*0.01) < tavg){ std::cerr << "uBLAS kernel 'vecscalaradd': Time deviation too large!!!" << std::endl; } */ return tavg; }
double vecscalarmult(size_t N, size_t iterations = 1) { boost::numeric::ublas::vector<value_type> a(N), b(N); value_type c = 3; vinit(a.size(), a); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); noalias(a) = b * c; auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); // check to see if nothing happened during run to invalidate the times if(variance(tavg, times) > max_variance){ std::cerr << "boost kernel 'vecscalarmult': Time deviation too large! \n"; } return tavg; }
void amdrv100init(uint8_t bus, uint8_t slot) { printf("amd_rv100: init on bus:slot %x:%x\n", bus, slot); uint16_t vendor = pci_config_read_word(bus, slot, 0, 0); if(vendor == 0xFFFF) { puts("amd_rv100: init failed: device not found on specified bus:slot\n"); return; } uint16_t device = pci_config_read_word(bus, slot, 0, 2); if(device != 0x4c59) { puts("amd_rv100: init failed: device is not compatible\n"); return; } uint32_t fbaddr = pci_config_read_dword(bus, slot, 0, 0x10) & ~0xF; uint32_t port = pci_config_read_dword(bus, slot, 0, 0x14) & ~0x3; printf("amd_rv100: framebuffer addr: 0x%x port: 0x%x\n", fbaddr, port); vga_card* v = graphics_add_card(); if(!v) return; v->bus = bus; v->slot = slot; v->data[0] = fbaddr; v->data[1] = port; pci_config_write_byte(bus, slot, 0, 0x3d, 1); pci_config_write_byte(bus, slot, 0, 0x3c, 11); vdestroy(); vinit(1024, 768, 32, 1024 * 4, fbaddr); printf("amd_rv100: finished.\n"); }
///////// // // Parse and interpret a stream, and return its value // // This is used in doCommand to execute a passed-in or collected text command, // in domacrocommand() when a macro/function is called from within a parse stream, // and in runBackgroundTasks to kick off the background run. // // numvar execscript(byte scripttype, numvar scriptaddress, char *scriptname) { // save parse context parsepoint fetchmark; markparsepoint(&fetchmark); byte thesym = sym; vpush(symval); // if this is the first stream context in this invocation, // set up our error recovery point and init the value stack // otherwise we skip this to allow nested execution calls // to properly return to top // if (fetchtype == SCRIPT_NONE) { // Exceptions come here via longjmp; see bitlash-error.c switch(setjmp(env)) { case 0: break; case X_EXIT: { // POLICY: Stop all background tasks on any error // // It is not possible to be certain that continuing here will work. // Not all errors leave the interpreter in a working state. Though most do. // The conservative/deterministic choice is to stop all background tasks // and drop the user back to the command prompt. // // On the other hand, you may find this inconvenient in your application, // and may be happy taking the risk of continuing. // // In which case, comment out this line and proceed with caution. // // TODO: if the macro "onerror" exists, call it here instead. Let it "stop *". // // -br // initTaskList(); // stop all pending tasks #ifdef SOFTWARE_SERIAL_TX resetOutput(); // clean up print module #endif // Other cleanups here vinit(); // initialize the expression stack fetchtype = SCRIPT_NONE; // reset parse context fetchptr = 0L; // reset parse location // sd_up = 0; // TODO: reset file system return (numvar) -1; } // X_EXIT case } // switch } initparsepoint(scripttype, scriptaddress, scriptname); getsym(); // interpret the function text and collect its result numvar ret = getstatementlist(); returntoparsepoint(&fetchmark, 1); // now where were we? sym = thesym; symval = vpop(); return ret; }
/* calculate observer position : modified only if trackmouse is used */ static void calcposobs(firestruct * fs) { fs->dir[0] = sin(fs->alpha * M_PI / 180.0); fs->dir[2] = cos(fs->alpha * M_PI / 180.0) * sin(fs->beta * M_PI / 180.0); fs->dir[1] = cos(fs->beta * M_PI / 180.0); fs->obs[0] += fs->v * fs->dir[0]; fs->obs[1] += fs->v * fs->dir[1]; fs->obs[2] += fs->v * fs->dir[2]; if (!fs->np) { vinit(fs->min,fs->obs[0]-7.0f,-0.2f,fs->obs[2]-7.0f); vinit(fs->max,fs->obs[0]+7.0f,8.0f,fs->obs[2]+7.0f); } }
/* initialise new rain particle */ static void setnewrain(firestruct * fs, rain * r) { r->age=0.0f; vinit(r->acc,0.0f,-0.98f,0.0f); vinit(r->vel,0.0f,0.0f,0.0f); r->partLength=0.2f; vinit(r->oldpos,fs->min[0]+(fs->max[0]-fs->min[0])*vrnd(), fs->max[1]+0.2f*fs->max[1]*vrnd(), fs->min[2]+(fs->max[2]-fs->min[2])*vrnd()); vequ(r->pos,r->oldpos); vadds(r->oldpos,-(r->partLength),r->vel); r->pos[1]=(fs->max[1]-fs->min[1])*vrnd()+fs->min[1]; r->oldpos[1]=r->pos[1]-r->partLength*r->vel[1]; }
// Initialize "last" global variable for new command line and get first symbol. Return status. int parsebegin(Parse *newp,char *clp,int termch) { last = newp; last->p_clp = clp; last->p_termch = termch; last->p_sym = s_any; #if VDebug vinit(&last->p_tok,"parsebegin"); #else vinit(&last->p_tok); #endif last->p_vgarbp = vgarbp; #if MMDEBUG & DEBUG_VALUE fprintf(logfile,"parsebegin(): saved garbage pointer %.8x\n",(uint) vgarbp); #endif (void) getsym(); return rc.status; }
void UpdateRenderingCPU(void) { double startTime = WallClockTime(); const float invWidth = 1.f / width; const float invHeight = 1.f / height; int x, y; for (y = 0; y < height; y++) { /* Loop over image rows */ for (x = 0; x < width; x++) { /* Loop cols */ const int i = (height - y - 1) * width + x; const int i2 = 2 * i; const float r1 = GetRandom(&seeds[i2], &seeds[i2 + 1]) - .5f; const float r2 = GetRandom(&seeds[i2], &seeds[i2 + 1]) - .5f; const float kcx = (x + r1) * invWidth - .5f; const float kcy = (y + r2) * invHeight - .5f; Vec rdir; vinit(rdir, camera.x.x * kcx + camera.y.x * kcy + camera.dir.x, camera.x.y * kcx + camera.y.y * kcy + camera.dir.y, camera.x.z * kcx + camera.y.z * kcy + camera.dir.z); Vec rorig; vsmul(rorig, 0.1f, rdir); vadd(rorig, rorig, camera.orig) vnorm(rdir); const Ray ray = {rorig, rdir}; Vec r; RadiancePathTracing(spheres, sphereCount, &ray, &seeds[i2], &seeds[i2 + 1], &r); if (currentSample == 0) colors[i] = r; else { const float k1 = currentSample; const float k2 = 1.f / (k1 + 1.f); colors[i].x = (colors[i].x * k1 + r.x) * k2; colors[i].y = (colors[i].y * k1 + r.y) * k2; colors[i].z = (colors[i].z * k1 + r.z) * k2; } pixels[y * width + x] = toInt(colors[i].x) | (toInt(colors[i].y) << 8) | (toInt(colors[i].z) << 16); } } const float elapsedTime = WallClockTime() - startTime; const float sampleSec = height * width / elapsedTime; sprintf(captionBuffer, "Rendering time %.3f sec (pass %d) Sample/sec %.1fK\n", elapsedTime, currentSample, sampleSec / 1000.f); currentSample++; }
static void clean(void) { int i, j, k; Buf b, path; Vec dir; binit(&b); binit(&path); vinit(&dir); for(i=0; i<nelem(cleantab); i++) { if((streq(cleantab[i], "cmd/prof")) && !isdir(cleantab[i])) continue; bpathf(&path, "%s/src/%s", goroot, cleantab[i]); xreaddir(&dir, bstr(&path)); // Remove generated files. for(j=0; j<dir.len; j++) { for(k=0; k<nelem(gentab); k++) { if(hasprefix(dir.p[j], gentab[k].nameprefix)) xremove(bpathf(&b, "%s/%s", bstr(&path), dir.p[j])); } } // Remove generated binary named for directory. if(hasprefix(cleantab[i], "cmd/")) xremove(bpathf(&b, "%s/%s", bstr(&path), cleantab[i]+4)); } // remove src/pkg/runtime/z* unconditionally vreset(&dir); bpathf(&path, "%s/src/pkg/runtime", goroot); xreaddir(&dir, bstr(&path)); for(j=0; j<dir.len; j++) { if(hasprefix(dir.p[j], "z")) xremove(bpathf(&b, "%s/%s", bstr(&path), dir.p[j])); } if(rebuildall) { // Remove object tree. xremoveall(bpathf(&b, "%s/pkg/obj/%s_%s", goroot, gohostos, gohostarch)); // Remove installed packages and tools. xremoveall(bpathf(&b, "%s/pkg/%s_%s", goroot, gohostos, gohostarch)); xremoveall(bpathf(&b, "%s/pkg/%s_%s", goroot, goos, goarch)); xremoveall(tooldir); // Remove cached version info. xremove(bpathf(&b, "%s/VERSION.cache", goroot)); } bfree(&b); bfree(&path); vfree(&dir); }
double vecvecadd(size_t N, size_t iterations = 1){ double* a = new double[N]; double* b = new double[N]; double* c = new double[N]; vinit(N, a); vinit(N, b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); for(size_t i = 0; i < N; ++i){ c[i] = a[i] + b[i]; } auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } delete [] a; delete [] b; delete [] c; double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); /* // check to see if nothing happened during rum to invalidate the times if(tmin*(1.0 + deviation*0.01) < tavg){ std::cerr << "uBLAS kernel 'vecvecadd': Time deviation too large!!!" << std::endl; } */ return tavg; }
static void clean(void) { int i, j, k; Buf b, path; Vec dir; binit(&b); binit(&path); vinit(&dir); for(i=0; i<nelem(cleantab); i++) { bpathf(&path, "%s/src/%s", goroot, cleantab[i]); xreaddir(&dir, bstr(&path)); // Remove generated files. for(j=0; j<dir.len; j++) { for(k=0; k<nelem(gentab); k++) { if(hasprefix(dir.p[j], gentab[k].nameprefix)) xremove(bpathf(&b, "%s/%s", bstr(&path), dir.p[j])); } } // Remove generated binary named for directory. if(hasprefix(cleantab[i], "cmd/")) xremove(bpathf(&b, "%s/%s", bstr(&path), cleantab[i]+4)); } // remove src/runtime/zaexperiment.h and // except leave zgoos and zgoarch, now maintained with go generate. bpathf(&path, "%s/src/runtime", goroot); for(j=0; j<nelem(runtimegen); j++) xremove(bpathf(&b, "%s/%s", bstr(&path), runtimegen[j])); if(rebuildall) { // Remove object tree. xremoveall(bpathf(&b, "%s/pkg/obj/%s_%s", goroot, gohostos, gohostarch)); // Remove installed packages and tools. xremoveall(bpathf(&b, "%s/pkg/%s_%s", goroot, gohostos, gohostarch)); xremoveall(bpathf(&b, "%s/pkg/%s_%s", goroot, goos, goarch)); xremoveall(tooldir); // Remove cached version info. xremove(bpathf(&b, "%s/VERSION.cache", goroot)); } bfree(&b); bfree(&path); vfree(&dir); }
/* init1(): * This is the first level of initialization (aside from the most fundamental * stuff that must be done in reset.s) that is done after the system resets. */ void init1(void) { initCPUio(); /* Configure all chip-selects, parallel IO * direction registers, etc... This may have * been done already in reset.s */ vinit(); /* Initialize the CPU's vector table. */ InitRemoteIO(); /* Initialize all application-settable IO functions */ if(ConsoleBaudRate == 0) { ConsoleBaudRate = DEFAULT_BAUD_RATE; } devInit(ConsoleBaudRate); }