Skip to content
This repository was archived by the owner on Sep 27, 2021. It is now read-only.
This repository was archived by the owner on Sep 27, 2021. It is now read-only.

Structs with tuple fields as broadcast arguments #38

@rafaqz

Description

@rafaqz

I've been trying to broadcast with an argument like this:

struct WithTuple
    a::Int32
    b::Tuple{Int32,Int32}
end

But it breaks with an error like this, somehow to do with differences in the packing of the tuple:

ERROR:     Julia and OpenCL type don't match at kernel argument 6: Found Tuple{CLArrays.DeviceArray{UInt32,2,CLArrays.HostPtr{UInt32}},Cellular.Life{Cellular.RadialNeighborhood{:test,Cellular.Skip},Int32,Tuple{Int32,Int32}}}. 
    Please make sure to define OpenCL structs correctly!
    You should be generally fine by using `__attribute__((packed))`, but sometimes the alignment of fields is different from Julia.
    Consider the following example:
        ```
        //packed
        // Tuple{NTuple{3, Float32}, Void, Float32}
        struct __attribute__((packed)) Test{
            float3 f1;
            int f2; // empty type gets replaced with Int32 (no empty types allowed in OpenCL)
            // you might need to define the alignement of fields to match julia's layout
            float f3; // for the types used here the alignement matches though!
        };
        // this is a case where Julia and OpenCL packed alignment would differ, so we need to specify it explicitely
        // Tuple{Int64, Int32}
        struct __attribute__((packed)) Test2{
            long f1;
            int __attribute__((aligned (8))) f2; // opencl would align this to 4 in packed layout, while Julia uses 8!
        };
        ```
    You can use `c.datatype_align(T)` to figure out the alignment of a Julia type!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions