#ifndef __GPUINITWIRES_CU__ #define __GPUINITWIRES_CU__ #include #include #include #include #include using namespace std; #include #include "cutil_math.h" #include "GPUWire.h" //------------------- // GPUInitWires //------------------- void GPUInitWires(string fname="gluex_wires.txt") { /// This defines the wire geometry. It does so by reading /// the wire parameters in from a text file whose name /// is given by the only argument to this function. The /// wire definitions are written into an array in device /// constant memory using the global symbol "wires_d" /// which is defined in GPUWire.h. // Open wire definitions file ifstream file(fname.c_str()); if(!file.is_open()){ cout << "Unable to open file \"" << fname << "\"!" << endl; exit(-1); } cout << "Reading " << fname << " ..." << endl; // Read in wire definitions int lineno=0; vector wires; // temporary container used to hold wire definitions while(!file.eof()){ char line[256]; file.getline(line, 256); lineno++; // keep track of line number in case we need to report error if(line[0] == '#') continue; // skip comment lines // Read in wire info Wire w; // temporary variable int N = sscanf(line, "%d %f %f %f %f %f %f %f", &w.id, &w.L, &w.x, &w.y, &w.z, &w.i, &w.j, &w.k); if(N == 0) continue; // skip empty lines if(N < 8 && !file.eof()){ cout << "Error in file \"" << fname << "\" at line " << lineno << endl; cout << "Could not find 8 valid numbers! Exiting now." << endl; exit(-1); } // Copy wire parameters into float3 variables w.origin = make_float3(w.x, w.y, w.z); w.udir = normalize(make_float3(w.i, w.j, w.k)); // not sure if the following is correct ??? w.sdir = normalize(cross(w.origin, w.udir)); w.tdir = cross(w.udir, w.sdir); wires.push_back(w); } file.close(); cout << "Found " << wires.size() << " wires" << endl; // We use device constant memory for increased access speed at run time // which requires that the memory be pre-allocated for a fixed number of // wires using a value known at compile time. Check here that the number // of wires read is not more than we preallocated for. if(wires.size() > MAX_WIRES){ cout << "FATAL: The number of wires found in the wire definitions file" << endl; cout << " is greater than number allocated at compile time (" << MAX_WIRES << ")." << endl; cout << " You must edit GPUWire.h and recompile in order to use" <=MAX_WIRES){ cerr << "ERROR: idx=" << idx << " is out of range! It should" << endl; cerr << " be from 0-" << MAX_WIRES << endl; a.id = 0; a.L = a.x = a.y = a.z = a.i = a.j = a.k = 0.0; return; } cudaMemcpyFromSymbol(&a, wires_d, sizeof(Wire), idx*sizeof(Wire)); } //------------------- // PrintWire //------------------- void PrintWire(Wire *tempH) { /// This is for debugging. The tempH pointer should point /// to a Wire object in the host memory. printf("%d\n", tempH->id); printf("%f\n", tempH->x); printf("%f\n", tempH->y); printf("%f\n", tempH->z); printf("%f\n", tempH->i); printf("%f\n", tempH->j); printf("%f\n", tempH->k); printf("%f\n\n", tempH->L); //printf("0x%x\n", tempH->ptr); } #endif // __GPUINITWIRES_CU__