cuda.jl:错误:loadError:methodError:无方法匹配typeof(fillpixel!)(:: cudevicematrix {rgb {float32},1})

发布于 2025-02-07 04:40:55 字数 1679 浏览 1 评论 0原文

我在朱莉娅(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美的太阳 2025-02-14 04:40:55

两个注释:fillPixel!(arr :: cuarray)将您的功能仅限于cuarray。 cuda.jl将主机侧表示cuarray转换为设备侧表示`cudeViceArray。因此,如果您放松了类型限制,则不会遇到此问题。

其次,您不想迭代您启动的内核内部的数组。您要么要使用MAP map!之类的函数来实现数据并行主义,要么使用CUDA索引原语。

Two comments: fillpixel!(arr::CuArray) limits your function to only the type CuArray. CUDA.jl translates the host side representation CuArray 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 or map! to implement the data-parallelism or use the CUDA index primitives.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文