Ejemplo n.º 1
0
int
NBody::verifyResults()
{
    if(verify) {
        /* reference implementation
        * it overwrites the input array with the output
        */
        refPos = (cl_float*)malloc(numBodies * sizeof(cl_float4));
        assert(refPos != NULL);
        refVel = (cl_float*)malloc(numBodies * sizeof(cl_float4));
        assert(refVel != NULL);

        memcpy(refPos, initPos, 4 * numBodies * sizeof(cl_float));
        memcpy(refVel, initVel, 4 * numBodies * sizeof(cl_float));

        for(int i = 0; i < iterations; ++i) {
            nBodyCPUReference();
        }

        /* compare the results and see if they match */
        if(!compareVector(pos, refPos, 4 * numBodies, 0.00001)) {
            exit(1);
        }
    }

    return 0;
}
Ejemplo n.º 2
0
int
NBody::verifyResults()
{
    if(verify)
    {
        /* reference implementation
        * it overwrites the input array with the output
        */

        refPos = (cl_float*)malloc(numBodies * sizeof(cl_float4));
        if(refPos == NULL)
        { 
            sampleCommon->error("Failed to allocate host memory. (refPos)");
            return SDK_FAILURE;
        }

        refVel = (cl_float*)malloc(numBodies * sizeof(cl_float4));
        if(refVel == NULL)
        { 
            sampleCommon->error("Failed to allocate host memory. (refVel)");
            return SDK_FAILURE;
        }

        memcpy(refPos, initPos, 4 * numBodies * sizeof(cl_float));
        memcpy(refVel, initVel, 4 * numBodies * sizeof(cl_float));

        for(int i = 0; i < iterations; ++i)
        {
            nBodyCPUReference();
        }

        /* compare the results and see if they match */
        if(sampleCommon->compare(pos, refPos, 4 * numBodies, 0.00001))
        {
            std::cout << "Passed!\n";
            return SDK_SUCCESS;
        }
        else
        {
            std::cout << "Failed!\n";
            return SDK_FAILURE;
        }
    }

    return SDK_SUCCESS;
}