/** * Initialization of CUDA and GLFW. */ bool init(int argc, char **argv) { // Set window title to "Student Name: [SM 2.0] GPU Name" std::string deviceName; cudaDeviceProp deviceProp; int gpuDevice = 0; int device_count = 0; cudaGetDeviceCount(&device_count); if (gpuDevice > device_count) { std::cout << "Error: GPU device number is greater than the number of devices!" << "Perhaps a CUDA-capable GPU is not installed?" << std::endl; return false; } cudaGetDeviceProperties(&deviceProp, gpuDevice); m_major = deviceProp.major; m_minor = deviceProp.minor; std::ostringstream ss; ss << m_yourName << ": [SM " << m_major << "." << m_minor << "] " << deviceProp.name; deviceName = ss.str(); // Window setup stuff glfwSetErrorCallback(errorCallback); if (!glfwInit()) { return false; } m_width = 800; m_height = 800; m_window = glfwCreateWindow(m_width, m_height, deviceName.c_str(), NULL, NULL); if (!m_window) { glfwTerminate(); return false; } glfwMakeContextCurrent(m_window); glfwSetKeyCallback(m_window, keyCallback); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) { return false; } // init all of the things initVAO(); initTextures(); initCUDA(); initPBO(&m_pbo); GLuint passthroughProgram; passthroughProgram = initShader(); glUseProgram(passthroughProgram); glActiveTexture(GL_TEXTURE0); return true; }
int main(int argc, char *argv[]) { int retValue; QApplication app(argc, argv); initCUDA(argc, argv); // Set up and show widgets. MainWindow window; window.show(); retValue = app.exec(); exitCUDA(argc, argv); return retValue; }
int main(int argc, char** argv) { printHeader("Initializare"); initCUDA(); init(); printHeader("Calcul CPU"); cutilCheckError(cutStartTimer(timer)); // Calculeaza sampleul de control - CPU printf("Asteptati: Se calculeaza controlul pe CPU ... "); computeControl(); printf("DONE\n"); float time = cutGetTimerValue(timer); printf("Timp de calcul pe CPU = %f milisecunde\n",time); cutilCheckError(cutResetTimer(timer)); printHeader("Calcul CUDA"); // Se calculeaza pe CUDA printf("Asteptati: Se calculeaza pe CUDA ... "); runCUDA(); printf("DONE\n"); time = cutGetTimerValue(timer); printf("Timp de calcul pe GPU = %f milisecunde\n",time); printHeader("Verificare calcule"); // Se verifica daca s-a calculat corect pe CUDA printf("Se verifica daca rezultatul pe CUDA corespunde cu rezultatul pe CPU : "); verificaCalcule(); printHeader(""); cleanup(); printf("Apasa ENTER pentru a termina programul\n"); getchar(); return 0; }
int main(int argc, char** argv) { initApplication( argc, argv ); //initGL( argc, argv ); initGLUT( argc, argv ); GLenum err = glewInit(); if (err || !glewIsSupported("GL_VERSION_2_0 GL_ARB_pixel_buffer_object")) { fprintf(stderr, "Required OpenGL extensions missing."); exit(-1); } else { initCUDA( argc, argv ); initObservationSpace(); // init the pbo dispResp->createPBO(); // Create pixel buffer object // init result device memory //createResMem(); atexit(cleanUpAtExit); // printHelpMenu(); // start glut main loop glutMainLoop(); } return 0; }
int main(int argc, char** argv) { glutInit(&argc, argv); //change mode here. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize(w_width, w_height); glutCreateWindow("GPU Path Tracer");//GPU Photon Mapping if(CUTFalse == initGL()) return 0; if(CUTFalse == initCUDA(argc, argv)) return 0; //call self defined init function initCUDAMemory(); //create scene / world here. createWorld(); //upload world scene to device. uploadToGPU(); //Event glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keypress); glutIdleFunc(display); srand(time(NULL)); glutMainLoop(); return 0; }
int main0 (int argc, char * const argv[]) { int elev = 0; int azim = 90; char ear = 'L'; int whrtfLength; initCUDA(); /* INIT_VARIABLES; INIT_RUNTIME; float* whr = whrtf(elev, azim, ear, &whrtfLength); END_RUNTIME; printf("\n[whrtf]: "); PRINT_RUNTIME; cudaDeviceReset(); if (0) { for (int i = 0; i < whrtfLength; i=i+3) { printf("\nColunas %d a %d \n", i, i+2); printf("%1.15f, %1.15f, %1.15f\n", whr[i], whr[i+1], whr[i+2]); } }*/ // OK - REVISADO ATÉ AQUI - 24/05/2011 // Implementação com threads struct whrtf_parameters *param1, *param2; param1 = (struct whrtf_parameters *) malloc(sizeof(struct whrtf_parameters)); param2 = (struct whrtf_parameters *) malloc(sizeof(struct whrtf_parameters)); param1->tid = 0; param1->elev = 0; param1->azim = 90; param1->ear = 'L'; param2->tid = 1; param2->elev = 0; param2->azim = 95; param2->ear = 'L'; int numThreads = 2; int rc[numThreads]; pthread_t thread1, thread2, thread3, thread4; pthread_t threads[numThreads]; INIT_VARIABLES; INIT_RUNTIME; for (int i = 0; i < numThreads; i++) { if (i % 2 == 0) { rc[i] = pthread_create(&threads[i], NULL, whrtfMain, (void *) param1); } else { rc[i] = pthread_create(&threads[i], NULL, whrtfMain, (void *) param2); } } for (int i = 0; i < numThreads; i++) { pthread_join( threads[i], NULL); } /*pthread_join( thread1, NULL); pthread_join( thread2, NULL); pthread_join( thread3, NULL); pthread_join( thread4, NULL);*/ END_RUNTIME; printf("\n[%d threads]: ", numThreads); PRINT_RUNTIME; cudaDeviceReset(); //printf("Thread 1 returns: %d\n", rc1); //printf("Thread 2 returns: %d\n", rc2); //printf("Thread 3 returns: %d\n", rc3); //printf("Thread 4 returns: %d\n", rc4); //exit(0); }
int main (int argc, char * const argv[]) { int elev = 0; int azim = 1; char ear = 'L'; double** Gl = NULL; int* Gl_size = NULL; double** Gr = NULL; int* Gr_size = NULL; if (elev > 90) { elev = elev - (2 * (elev - 90)); } initCUDA(); INIT_VARIABLES; INIT_RUNTIME; //for (azim = 0; azim < 1; azim++) { int flipAzim = 360 - azim; if (flipAzim == 360) { flipAzim = 0; } int whrtfLengthL, whrtfLengthR; Gl_size = (int*) calloc((NUM_FILTROS+1), sizeof(int)); Gl = getSparseCoefficients(elev, azim, ear, Gl_size); float* whrtfL = getRespImp(NUM_FILTROS, Gl, Gl_size, &whrtfLengthL); Gr_size = (int*) calloc((NUM_FILTROS+1), sizeof(int)); Gr = getSparseCoefficients(elev, flipAzim, ear, Gr_size); float* whrtfR = getRespImp(NUM_FILTROS, Gr, Gr_size, &whrtfLengthR); END_RUNTIME; printf("\n[2 whrtfs]: "); PRINT_RUNTIME; if (1) { for (int i = 0; i < 3; i=i+3) { //printf("\nColunas %d a %d \n", i, i+2); printf("%1.15f, %1.15f, %1.15f\n", whrtfL[i], whrtfL[i+1], whrtfL[i+2]); } } free(Gl); free(Gr); free(Gl_size); free(Gr_size); free(whrtfL); free(whrtfR); Gl = NULL; Gr = NULL; Gl_size = NULL; Gr_size = NULL; whrtfL = NULL; whrtfR = NULL; //} // TODO implementar calc_delta int atrasos[5] = {1, 1, 8, 22, 50}; }
int main() { initCUDA(0); // tensor<float, MEMORY> mean(extents[N_CLASSES][N_DIM]); // mean[0] = 2.f; // mean[1] = 1.f; // mean[2] = 5.f; // mean[3] = 1.f; // // mean[4] = 2.f; // // mean[5] = 4.f; // // mean[6] = 5.f; // // mean[7] = 4.f; // // // tensor<float, MEMORY> covariance(extents[N_CLASSES][N_DIM][N_DIM]); // covariance(0, 0, 0) = 1.f; // covariance(0, 1, 1) = 1.f; // covariance(0, 1, 0) = 0.f; // covariance(0, 0, 1) = 0.f; // covariance(1, 0, 0) = 1.f; // covariance(1, 1, 1) = 1.f; // covariance(1, 1, 0) = 0.f; // covariance(1, 0, 1) = 0.f; // // covariance(2, 0, 0) = 1.f; // // covariance(2, 1, 1) = 1.f; // // covariance(2, 1, 0) = 0.f; // // covariance(2, 0, 1) = 0.f; // // covariance(3, 0, 0) = 1.f; // // covariance(3, 1, 1) = 1.f; // // covariance(3, 1, 0) = 0.f; // // covariance(3, 0, 1) = 0.f; vector<float> l_rate; vector<float> r_rate; for (int i = 1; i <= 1000000; i *= 10) { l_rate.push_back(1.0/i); r_rate.push_back(1.0/i); cout<<1.0/i<<endl; } MnistDataSet<MEMORY> mnist(784, 60000, 10000, 5); // GaussianDataSet<MEMORY> train(N_DIM, 300, N_CLASSES, covariance, mean); // GaussianDataSet<MEMORY> test(N_DIM, 2000, N_CLASSES, covariance, mean); // train.printToScreen(); // train.printToFile("./Results/train.dat"); // LogisticRegression<MEMORY> logReg(0.01, 0, N_ITERATIONS, N_CLASSES, N_DIM); // logReg.fit(train.getData(), train.getLabels()); LogRegFactory<MEMORY>* m; m = new LogRegFactory<MEMORY>(); CrossValidator<MEMORY> c(l_rate, r_rate, N_CLASSES, N_ITERATIONS, 10, m); c.fit(mnist.getData(), mnist.getLabels()); cout<<"ERRORS TEST DATA: "<<c.predictWithError(mnist.getX_test(), mnist.getY_test()); c.printBestModel(); return 0; }