How can I interpolate a set of precomputed functions in OpenCL?

I am working with OpenCL core where I need to use linked Legendre polynomials.

This is a set of fairly complex calculations, indexed by an integer of n and m orders, and taking a real argument. The specifics of the actual polynomials are irrelevant since I have a (slow) side function that can generate them, but the kernel side function should look something like this:

float legendre(int n, int m, float z)
 {
    float3 lookupCoords;
    lookupCoords.x = n;
    lookupCoords.y = m;
    lookupCoords.z = z;

    //Do something here to interpolate Z for a given N and M...
 }

      

I want to interpolate along the Z axis, but just have the nearest neighbor for the n and m axes as they are only defined for integer values. The advantage of Z is that it is only defined between -1 and 1, so it is already very similar to the texture coordinate.

How do I do this using a sampler table and lookup in OpenCL?

My first thought was trying to use a 3D texture filled with pre-computed orders, but I only want to interpolate one dimension (real or Z argument) and I'm not sure what that would look like in OpenCL C.

+3


source to share


1 answer


In OpenCL 1.1, use read_imagef

c image3d_t

for the first parameter, a sampler_t

created with CLK_FILTER_LINEAR

for the second parameter, and finally float4 coord

for the third parameter with your coordinates to read from.

To interpolate along one axis only, let this coordinate value be any float value, but make the other two coordinates floor(value) + 0.5f

. This will make them non-interpolated. Like this (only z interpolation):



float4 coordinate = (float4)(floor(x) + 0.5f, floor(y) + 0.5f, z, 0.0f);

      

In OpenCL 1.2, you can use arrays of images, but I'm not sure if that will be faster and NVIDIA does not support OpenCL 1.2 on Windows.

+2


source







All Articles