英文:
How to pass an array of structs to kernel with JOCL
问题
我正在使用JOCL(Java的OpenCL绑定)编写一个OpenCL光线追踪器。我想要将一个结构体数组传递给我的内核。这个结构体的定义如下:
struct Sphere {
float3 center;
float radius;
int materialIndex;
};
而内核接受的形式如下:
__kernel void raytraceKernel(
__constant struct Sphere *spheres,
// 其他参数...
在这种情况下,最佳的做法是什么?最初,这个结构体没有materialIndex
字段,所以我只是在Java中创建了一个浮点数数组,将中心、半径和填充数据填充进去,然后将其发送到内核中。然而,当我添加了materialIndex
字段后,我决定将我的程序转换为使用NIO缓冲区,但这并没有成功(数据损坏)。
在JOCL中向内核传递结构体数组是否有更好的方法呢?
英文:
I'm writing an OpenCL raytracer using JOCL (OpenCL bindings for Java). I want to pass an array of structs to my kernel. The struct looks like this:
struct Sphere {
float3 center;
float radius;
int materialIndex;
};
and the kernel takes it as this:
__kernel void raytraceKernel(
__constant struct Sphere *spheres,
etc...
What is the best way to do this? Initially, the struct did not have the materialIndex
field, so I simply created an array of floats in Java, populated it with center, radius, and padding, and sent it to the kernel. However, when I added materialIndex
I decided to convert my program to use NIO buffers, which didn't work (data was corrupted).
Is there a better approach to passing an array of structs to a kernel with JOCL?
专注分享java语言的经验与见解,让所有开发者获益!
评论