Exemple #1
0
void cl_writeToZCBuffer(cl_mem mem, void* data, size_t size)
{

    void* ptr;

    ptr = cl_mapBuffer(mem, size, CL_MAP_WRITE);

    memcpy(ptr, data, size);

    cl_unmapBuffer(mem, ptr);
}
Exemple #2
0
/*!
    Copy data back from the GPU into an IpVec structure on the host
*/
IpVec* Surf::retrieveDescriptors()
{
    IpVec* ipts = new IpVec();

    if(this->numIpts == 0) 
    {
        return ipts;
    }

    // Copy back the output data

#ifdef OPTIMIZED_TRANSFERS
    // We're using pinned memory for the transfers.  The data is 
    // copied back to pinned memory and then must be mapped before
    // it's usable on the host

    // Copy back Laplacian data
    this->laplacian = (int*)cl_copyAndMapBuffer(this->h_laplacian, 
        this->d_laplacian, this->numIpts * sizeof(int));

    // Copy back scale data
    this->scale = (float*)cl_copyAndMapBuffer(this->h_scale, 
        this->d_scale, this->numIpts * sizeof(float));
    
    // Copy back pixel positions
    this->pixPos = (float2*)cl_copyAndMapBuffer(this->h_pixPos, 
        this->d_pixPos, this->numIpts * sizeof(float2));

    // Copy back descriptors
    this->desc = (float*)cl_copyAndMapBuffer(this->h_desc, 
        this->d_desc, this->numIpts * DESC_SIZE* sizeof(float));

    // Copy back orientation data
    this->orientation = (float*)cl_copyAndMapBuffer(this->h_orientation, 
        this->d_orientation, this->numIpts * sizeof(float));
#else
    // Copy back Laplacian information
    cl_copyBufferToHost(this->laplacian, this->d_laplacian, 
        (this->numIpts) * sizeof(int), CL_FALSE);

    // Copy back scale data
    cl_copyBufferToHost(this->scale, this->d_scale,
        (this->numIpts)*sizeof(float), CL_FALSE);

    // Copy back pixel positions
    cl_copyBufferToHost(this->pixPos, this->d_pixPos, 
        (this->numIpts) * sizeof(float2), CL_FALSE);   

    // Copy back descriptors
    cl_copyBufferToHost(this->desc, this->d_desc, 
        (this->numIpts)*DESC_SIZE*sizeof(float), CL_FALSE);
    
    // Copy back orientation data
    cl_copyBufferToHost(this->orientation, this->d_orientation, 
        (this->numIpts)*sizeof(float), CL_TRUE);
#endif  

    // Parse the data into Ipoint structures
    for(int i= 0;i<(this->numIpts);i++)
    {		
        Ipoint ipt;		
        ipt.x = pixPos[i].x;
        ipt.y = pixPos[i].y;
        ipt.scale = scale[i];
        ipt.laplacian = laplacian[i];
        ipt.orientation = orientation[i];
        memcpy(ipt.descriptor, &desc[i*64], sizeof(float)*64);
        ipts->push_back(ipt);
    }

#ifdef OPTIMIZED_TRANSFERS
    // We're done reading from the buffers, so we unmap
    // them so they can be used again by the device
    cl_unmapBuffer(this->h_laplacian, this->laplacian);
    cl_unmapBuffer(this->h_scale, this->scale);
    cl_unmapBuffer(this->h_pixPos, this->pixPos);
    cl_unmapBuffer(this->h_desc, this->desc);
    cl_unmapBuffer(this->h_orientation, this->orientation);
#endif

    return ipts;
}