[Mesa-dev] [cfe-dev] 3 element vectors in opencl 1.1+

Matt Arsenault Matthew.Arsenault at amd.com
Tue Apr 22 14:40:25 PDT 2014


On 04/22/2014 02:35 PM, Tom Stellard wrote:
> On Mon, Apr 21, 2014 at 10:02:27PM -0400, Jan Vesely wrote:
>> Hi,
>>
>> I ran into a problem caused by this part of the OCL specs (6.1.5
>> Alignment of Types):
>> "For 3-component vector data types, the size of the data type is 4 *
>> sizeof(component)."
>>
>> and the corresponding part of Khronos cl_platform.h (with all types, not
>> just float):
>> /* cl_float3 is identical in size, alignment and behavior to cl_float4.
>> See section 6.1.5. */
>> typedef  cl_float4  cl_float3;
>>
>> So when I try to run kernel that takes 3 element vectors as arguments I
>> get 'invalid arg size' error.
>>
>> Not sure whether this is best solved in clang, libclc or clover. I tried
>> changing float3 to have 4 elements in libclc, it caused clang to
>> complain in thousand places. I don't think this can be handled cleanly
>> in clang, unless we add something like __attribute__((padding)).
>>
>> I have attached a workaround that I use now.
>>
> You may want to ask this question on the pocl mailing list as they
> have likely solved this issue already.  Ideally, TD.getTypeStoreSize
> would return the correct value.  Also, maybe look at the DataLayout
> description for R600 and see if there is a way to specify the
> correct type size.
>
> -Tom
I think this is what v96:128 is for


>
>> any advice welcome,
>> Jan
>>
>> -- 
>> Jan Vesely <jan.vesely at rutgers.edu>
>> diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> index a81bdf8..71ee01f 100644
>> --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
>> @@ -62,6 +62,8 @@
>>   #include <llvm/IR/DataLayout.h>
>>   #endif
>>   
>> +#include <llvm/Support/Debug.h>
>> +
>>   #include "pipe/p_state.h"
>>   #include "util/u_memory.h"
>>   
>> @@ -309,6 +311,13 @@ namespace {
>>   
>>               llvm::Type *arg_type = arg.getType();
>>               unsigned arg_size = TD.getTypeStoreSize(arg_type);
>> +            if (arg_type->isVectorTy() &&
>> +               ::llvm::cast<::llvm::VectorType>(arg_type)->getNumElements() == 3) {
>> +               ::llvm::dbgs() << "Fixing argument type: " << *arg_type
>> +                              << " size: " << arg_size << "->"
>> +                              << (arg_size / 3) * 4 << "\n";
>> +               arg_size = (arg_size / 3) * 4;
>> +            }
>>   
>>               llvm::Type *target_type = arg_type->isIntegerTy() ?
>>                  TD.getSmallestLegalIntType(mod->getContext(), arg_size * 8) :
>
>
>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the mesa-dev mailing list