jas
jas

Reputation: 49

How to convert a double4 to a double array in opencl?

I have a double4 variable which I want to convert to a double array. As double4 is a vector of 4 doubles, is there a way we can extract these doubles from double4 ? Also at the most basic level, all data types can be broken down to bytes, so is there a way I can ready double4 as bytes and then convert to double ?

Upvotes: 0

Views: 673

Answers (2)

DarkZeros
DarkZeros

Reputation: 8410

You just need vstoren(). Here you have the DOC and an usage example:

__kernel mykern (...){

    ...
    private double data[8]; //vstore works for private/local/global memory types
    private double4 vec = (double4)(0.0, 1.0, 2.0, 3.0);

    vstore4(vec, 0, data); //Will write the first 4 doubles of data with vec information
    vstore4(vec, 4, data); //Will write the last 4 doubles of data with vec information
    ...
}

Upvotes: 1

Meluha
Meluha

Reputation: 1578

yes you can do, component of vector data type (with 1 to 4 components) can be addressed as .xyzw

double4 vecArray;
....
....
double extractedVecArray[4];

extractedVecArray[0] = vecArray.w;
extractedVecArray[1] = vecArray.x;
extractedVecArray[2] = vecArray.y;
extractedVecArray[3] = vecArray.z;

I have not tested above code, but it should work.

Upvotes: 0

Related Questions