On Mon, 13 Feb 2012 17:47:18 +0100, Holger Rapp <[email protected]> wrote: > Hello, > > I recently refactored my code to use the following structure. > > typedef struct { > // __read_only image2d_t sgmf; Note: commented out, see below > > float3 so; > float3 sbvw; > float3 sbvh; > > float4 intrinsics; > DualQuaternion w2c; > DualQuaternion c2w; > } Measurement __attribute__ ((aligned (16))) ; > The python site looks something like that: > s = \ > pack("=fff4x", *dm.screen.origin) + \ > pack("=fff4x", *dm.screen.bv1) + \ > pack("=fff4x", *dm.screen.bv2) + \ > pack("=ffff", A[0,0], A[1,1], A[0,2], A[1,2]) + \ > pack("=ffff", *dm.w2c.dq.r._v) + \ > pack("=ffff", *dm.w2c.dq.d._v) + \ > pack("=ffff", *dm.w2c.inv.dq.r._v) + \ > pack("=ffff", *dm.w2c.inv.dq.d._v) > params_buf = cl.Buffer(ctx, mf.READ_ONLY, len(s)) > cl.enqueue_write_buffer(queue, params_buf, s).wait() > > Before, I had to pass all arguments individually into my kernel (and I > had 2-n of those structures). All is fine and dandy, except for two > issues I am unable to work out and would appreciate some help: > > 1) How can I pack the image2d_t on the python site so that I can include it > into > my structure. Currently I have to pass it individually, but it is really just > a parameter of the structure from a semantic point of view. I'd like to > pass the kernel a variable number of the structures, so this would be > really useful.
OpenCL 1.2 spec, 6.9b): An image type (image2d_t, image3d_t, image2d_array_t, image1d_t, image1d_buffer_t or image1d_array_t) can only be used as the type of a function argument. An image function argument cannot be modified. Elements of an image can only be accessed using built-in functions described in section 6.12.14. An image type cannot be used to declare a variable, a structure or union field, an array of images, a pointer to an image, or the return type of a function. An image type cannot be used with the __private, __local and __constant address space qualifiers. The image3d_t type cannot be used with the __write_only access qualifier unless the cl_khr_3d_image_writes extension is enabled. An image type cannot be used with the __read_write access qualifer which is reserved for future use. > 2) I pass the params_buf as __constant to my kernel. I have some > functions doing arithmetic with DualQuaternions and I have to first copy > all data from my structure before working with them: e.g. > > void conjugate(const DualQuaternion * a, DualQuaternion * rv); > > DualQuaternion rv; > conjugate(&measurement->w2c, &rv); > Gives this error: > passing 'DualQuaternion __attribute__((address_space(2)))const *' discards > qualifiers, expected 'DualQuaternion const *' > > DualQuaternion temp = measurement->w2c; > conjugate(&w2c, &rv); > is working okay. > > I understand the reason for this I think: functions need to work in one > address space only. But is there a way to pass my structures to my kernel > that the explicit copy is not needed? My advice would be to pass the arguments to conjugate() by value and use a return value. This avoids issues of address space matching (i.e. declaring __constant args in conjugate()), and any half-way smart compiler will generate equivalent code anyway. HTH, Andreas
pgp52VHkQ4yhg.pgp
Description: PGP signature
_______________________________________________ PyOpenCL mailing list [email protected] http://lists.tiker.net/listinfo/pyopencl
