gpt4 book ai didi

cuda - NVIDIA __constant内存: how to populate constant memory from host in both OpenCL and CUDA?

转载 作者:行者123 更新时间:2023-12-02 18:12:13 24 4
gpt4 key购买 nike

我在主机上有一个缓冲区(数组),该缓冲区应驻留在设备(在本例中为 NVIDIA GPU)的常量内存区域中。

所以,我有两个问题:

  1. 如何分配一 block 常量内存?鉴于我正在跟踪设备上的可用常量内存,并且我知道,事实上,我们有足够的可用内存(此时)

  2. 如何根据主机上运行时计算的值初始化(填充)这些数组?

我在网上搜索了这一点,但没有简明的文档记录这一点。如果提供的示例同时包含 OpenCL 和 CUDA,我将不胜感激。 OpenCL 的示例对我来说比 CUDA 更重要。

最佳答案

  1. How can I allocate a chunk of constant memory? Given the fact that I am tracing the available constant memory on the device and I know, for a fact, that we have that amount of memory available to us (at this time)

在 CUDA 中,你不能。没有常量内存的运行时分配,只有通过 __constant__ 说明符静态定义内存,该说明符在汇编时映射到常量内存页。您可以在运行时生成一些包含此类静态声明的代码,并通过nvrtc进行编译。 ,但是对于您知道大小只能达到 64kb 的东西来说,这似乎需要付出很大的努力。静态声明一个 64kb 常量缓冲区并在运行时根据需要使用它似乎要简单得多(至少对我来说)。

  1. How can I initialize (populate) those arrays from values that are computed at the runtime on the host?

如评论中所述,请参阅herecudaMemcpyToSymbol API 就是为此目的而创建的,它的工作原理与标准 memcpy 一样。

从功能上来说,OpenCL 中的 __constant 和 CUDA 中的 __constant__ 没有区别。同样的限制也适用:编译时静态定义(标准 OpenCL 执行模型中的运行时)、64kb 限制。

关于cuda - NVIDIA __constant内存: how to populate constant memory from host in both OpenCL and CUDA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72147453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com