- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
使用 VS 2012、.NET 4.5、64 位和 CUDAfy 1.12,我有以下概念证明
using System;
using System.Runtime.InteropServices;
using Cudafy;
using Cudafy.Host;
using Cudafy.Translator;
namespace Test
{
[Cudafy(eCudafyType.Struct)]
[StructLayout(LayoutKind.Sequential)]
public struct ChildStruct
{
[MarshalAs(UnmanagedType.LPArray)]
public float[] FArray;
public long FArrayLength;
}
[Cudafy(eCudafyType.Struct)]
[StructLayout(LayoutKind.Sequential)]
public struct ParentStruct
{
public ChildStruct Child;
}
public class Program
{
[Cudafy]
public static void KernelFunction(GThread gThread, ParentStruct parent)
{
long length = parent.Child.FArrayLength;
}
public static void Main(string[] args)
{
var module = CudafyTranslator.Cudafy(
ePlatform.x64, eArchitecture.sm_35,
new[] {typeof(ChildStruct), typeof(ParentStruct), typeof(Program)});
var dev = CudafyHost.GetDevice();
dev.LoadModule(module);
float[] hostFloat = new float[10];
for (int i = 0; i < hostFloat.Length; i++) { hostFloat[i] = i; }
ParentStruct parent = new ParentStruct
{
Child = new ChildStruct
{
FArray = dev.Allocate(hostFloat),
FArrayLength = hostFloat.Length
}
};
dev.Launch(1, 1, KernelFunction, parent);
Console.ReadLine();
}
}
}
当程序运行时,我在 dev.Launch 上收到以下错误:
类型“Test.ParentStruct”不能作为非托管结构进行编码;无法计算有意义的大小或偏移量。
如果我从 ChildStruct 中删除 float 组,它会按预期工作。
我过去曾在 C/C++/Cli 和 CUDA C 中工作过,我知道错误的性质。此错误的一些解决方案建议使用 MarshalAs
的 Size
参数手动设置结构大小,但由于结构中类型的多样性,这是不可能的。
我查看了生成的 .cu 文件,它正在将 float 组生成为 float *
,这正是我所期望的。
有没有办法将结构中的数组传递给内核?如果没有什么是最好的第二种选择?这个问题在 CUDA C 中不存在,它只存在是因为我们是从 CLR 编码的。
最佳答案
我花了很多时间阅读 CUDAfy 的源代码,看看是否有解决这个问题的方法。
CUDAfy 试图让 .NET 开发人员的工作变得过于简单,并使他们远离 IntPtr
和其他指针概念。然而,抽象级别使得如果不对该库的工作方式进行重大重构,就很难找到这个问题的答案。
无法在结构中发送 float 组是一个阻碍。我最终对 CUDA 运行时执行了 PInvoke 而没有使用 CUDAfy。
关于c# - 在 CUDAfy 的结构中传递数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16340278/
我正在尝试运行我的第一个 cudafy 项目,但在以下行中收到以下错误: CudafyModule km = CudafyTranslator.Cudafy(); 下面是我收到的确切错误消息的屏幕截图
我有一个要进行 CUDA 化的结构“DDReal”,它依赖于一个类“Base”,该类具有要进行 CUDA 化的静态方法——两者都在同一项目的单独文件中。它们被编译成 DLL 程序集,由发生 CUDAf
如何在 cudafy 中拥有一个充满数组的结构? 这似乎是一个微不足道的问题,但我无法在网上找到它的简单实现。 某些链接表明无法完成,例如:Passing an array within a stru
我需要一种算法来计算数组的并行前缀和而不使用共享内存。如果除了使用共享内存别无选择,解决冲突问题的最佳方法是什么? 最佳答案 此链接包含对并行前缀和的顺序和并行算法的详分割析: Parallel Pr
使用 VS 2012、.NET 4.5、64 位和 CUDAfy 1.12,我有以下概念证明 using System; using System.Runtime.InteropServices; u
我在将包含多个数组的结构分配给 GPU 时遇到了一些问题。在第二个代码块中,我收到一个错误: SimpleDataStructure[] dev_SDS = _gpu.CopyToDevice(SDS
我想在内核中这样做: int count[8]; 我几乎肯定您可以在 CUDA GPU 内核中声明固定大小的数组。那么我该如何在使用 Cudafy 的同时做到这一点呢?这不起作用: [Cudafy]
感谢您阅读我的主题。 我的 Cudafy 无法加载 cublas64_55.dll 我使用的是 Windows 7、VS2012 和 CUDA5.5。我的 cublas64_55.dll , cuff
我的问题 嘿,所以我正在做这个简单的计算来找到 0 到 100 度之间的罪恶总和(因为我用它作为我的系统的基准),计算不是问题我的问题是我是Cudafy 的新手,我不确定如何正确传入和返回值,以便可以
我有一个工作算法可以对图像执行 2D 透视变换。 算法如下: private Bitmap RescaleImage(double TopLX, double TopLY, double TopRX,
我正在使用 CUDAfy 和 C#。对于我的内核,我需要 double 。在 CUDA 中,这没有问题,它是自动支持的。然而,为了支持非 NVIDIA 硬件,用户也应该能够使用 OpenCL。在这里,
我添加了对 CUDAfy.NET 的引用通过 NuGet 库。 当我运行我的程序时,我遇到了一个Win32Exception: The system cannot find the file spe
我正在尝试在 Web 应用程序中使用 CUDAfy.NET,该应用程序将从 Web 表单中进一步调用。 当它尝试启动 CudafyModule 时,会出现如下图所示的错误: 代码在控制台应用程序中运行
我是一名优秀的程序员,十分优秀!