// Run a test sequence without any GL 
//*****************************************************************************
void TestNoGL()
{
    // Warmup call to assure OpenCL driver is awake
    // note this function has a finish for all queues at its end, so no further host sync is needed
    SobelFilterGPU (uiInput, uiOutput);

    // Start timer 0 and process n loops on the GPU
    const int iCycles = 150;
    dProcessingTime = 0.0;
    shrLog("\nRunning SobelFilterGPU for %d cycles...\n\n", iCycles);
    shrDeltaT(2); 
    for (int i = 0; i < iCycles; i++)
    {
        // note this function has a finish for all queues at its end, so no further host sync is needed
        dProcessingTime += SobelFilterGPU (uiInput, uiOutput);
    }

    // Get round-trip and average computation time
    double dRoundtripTime = shrDeltaT(2)/(double)iCycles;
    dProcessingTime /= (double)iCycles;

    // log throughput, timing and config info to sample and master logs
    shrLogEx(LOGBOTH | MASTER, 0, "oclSobelFilter, Throughput = %.4f M RGB Pixels/s, Time = %.5f s, Size = %u RGB Pixels, NumDevsUsed = %u, Workgroup = %u\n", 
           (1.0e-6 * uiImageWidth * uiImageHeight)/dProcessingTime, dProcessingTime, (uiImageWidth * uiImageHeight), GpuDevMngr->uiUsefulDevCt, szLocalWorkSize[0] * szLocalWorkSize[1]); 
    shrLog("\nRoundTrip Time = %.5f s, Equivalent FPS = %.1f\n\n", dRoundtripTime, 1.0/dRoundtripTime);

    // Compute on host 
    cl_uint* uiGolden = (cl_uint*)malloc(szBuffBytes);
    SobelFilterHost(uiInput, uiGolden, uiImageWidth, uiImageHeight, fThresh);

    // Compare GPU and Host results:  Allow variance of 1 GV in up to 0.01% of pixels 
    shrLog("Comparing GPU Result to CPU Result...\n"); 
    shrBOOL bMatch = shrCompareuit(uiGolden, uiOutput, (uiImageWidth * uiImageHeight), 1.0f, 0.0001f);
    shrLog("\nGPU Result %s CPU Result within tolerance...\n", (bMatch == shrTRUE) ? "matches" : "DOESN'T match"); 

    // Cleanup and exit
    free(uiGolden);
    Cleanup((bMatch == shrTRUE) ? EXIT_SUCCESS : EXIT_FAILURE);
}
예제 #2
0
bool CheckRender::compareBin2BinUint(const char *src_file, const char *ref_file, unsigned int nelements, const float epsilon, const float threshold)
{
    unsigned int *src_buffer, *ref_buffer;
    FILE *src_fp = NULL, *ref_fp = NULL;

    unsigned long error_count = 0;

    #ifdef WIN32
        fopen_s(&src_fp, src_file, "rb");
    #else
        src_fp = fopen(src_file, "rb");
    #endif

    if (src_fp== NULL) {
        shrLog("compareBin2Bin <unsigned int> unable to open src_file: %s\n", src_file);   
        error_count++;
    }
    char *ref_file_path = shrFindFilePath(ref_file, m_ExecPath);
    if (ref_file_path == NULL) {
        shrLog("compareBin2Bin <unsigned int>  unable to find <%s> in <%s>\n");
        shrLog(">>> Check info.xml and [project//data] folder <%s> <<<\n", ref_file);
        shrLog("Aborting comparison!\n", ref_file, m_ExecPath);
        error_count++;

        if (src_fp) fclose(src_fp);
        if (ref_fp) fclose(ref_fp);
    } 
    else 
    {
        #ifdef WIN32
            fopen_s(&ref_fp, ref_file_path, "rb");
        #else
            ref_fp = fopen(ref_file_path, "rb");
        #endif

        if (ref_fp == NULL) {
            shrLog("compareBin2Bin <unsigned int>  unable to open ref_file: %s\n", ref_file_path);   
            error_count++;
        }

        if (src_fp && ref_fp) {
            src_buffer = (unsigned int *)malloc(nelements*sizeof(unsigned int));
            ref_buffer = (unsigned int *)malloc(nelements*sizeof(unsigned int));

            fread(src_buffer, nelements, sizeof(unsigned int), src_fp);
            fread(ref_buffer, nelements, sizeof(unsigned int), ref_fp);

            shrLog("> compareBin2Bin <unsigned int> nelements=%d, epsilon=%.2f, threshold=%.2f\n", nelements, epsilon, threshold);
			shrLog("   src_file <%s>\n", src_file);
			shrLog("   ref_file <%s>\n", ref_file_path);
            if (!shrCompareuit( ref_buffer, src_buffer, nelements, epsilon, threshold))
                error_count++;

            fclose(src_fp);
            fclose(ref_fp);

            free(src_buffer);
            free(ref_buffer);
        } else {
            if (src_fp) fclose(src_fp);
            if (ref_fp) fclose(ref_fp);
        }
    }

    if (error_count == 0) { 
        shrLog("   Data Matches\n"); 
    } else {
        shrLog("   Data Doesn't Match!!! %d errors...\n", (unsigned int)error_count);
    }

    return (error_count == 0);  // returns true if all pixels pass
}
예제 #3
0
bool CheckRender::compareBin2BinUint(const char *src_file, const char *ref_file, unsigned int nelements, const float epsilon, const float threshold)
{
    unsigned int *src_buffer, *ref_buffer;
    FILE *src_fp = NULL, *ref_fp = NULL;

    unsigned long error_count = 0;

    #ifdef WIN32
        errno_t err;
        if ((err = fopen_s(&src_fp, src_file, "rb")) != 0)
    #else
        if ((src_fp = fopen(src_file, "rb")) == NULL)
    #endif
        {
            printf(" compareBin2Bin <unsigned int> unable to open src_file: %s\n", src_file);
            error_count++;
        }

    char *ref_file_path = shrFindFilePath(ref_file, m_ExecPath);
    if (ref_file_path == NULL) {
        printf(" compareBin2Bin <unsigned int>  unable to find <%s> in <%s>\n", ref_file, m_ExecPath);
        printf(" >>> Check info.xml and [project//data] folder <%s> <<<\n", ref_file);
        printf(" Aborting comparison!\n");
        printf("  FAILED!\n");
        error_count++;

        if (src_fp) fclose(src_fp);
        if (ref_fp) fclose(ref_fp);
    }
    else
    {
        #ifdef WIN32
            errno_t err;
            if ((err = fopen_s(&ref_fp, ref_file_path, "rb")) != 0)
        #else
            if ((ref_fp = fopen(ref_file_path, "rb")) == NULL)
        #endif
            {
                printf("compareBin2Bin <unsigned int>  unable to open ref_file: %s\n", ref_file_path);
                error_count++;
            }

        if (src_fp && ref_fp) {
            src_buffer = (unsigned int *)malloc(nelements*sizeof(unsigned int));
            ref_buffer = (unsigned int *)malloc(nelements*sizeof(unsigned int));

            if (fread(src_buffer, sizeof(unsigned int), nelements, src_fp) != nelements)
            {
                printf("compareBin2Bin <unsigned int>  unable to read from src_file: %s\n", src_file);
                error_count++;
            }
            else if (fread(ref_buffer, sizeof(unsigned int), nelements, ref_fp) != nelements)
            {
                printf("compareBin2Bin <unsigned int>  unable to read from ref_file: %s\n", ref_file_path);
                error_count++;
            }
            else
            {
                printf(" > compareBin2Bin <unsigned int> nelements=%d, epsilon=%4.2f, threshold=%4.2f\n", nelements, epsilon, threshold);
                printf("   src_file <%s>\n", src_file);
                printf("   ref_file <%s>\n", ref_file_path);
                if (!shrCompareuit( ref_buffer, src_buffer, nelements, epsilon, threshold))
                    error_count++;
            }

            fclose(src_fp);
            fclose(ref_fp);

            free(src_buffer);
            free(ref_buffer);
        }
        else
        {
            if (src_fp) fclose(src_fp);
            if (ref_fp) fclose(ref_fp);
        }
    }

    if (error_count == 0)
    {
        printf("TEST PASSED\n\n");
    }
    else
    {
        printf("TEST FAILED !!! %d errors...\n\n", (unsigned int)error_count);
    }

    return (error_count == 0);  // returns true if all pixels pass
}