void runAutoTest(int argc, char **argv) { printf("[%s] (automated testing w/ readback)\n", sSDKsample); if( cutCheckCmdLineFlag(argc, (const char**)argv, "device") ) { cutilDeviceInit(argc, argv); } else { cudaSetDevice( cutGetMaxGflopsDeviceId() ); } loadDefaultImage( argv[0] ); if (argc > 1) { char *filename; if (cutGetCmdLineArgumentstr(argc, (const char **)argv, "file", &filename)) { initializeData(filename); } } else { loadDefaultImage( argv[0]); } g_CheckRender = new CheckBackBuffer(imWidth, imHeight, sizeof(Pixel), false); g_CheckRender->setExecPath(argv[0]); Pixel *d_result; cutilSafeCall( cudaMalloc( (void **)&d_result, imWidth*imHeight*sizeof(Pixel)) ); while (g_SobelDisplayMode <= 2) { printf("AutoTest: %s <%s>\n", sSDKsample, filterMode[g_SobelDisplayMode]); sobelFilter(d_result, imWidth, imHeight, g_SobelDisplayMode, imageScale ); cutilSafeCall( cudaThreadSynchronize() ); cudaMemcpy(g_CheckRender->imageData(), d_result, imWidth*imHeight*sizeof(Pixel), cudaMemcpyDeviceToHost); g_CheckRender->savePGM(sOriginal[g_Index], false, NULL); if (!g_CheckRender->PGMvsPGM(sOriginal[g_Index], sReference[g_Index], MAX_EPSILON_ERROR, 0.15f)) { g_TotalErrors++; } g_Index++; g_SobelDisplayMode = (SobelDisplayMode)g_Index; } cutilSafeCall( cudaFree( d_result ) ); delete g_CheckRender; if (!g_TotalErrors) printf("TEST PASSED!\n"); else printf("TEST FAILED!\n"); }
int main(int argc, char *argv[]) { char *fnameOut = "data/lena_filtered_gpu_lp.pgm"; // Output image unsigned char *h_pImgResult = NULL; // Output handle Complex *h_pTwiddleDFT = NULL; // Host DFT Twiddle Matrix Complex *h_pTwiddleIDFT = NULL; // Host IDFT Twiddle Matrix double complex *h_pTwiddleDFT_z = NULL; // Host CPU DFT Twiddle Matrix double complex *h_pTwiddleIDFT_z = NULL; // Host CPU IDFT Twiddle Matrix float *h_pFilterCoeffs = NULL; // Host Filter Coefficent Matrix static const int dev = 0; // Hard code to use device 0 cudaEvent_t start, stop; // Cuda events for benchmarking float time; // Performance timer for benchmarking std::string filterOption ("lowpass"); // Cmd line filter option // Load the image loadDefaultImage( argv[0] ); // Capture image reference unsigned char *m_imgRef = h_pImage; std::cout << "Image width = " << imWidth << " and image height = " << imHeight << std::endl; // Define number of threads and blocks to be mapped to the GPU dim3 nThreads = dim3( blkSize_x, blkSize_y, 1 ); dim3 nBlocks = dim3( ceil( imWidth / nThreads.x ), ceil( imHeight / nThreads.y ) ); int nPixels = imWidth * imHeight; unsigned int imSz = sizeof( unsigned char ) * nPixels; // Allocate host memory for the result h_pImgResult = static_cast<unsigned char*>( malloc( imSz ) ); unsigned char *m_imgOut = h_pImgResult; // Generate the DFT and IDFT twiddle matrix to be dumped to the GPU // and for CPU reference implementation unsigned int twiddleSz = sizeof( Complex ) * nPixels; unsigned int twiddleSz_z = sizeof( double complex ) * nPixels; h_pTwiddleDFT = static_cast<Complex*>( malloc( twiddleSz ) ); h_pTwiddleDFT_z = static_cast<double complex*>( malloc( twiddleSz_z ) ); twiddleMatrixGen( false, h_pTwiddleDFT, h_pTwiddleDFT_z ); h_pTwiddleIDFT = static_cast<Complex*>( malloc ( twiddleSz ) ); h_pTwiddleIDFT_z = static_cast<double complex*>( malloc( twiddleSz_z ) ); twiddleMatrixGen( true, h_pTwiddleIDFT, h_pTwiddleIDFT_z ); // Allocate and generate the Filter Coefficient Matrix unsigned int filterSz = sizeof( float ) * nPixels; h_pFilterCoeffs = static_cast<float*>( malloc( filterSz ) ); if ( filterOption == "lowpass" ) filterCoeffGen( true, W_C, h_pFilterCoeffs ); else filterCoeffGen( false, W_C, h_pFilterCoeffs ); // Initialize the result buffer for ( int i = 0; i < nPixels; ++i ) h_pImgResult[i] = 0; // Allocate device memory unsigned char *d_pImage, *d_pImgResult; Complex *d_pTwiddleDFT, *d_pTwiddleIDFT, *d_pTempMatrix, *d_p2D_xfm, *d_pFilterOut; float *d_pFilterCoeffs; checkCudaErrors( cudaMalloc( (void**) &d_pImage, imSz ) ); checkCudaErrors( cudaMalloc( (void**) &d_pImgResult, imSz ) ); checkCudaErrors( cudaMalloc( (void**) &d_pTwiddleDFT, twiddleSz ) ); checkCudaErrors( cudaMalloc( (void**) &d_pTwiddleIDFT, twiddleSz ) ); checkCudaErrors( cudaMalloc( (void**) &d_pTempMatrix, twiddleSz ) ); checkCudaErrors( cudaMalloc( (void**) &d_p2D_xfm, twiddleSz ) ); checkCudaErrors( cudaMalloc( (void**) &d_pFilterCoeffs, filterSz ) ); checkCudaErrors( cudaMalloc( (void**) &d_pFilterOut, filterSz ) ); // Copy host memory to the device - use h_pImgResult for zeroing device result buffer checkCudaErrors( cudaMemcpy( d_pImage, h_pImage, imSz, cudaMemcpyHostToDevice ) ); checkCudaErrors( cudaMemcpy( d_pImgResult, h_pImgResult, imSz, cudaMemcpyHostToDevice ) ); checkCudaErrors( cudaMemcpy( d_pTwiddleDFT, h_pTwiddleDFT, twiddleSz, cudaMemcpyHostToDevice ) ); checkCudaErrors( cudaMemcpy( d_pTwiddleIDFT, h_pTwiddleIDFT, twiddleSz, cudaMemcpyHostToDevice ) ); checkCudaErrors( cudaMemcpy( d_pFilterCoeffs, h_pFilterCoeffs, filterSz, cudaMemcpyHostToDevice ) ); // Create CUDA events for the timer checkCudaErrors ( cudaEventCreate( &start ) ); checkCudaErrors ( cudaEventCreate( &stop ) ); // Kickoff start timer and dispatch the row-wise DFT kernel, block until the kernel returns checkCudaErrors( cudaEventRecord( start, NULL ) ); dispatchDFTkernel( d_pImage, d_pTwiddleDFT, d_pTempMatrix, d_p2D_xfm, false, true, d_pImgResult, nBlocks, nThreads ); cudaDeviceSynchronize(); // Dispatch the column-wise DFT kernel, block until the kernel returns dispatchDFTkernel( d_pImage, d_pTwiddleDFT, d_pTempMatrix, d_p2D_xfm, false, false, d_pImgResult, nBlocks, nThreads ); cudaDeviceSynchronize(); // Dispatch the filter kernel, block until the kernel returns dispatchFilterKernel( d_p2D_xfm, d_pFilterCoeffs, d_pTempMatrix, nBlocks, nThreads ); cudaDeviceSynchronize(); // Dispatch the row-wise IDFT kernel, block until the kernel returns dispatchDFTkernel( d_pImage, d_pTwiddleIDFT, d_pTempMatrix, d_p2D_xfm, true, true, d_pImgResult, nBlocks, nThreads ); cudaDeviceSynchronize(); // Dispatch the column-wise IDFT kernel, block until the kernel returns dispatchDFTkernel( d_pImage, d_pTwiddleIDFT, d_pTempMatrix, d_p2D_xfm, true, false, d_pImgResult, nBlocks, nThreads ); cudaDeviceSynchronize(); // Test checkCudaErrors( cudaMemcpy( h_pImgResult, d_pImgResult, imSz, cudaMemcpyDeviceToHost ) ); // Generate stop event and record execution time checkCudaErrors( cudaEventRecord( stop, NULL ) ); checkCudaErrors( cudaEventSynchronize( stop ) ); checkCudaErrors( cudaEventElapsedTime( &time, start, stop ) ); checkCudaErrors( cudaEventDestroy( start ) ); checkCudaErrors( cudaEventDestroy( stop ) ); // Print out time results std::cout << "Total GPU Execution time = " << time/1000 << " seconds" << std::endl; // Save our result if( !sdkSavePGM( fnameOut, m_imgOut, imWidth, imHeight ) ) std::cout << "Error Saving output file!!" << std::endl; else std::cout << "Finished writing to output!" << std::endl; cudaDeviceReset(); // Calculate CPU reference output and benchmark calcGoldRef( h_pImage, h_pTwiddleDFT_z, h_pTwiddleIDFT_z, h_pFilterCoeffs ); // Host cleanup - CUDA device reset reclaims device memory allocations if ( h_pImgResult != NULL ) free ( h_pImgResult ); if ( h_pTwiddleDFT != NULL ) free ( h_pTwiddleDFT ); if ( h_pTwiddleDFT_z != NULL ) free ( h_pTwiddleDFT_z ); if ( h_pTwiddleIDFT != NULL ) free ( h_pTwiddleIDFT ); if ( h_pTwiddleIDFT_z != NULL ) free ( h_pTwiddleIDFT_z ); if ( h_pFilterCoeffs != NULL ) free ( h_pFilterCoeffs ); exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { printf("[%s]\n", sSDKsample); if (argc > 1) { if (cutCheckCmdLineFlag(argc, (const char **)argv, "help")) { printHelp(); } if (cutCheckCmdLineFlag(argc, (const char **)argv, "qatest") || cutCheckCmdLineFlag(argc, (const char **)argv, "noprompt")) { g_bQAReadback = true; fpsLimit = frameCheckNumber; } if (cutCheckCmdLineFlag(argc, (const char **)argv, "glverify")) { g_bOpenGLQA = true; fpsLimit = frameCheckNumber; } if (cutCheckCmdLineFlag(argc, (const char **)argv, "fbo")) { g_bFBODisplay = true; fpsLimit = frameCheckNumber; } } if (g_bQAReadback) { runAutoTest(argc, argv); } else { // First initialize OpenGL context, so we can properly set the GL for CUDA. // This is necessary in order to achieve optimal performance with OpenGL/CUDA interop. initGL( &argc, argv ); // use command-line specified CUDA device if possible, otherwise search for capable device if( cutCheckCmdLineFlag(argc, (const char**)argv, "device") ) { cutilGLDeviceInit(argc, argv); int device; cudaGetDevice( &device ); if( checkCUDAProfile( device ) == false ) { cudaThreadExit(); cutilExit(argc, argv); } } else { //cudaGLSetGLDevice (cutGetMaxGflopsDeviceId() ); int dev = findCapableDevice(argc, argv); if( dev != -1 ) cudaGLSetGLDevice( dev ); else { cudaThreadExit(); cutilExit(argc, argv); } } cutilCheckError(cutCreateTimer(&timer)); cutilCheckError(cutResetTimer(timer)); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); glutIdleFunc(idle); if (g_bOpenGLQA) { loadDefaultImage( argc, argv ); } if (argc > 1) { char *filename; if (cutGetCmdLineArgumentstr(argc, (const char **)argv, "file", &filename)) { initializeData(filename, argc, argv); } } else { loadDefaultImage( argc, argv ); } // If code is not printing the USage, then we execute this path. if (!bQuit) { if (g_bOpenGLQA) { g_CheckRender = new CheckBackBuffer(wWidth, wHeight, 4); g_CheckRender->setPixelFormat(GL_BGRA); g_CheckRender->setExecPath(argv[0]); g_CheckRender->EnableQAReadback(true); } printf("I: display image\n"); printf("T: display Sobel edge detection (computed with tex)\n"); printf("S: display Sobel edge detection (computed with tex+shared memory)\n"); printf("Use the '-' and '=' keys to change the brightness.\n"); printf("b: switch block filter operation (mean/Sobel)\n"); printf("p: swtich point filter operation (threshold on/off)\n"); fflush(stdout); atexit(cleanup); glutMainLoop(); } } cudaThreadExit(); cutilExit(argc, argv); }
int main(int argc, char **argv) { pArgc = &argc; pArgv = argv; #if defined(__linux__) setenv ("DISPLAY", ":0", 0); #endif printf("%s Starting...\n\n", sSDKsample); if (checkCmdLineFlag(argc, (const char **)argv, "help")) { printf("\nUsage: SobelFilter <options>\n"); printf("\t\t-mode=n (0=original, 1=texture, 2=smem + texture)\n"); printf("\t\t-file=ref_orig.pgm (ref_tex.pgm, ref_shared.pgm)\n\n"); exit(EXIT_SUCCESS); } if (checkCmdLineFlag(argc, (const char **)argv, "file")) { g_bQAReadback = true; runAutoTest(argc, argv); } // use command-line specified CUDA device, otherwise use device with highest Gflops/s if (checkCmdLineFlag(argc, (const char **)argv, "device")) { printf(" This SDK does not explicitly support -device=n when running with OpenGL.\n"); printf(" When specifying -device=n (n=0,1,2,....) the sample must not use OpenGL.\n"); printf(" See details below to run without OpenGL:\n\n"); printf(" > %s -device=n\n\n", argv[0]); printf("exiting...\n"); exit(EXIT_SUCCESS); } // First initialize OpenGL context, so we can properly set the GL for CUDA. // This is necessary in order to achieve optimal performance with OpenGL/CUDA interop. initGL(&argc, argv); cudaGLSetGLDevice(gpuGetMaxGflopsDeviceId()); sdkCreateTimer(&timer); sdkResetTimer(&timer); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); loadDefaultImage(argv[0]); // If code is not printing the USage, then we execute this path. printf("I: display Image (no filtering)\n"); printf("T: display Sobel Edge Detection (Using Texture)\n"); printf("S: display Sobel Edge Detection (Using SMEM+Texture)\n"); printf("Use the '-' and '=' keys to change the brightness.\n"); fflush(stdout); #if defined (__APPLE__) || defined(MACOSX) atexit(cleanup); #else glutCloseFunc(cleanup); #endif glutTimerFunc(REFRESH_DELAY, timerEvent,0); glutMainLoop(); }
void runAutoTest(int argc, char *argv[]) { printf("[%s] (automated testing w/ readback)\n", sSDKsample); int devID = findCudaDevice(argc, (const char **)argv); loadDefaultImage(argv[0]); Pixel *d_result; checkCudaErrors(cudaMalloc((void **)&d_result, imWidth*imHeight*sizeof(Pixel))); char *ref_file = NULL; char dump_file[256]; int mode = 0; mode = getCmdLineArgumentInt(argc, (const char **)argv, "mode"); getCmdLineArgumentString(argc, (const char **)argv, "file", &ref_file); switch (mode) { case 0: g_SobelDisplayMode = SOBELDISPLAY_IMAGE; sprintf(dump_file, "lena_orig.pgm"); break; case 1: g_SobelDisplayMode = SOBELDISPLAY_SOBELTEX; sprintf(dump_file, "lena_tex.pgm"); break; case 2: g_SobelDisplayMode = SOBELDISPLAY_SOBELSHARED; sprintf(dump_file, "lena_shared.pgm"); break; default: printf("Invalid Filter Mode File\n"); exit(EXIT_FAILURE); break; } printf("AutoTest: %s <%s>\n", sSDKsample, filterMode[g_SobelDisplayMode]); sobelFilter(d_result, imWidth, imHeight, g_SobelDisplayMode, imageScale); checkCudaErrors(cudaDeviceSynchronize()); unsigned char *h_result = (unsigned char *)malloc(imWidth*imHeight*sizeof(Pixel)); checkCudaErrors(cudaMemcpy(h_result, d_result, imWidth*imHeight*sizeof(Pixel), cudaMemcpyDeviceToHost)); sdkSavePGM(dump_file, h_result, imWidth, imHeight); if (!sdkComparePGM(dump_file, sdkFindFilePath(ref_file, argv[0]), MAX_EPSILON_ERROR, 0.15f, false)) { g_TotalErrors++; } checkCudaErrors(cudaFree(d_result)); free(h_result); if (g_TotalErrors != 0) { printf("Test failed!\n"); exit(EXIT_FAILURE); } printf("Test passed!\n"); exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { pArgc = &argc; pArgv = argv; shrQAStart(argc, argv); if (argc > 1) { if (cutCheckCmdLineFlag(argc, (const char **)argv, "help")) { printHelp(); } if (cutCheckCmdLineFlag(argc, (const char **)argv, "qatest") || cutCheckCmdLineFlag(argc, (const char **)argv, "noprompt")) { g_bQAReadback = true; fpsLimit = frameCheckNumber; } if (cutCheckCmdLineFlag(argc, (const char **)argv, "glverify")) { g_bOpenGLQA = true; fpsLimit = frameCheckNumber; } if (cutCheckCmdLineFlag(argc, (const char **)argv, "fbo")) { g_bFBODisplay = true; fpsLimit = frameCheckNumber; } } if (g_bQAReadback) { runAutoTest(argc, argv); } else { if ( cutCheckCmdLineFlag(argc, (const char **)argv, "device")) { printf(" This SDK does not explicitly support -device=n when running with OpenGL.\n"); printf(" When specifying -device=n (n=0,1,2,....) the sample must not use OpenGL.\n"); printf(" See details below to run without OpenGL:\n\n"); printf(" > %s -device=n -qatest\n\n", argv[0]); printf("exiting...\n"); shrQAFinishExit(argc, (const char **)argv, QA_PASSED); } // First initialize OpenGL context, so we can properly set the GL for CUDA. // This is necessary in order to achieve optimal performance with OpenGL/CUDA interop. initGL( &argc, argv ); //cudaGLSetGLDevice (cutGetMaxGflopsDeviceId() ); int dev = findCapableDevice(argc, argv); if( dev != -1 ) { cudaGLSetGLDevice( dev ); } else { shrQAFinishExit2(g_bQAReadback, *pArgc, (const char **)pArgv, QA_PASSED); } cutilCheckError(cutCreateTimer(&timer)); cutilCheckError(cutResetTimer(timer)); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); if (g_bOpenGLQA) { loadDefaultImage( argc, argv ); } if (argc > 1) { char *filename; if (cutGetCmdLineArgumentstr(argc, (const char **)argv, "file", &filename)) { initializeData(filename, argc, argv); } } else { loadDefaultImage( argc, argv ); } // If code is not printing the USage, then we execute this path. if (!bQuit) { if (g_bOpenGLQA) { g_CheckRender = new CheckBackBuffer(wWidth, wHeight, 4); g_CheckRender->setPixelFormat(GL_BGRA); g_CheckRender->setExecPath(argv[0]); g_CheckRender->EnableQAReadback(true); } printf("I: display Image (no filtering)\n"); printf("T: display Sobel Edge Detection (Using Texture)\n"); printf("S: display Sobel Edge Detection (Using SMEM+Texture)\n"); printf("Use the '-' and '=' keys to change the brightness.\n"); printf("b: switch block filter operation (mean/Sobel)\n"); printf("p: switch point filter operation (threshold on/off)\n"); fflush(stdout); atexit(cleanup); glutTimerFunc(REFRESH_DELAY, timerEvent,0); glutMainLoop(); } } cutilDeviceReset(); shrQAFinishExit(argc, (const char **)argv, QA_PASSED); }
void runAutoTest(int argc, char **argv) { printf("[%s] (automated testing w/ readback)\n", sSDKsample); if( cutCheckCmdLineFlag(argc, (const char**)argv, "device") ) { int device = cutilDeviceInit(argc, argv); if (device < 0) { printf("No CUDA Capable devices found, exiting...\n"); shrQAFinishExit(argc, (const char **)argv, QA_WAIVED); } checkDeviceMeetComputeSpec( argc, argv ); } else { int dev = findCapableDevice(argc, argv); if( dev != -1 ) cudaSetDevice( dev ); else { cutilDeviceReset(); shrQAFinishExit2(g_bQAReadback, *pArgc, (const char **)pArgv, QA_PASSED); } } loadDefaultImage( argc, argv ); if (argc > 1) { char *filename; if (cutGetCmdLineArgumentstr(argc, (const char **)argv, "file", &filename)) { initializeData(filename, argc, argv); } } else { loadDefaultImage( argc, argv ); } g_CheckRender = new CheckBackBuffer(imWidth, imHeight, sizeof(Pixel), false); g_CheckRender->setExecPath(argv[0]); Pixel *d_result; cutilSafeCall( cudaMalloc( (void **)&d_result, imWidth*imHeight*sizeof(Pixel)) ); while (g_SobelDisplayMode <= 2) { printf("AutoTest: %s <%s>\n", sSDKsample, filterMode[g_SobelDisplayMode]); sobelFilter(d_result, imWidth, imHeight, g_SobelDisplayMode, imageScale, blockOp, pointOp ); cutilSafeCall( cutilDeviceSynchronize() ); cudaMemcpy(g_CheckRender->imageData(), d_result, imWidth*imHeight*sizeof(Pixel), cudaMemcpyDeviceToHost); g_CheckRender->savePGM(sOriginal[g_Index], false, NULL); if (!g_CheckRender->PGMvsPGM(sOriginal[g_Index], sReference[g_Index], MAX_EPSILON_ERROR, 0.15f)) { g_TotalErrors++; } g_Index++; g_SobelDisplayMode = (SobelDisplayMode)g_Index; } cutilSafeCall( cudaFree( d_result ) ); delete g_CheckRender; shrQAFinishExit(argc, (const char **)argv, (!g_TotalErrors ? QA_PASSED : QA_FAILED) ); }
int main(int argc, char **argv) { pArgc = &argc; pArgv = argv; printf("%s Starting...\n\n", argv[0]); if (checkCmdLineFlag(argc, (const char **)argv, "help")) { printf("\nUsage: FunctionPointers (SobelFilter) <options>\n"); printf("\t\t-mode=n (0=original, 1=texture, 2=smem + texture)\n"); printf("\t\t-file=ref_orig.pgm (ref_tex.pgm, ref_shared.pgm)\n\n"); exit(EXIT_WAIVED); } if (checkCmdLineFlag(argc, (const char **)argv, "file")) { g_bQAReadback = true; runAutoTest(argc, argv); } // use command-line specified CUDA device, otherwise use device with highest Gflops/s if (checkCmdLineFlag(argc, (const char **)argv, "device")) { printf(" This SDK does not explicitly support -device=n when running with OpenGL.\n"); printf(" When specifying -device=n (n=0,1,2,....) the sample must not use OpenGL.\n"); printf(" See details below to run without OpenGL:\n\n"); printf(" > %s -device=n\n\n", argv[0]); printf("exiting...\n"); exit(EXIT_WAIVED); } if (!g_bQAReadback) { // First initialize OpenGL context, so we can properly set the GL for CUDA. // This is necessary in order to achieve optimal performance with OpenGL/CUDA interop. initGL(&argc, argv); int dev = findCapableDevice(argc, argv); checkDeviceMeetComputeSpec(argc, argv); if (dev != -1) { cudaGLSetGLDevice(dev); } else { exit(EXIT_WAIVED); } sdkCreateTimer(&timer); sdkResetTimer(&timer); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); loadDefaultImage(argv[0]); // If code is not printing the USage, then we execute this path. printf("I: display Image (no filtering)\n"); printf("T: display Sobel Edge Detection (Using Texture)\n"); printf("S: display Sobel Edge Detection (Using SMEM+Texture)\n"); printf("Use the '-' and '=' keys to change the brightness.\n"); printf("b: switch block filter operation (Mean/Sobel)\n"); printf("p: switch point filter operation (Threshold ON/OFF)\n"); fflush(stdout); atexit(cleanup); glutTimerFunc(REFRESH_DELAY, timerEvent,0); glutMainLoop(); } cudaDeviceReset(); exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { // EDISON ////////////////////////////////////////////////////////////////// sigmaS = 7.0f; sigmaR = 6.5f; edison.minRegion = 20.0f; cutLoadPPMub("image.ppm", &edison.inputImage_, &width, &height); edison.meanShift(); cutSavePPMub("segmimage.ppm", edison.segmImage_, width, height); cutSavePPMub("filtimage.ppm", edison.filtImage_, width, height); unsigned char data[height * width]; memset(data, 0, height * width * sizeof(unsigned char)); for(int i = 0; i < edison.numBoundaries_; i++) { data[edison.boundaries_[i]] = 255; } cutSavePGMub("bndyimage.pgm", data, width, height); //return 0; // EDISON ////////////////////////////////////////////////////////////////// if (argc > 1) { if (cutCheckCmdLineFlag(argc, (const char **)argv, "help")) { printHelp(); } if (cutCheckCmdLineFlag(argc, (const char **)argv, "qatest") || cutCheckCmdLineFlag(argc, (const char **)argv, "noprompt")) { g_bQAReadback = true; fpsLimit = frameCheckNumber; } if (cutCheckCmdLineFlag(argc, (const char **)argv, "glverify")) { g_bOpenGLQA = true; fpsLimit = frameCheckNumber; } if (cutCheckCmdLineFlag(argc, (const char **)argv, "fbo")) { g_bFBODisplay = true; fpsLimit = frameCheckNumber; } } if (g_bQAReadback) { runAutoTest(argc, argv); } else { // First initialize OpenGL context, so we can properly set the GL for CUDA. // This is necessary in order to achieve optimal performance with OpenGL/CUDA interop. initGL( argc, argv ); // use command-line specified CUDA device, otherwise use device with highest Gflops/s if( cutCheckCmdLineFlag(argc, (const char**)argv, "device") ) { cutilGLDeviceInit(argc, argv); } else { cudaGLSetGLDevice (cutGetMaxGflopsDeviceId() ); } int device; struct cudaDeviceProp prop; cudaGetDevice( &device ); cudaGetDeviceProperties( &prop, device ); if(!strncmp( "Tesla", prop.name, 5 )) { printf("This sample needs a card capable of OpenGL and display.\n"); printf("Please choose a different device with the -device=x argument.\n"); cudaThreadExit(); cutilExit(argc, argv); } cutilCheckError(cutCreateTimer(&timer)); cutilCheckError(cutResetTimer(timer)); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); glutIdleFunc(idle); if (g_bOpenGLQA) { loadDefaultImage( argv[0] ); } if (argc > 1) { char *filename; if (cutGetCmdLineArgumentstr(argc, (const char **)argv, "file", &filename)) { initializeData(filename); } } else { loadDefaultImage( argv[0]); } // If code is not printing the USage, then we execute this path. if (!bQuit) { if (g_bOpenGLQA) { g_CheckRender = new CheckBackBuffer(wWidth, wHeight, 4); g_CheckRender->setPixelFormat(GL_BGRA); g_CheckRender->setExecPath(argv[0]); g_CheckRender->EnableQAReadback(true); } printf("I: display image\n"); printf("T: display Sobel edge detection (computed with tex)\n"); printf("S: display Sobel edge detection (computed with tex+shared memory)\n"); printf("Use the '-' and '=' keys to change the brightness.\n"); fflush(stdout); atexit(cleanup); glutMainLoop(); } } cudaThreadExit(); cutilExit(argc, argv); }