Results 1 to 2 of 2

Thread: calculate optimal pitch value

  1. #1

    calculate optimal pitch value

    Hi forum,

    I am calculating the pitch value for the device i am working on in the following manner:

    Code :
          //pull out the device info for the optimal texture pitch
          cl_uint deviceMemBaseAddressAlignmentInBits;      
          unsigned int deviceMemBaseAddressAlignmentInBytes;
          //get the device info
          //describes the alignment in bits of the base address of any allocated
          //memory object
          errNum = clGetDeviceInfo(cdDevices[0],
          if( errNum != CL_SUCCESS )
    	 std::cerr << "Device Memory Base Address Alignment Extraction is not successful." << std::endl;
    	 return NULL;
          //convert bits to bytes
          deviceMemBaseAddressAlignmentInBytes = deviceMemBaseAddressAlignmentInBits / 8;
          unsigned int remainingAlignmentBytes = (DIM*sizeof(cl_float2)) % deviceMemBaseAddressAlignmentInBytes;
          if( remainingAlignmentBytes != 0 )
    	 tPitch = (DIM*sizeof(cl_float2)) + (deviceMemBaseAddressAlignmentInBytes - remainingAlignmentBytes);
    	 //returns basically the image row pitch
    	 tPitch =  (DIM*sizeof(cl_float2)); // no additional bytes required.

    I need your feed-back over this issue to make sure that i am doing it right.


  2. #2
    Senior Member
    Join Date
    Oct 2012
    You computation is right. Two remarks, though:

    1. CL_DEVICE_MEM_BASE_ADDR_ALIGN gives the alignment for the largest OpenCL built-in type. This is useful if you intend to store various built-in types at different times in the same buffer because it guarantees that data will always be aligned.

    If you know that your buffer will contain only float2 data, you just have to align on sizeof(float2)=8.

    2. You can make your computation simpler:

    Code :
    tPitch = ((DIM*sizeof(cl_float2) + deviceMemBaseAddressAlignmentInBytes - 1) / deviceMemBaseAddressAlignmentInBytes) * deviceMemBaseAddressAlignmentInBytes;

    or even simpler if deviceMemBaseAddressAlignmentInBytes is a power of 2:

    Code :
    tPitch = (DIM*sizeof(cl_float2) + deviceMemBaseAddressAlignmentInBytes - 1) % ~(deviceMemBaseAddressAlignmentInBytes - 1);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean