cuda.jl:错误:loadError:methodError:无方法匹配typeof(fillpixel!)(:: cudevicematrix {rgb {float32},1})
我在朱莉娅(Julia)制作了一个非常最小的射线示踪剂,并且正在实现使用CUDA的更快版本。完整的代码太广泛而无法共享,但是这是我认为与问题最相关的部分:
world = World(RGB(1, 1, 1), 5e-6, shapes, lights, 0.2, 4)
camera = Camera((0, -5000, -5000), 1000, (0, 0, 0), 1920, 1080)
canvas = CUDA.fill(world.background, camera.height, camera.width)
function fillpixel!(arr::CuArray)
height = size(arr)[1]
for j in 1:length(arr)
ind = (j % height, ceil(j / height))
ray = [([ind[2], ind[1]] - [camera.width / 2, camera.height / 2])..., camera.depth]
(ray[2], ray[3]) = (cos(camera.rotation[1] + atan(ray[3], ray[2])), sin(camera.rotation[1] + atan(ray[3], ray[2]))) .* sqrt(ray[2]^2 + ray[3]^2)
(ray[1], ray[3]) = (cos(camera.rotation[2] + atan(ray[3], ray[1])), sin(camera.rotation[2] + atan(ray[3], ray[1]))) .* sqrt(ray[1]^2 + ray[3]^2)
(ray[1], ray[2]) = (cos(camera.rotation[3] + atan(ray[2], ray[1])), sin(camera.rotation[3] + atan(ray[2], ray[1]))) .* sqrt(ray[2]^2 + ray[1]^2)
v = (Inf, nothing, nothing)
for object in world.objects
t = traceray(ray, camera.position, object, mindistance=camera.depth)
t !== nothing && t[1] < v[1] && (v = (t[1], t[2], object))
end
v[1] != Inf && (arr[j] = computecolor(v[3].material, ray, v[1], v[2], world, camera.position .+ v[1] * ray, v[3]))
return nothing
end
end
@cuda fillpixel!(canvas)
但是当我运行程序时,它给我以下错误:
CUDA.jl: ERROR: LoadError: MethodError: no method matching typeof(fillpixel!)(::CuDeviceMatrix{RGB{Float32}, 1})
我无法找出导致此错误和的原因我到底做错了什么。
谢谢。
I had made a very minimal ray tracer in Julia, and was in the process of implementing a faster version that uses CUDA. The full code is too extensive to share, but here is the part that I think is most relevant to the question:
world = World(RGB(1, 1, 1), 5e-6, shapes, lights, 0.2, 4)
camera = Camera((0, -5000, -5000), 1000, (0, 0, 0), 1920, 1080)
canvas = CUDA.fill(world.background, camera.height, camera.width)
function fillpixel!(arr::CuArray)
height = size(arr)[1]
for j in 1:length(arr)
ind = (j % height, ceil(j / height))
ray = [([ind[2], ind[1]] - [camera.width / 2, camera.height / 2])..., camera.depth]
(ray[2], ray[3]) = (cos(camera.rotation[1] + atan(ray[3], ray[2])), sin(camera.rotation[1] + atan(ray[3], ray[2]))) .* sqrt(ray[2]^2 + ray[3]^2)
(ray[1], ray[3]) = (cos(camera.rotation[2] + atan(ray[3], ray[1])), sin(camera.rotation[2] + atan(ray[3], ray[1]))) .* sqrt(ray[1]^2 + ray[3]^2)
(ray[1], ray[2]) = (cos(camera.rotation[3] + atan(ray[2], ray[1])), sin(camera.rotation[3] + atan(ray[2], ray[1]))) .* sqrt(ray[2]^2 + ray[1]^2)
v = (Inf, nothing, nothing)
for object in world.objects
t = traceray(ray, camera.position, object, mindistance=camera.depth)
t !== nothing && t[1] < v[1] && (v = (t[1], t[2], object))
end
v[1] != Inf && (arr[j] = computecolor(v[3].material, ray, v[1], v[2], world, camera.position .+ v[1] * ray, v[3]))
return nothing
end
end
@cuda fillpixel!(canvas)
but when I run the program, it gives me the following error:
CUDA.jl: ERROR: LoadError: MethodError: no method matching typeof(fillpixel!)(::CuDeviceMatrix{RGB{Float32}, 1})
and I am unable to find out what causes this error and what exactly I'm doing wrong.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个注释:
fillPixel!(arr :: cuarray)
将您的功能仅限于cuarray
。 cuda.jl将主机侧表示cuarray
转换为设备侧表示`cudeViceArray。因此,如果您放松了类型限制,则不会遇到此问题。其次,您不想迭代您启动的内核内部的数组。您要么要使用
MAP
map!之类的函数来实现数据并行主义,要么使用CUDA索引原语。Two comments:
fillpixel!(arr::CuArray)
limits your function to only the typeCuArray
. CUDA.jl translates the host side representationCuArray
to the device side representation `CuDeviceArray. So if you loosen your type restrictions you won't run into this issue.Secondly you don't want to iterate over the array inside the kernel you launched. You either want to use a function like
map
ormap!
to implement the data-parallelism or use the CUDA index primitives.