有没有人在VB.NET中成功地使用过CUDAfy?

有没有人在VB.NET中成功地使用过CUDAfy?,vb.net,cudafy.net,Vb.net,Cudafy.net,我正在尝试使用VS2013在VB.NET中使用CUDAFy 1.29 我试图翻译CUDAFy的C样本,我有两种错误,如下所述: 我的变量 我的代码: 端接头 将在CUDA上运行的函数ADICIONA 问题是: 问题1:如果我使用dim模作为CudafyModule=CudafyTranslator.Cudafy,我会得到以下错误:不支持Checked语句。真奇怪!Cudafy的所有文档都显示了这一行 问题2:因此,我尝试检查是否存在已写入的module.CDFY,如果不存在,则调用Seriali

我正在尝试使用VS2013在VB.NET中使用CUDAFy 1.29

我试图翻译CUDAFy的C样本,我有两种错误,如下所述:

我的变量

我的代码:

端接头

将在CUDA上运行的函数ADICIONA

问题是:

问题1:如果我使用dim模作为CudafyModule=CudafyTranslator.Cudafy,我会得到以下错误:不支持Checked语句。真奇怪!Cudafy的所有文档都显示了这一行

问题2:因此,我尝试检查是否存在已写入的module.CDFY,如果不存在,则调用Serialize函数。问题是函数在我的文件夹中创建了一个名为STRING.CDFY的文件,但没有正确的ADICIONA.CDFY或ADD_LONG_LOOP.CDFY。既然我希望避免在每次运行这段代码时编译,那么如何正确地让CUDAFy编写它呢

问题3:当VS运行时,一切正常,直到调用ADICIONA MyGPU.Launch!VS停止执行,并显示一条消息:在模块中找不到函数“ADICIONA”

值得注意的是:

1-创建了两个临时文件.CU、.PTX和.CDFY文件。这表明NVCC编译器运行良好,并且正在创建CUDA模块。那么,为什么代码找不到函数ADICIONA呢

2-所有用C编写的样本在此处100%运行。从C和VB的转换似乎还可以,我已经用TELERIK来做了。我想问题可能与此无关,但我可能错了

3-问题与NVCC编译器或VB.NET中的某些引用无关,因为代码是编译的

我试着用CODEPLEX写下答案。根本没有答案。。。 我试图在互联网上看到很多样本,但所有的样本都是为CUDAFy C创建的,没有一个是使用版本1.29和CUDA 7.5

另外,我想了解为什么基本函数CudafyTranslator.Cudafy在VB中出错,而在C中却没有

那么,这里有没有人使用VB.NET成功地创建了CUDAFy代码


非常感谢您的帮助。

要解决问题1,请选中“项目属性”>“编译”>“高级编译选项”>“优化”下的“删除整数溢出检查”。更多信息:

试试这个简单的例子:

Imports Cudafy
Imports Cudafy.Host
Imports Cudafy.Translator

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim GPU As GPGPU = CudafyHost.GetDevice(eGPUType.OpenCL, CudafyModes.DeviceId)
        Dim Modulo As CudafyModule = CudafyTranslator.Cudafy(ePlatform.All, GPU.GetArchitecture())

        GPU.LoadModule(Modulo)

        Dim Resultado As Integer
        Dim ResultadoGPU As Integer() = gpu.Allocate(Of Integer)()

        GPU.Launch().Adicionar(2, 7, ResultadoGPU)
        GPU.CopyFromDevice(ResultadoGPU, Resultado)
        MessageBox.Show("2 + 7 = " & Resultado)

        GPU.Launch().Subtrair(2, 7, ResultadoGPU)
        GPU.CopyFromDevice(ResultadoGPU, Resultado)
        MessageBox.Show("2 - 7 = " & Resultado)

        GPU.Free(ResultadoGPU)
    End Sub

    <Cudafy()>
    Private Shared Sub Adicionar(a As Integer, b As Integer, c As Integer())
        c(0) = a + b
    End Sub

    <Cudafy()>
    Private Shared Sub Subtrair(a As Integer, b As Integer, c As Integer())
        c(0) = a - b
    End Sub
End Class

MyGPU.LoadModuleModulo在哪里?你似乎在代码示例中遗漏了这一部分。谢谢@Mystra007,我只是忘了把它放在上面的帖子里。我现在将提供更新,但我向您保证问题与此无关。
 Shared Executa()

 if Loader = true

        Dim Modulo = CudafyModule.TryDeserialize(cs_cc)
        If IsNothing(Modulo) OrElse (Not Modulo.TryVerifyChecksums) Then
            Modulo = CudafyTranslator.Cudafy(ePlatform.All, Arch, cs_CC.GetType)
            Modulo.Serialize()
        End If

        MyGPU.Loadmodule(Modulo)

        Dim a As Integer() = New Integer(N - 1) {}
        Dim b As Integer() = New Integer(N - 1) {}
        Dim c As Integer() = New Integer(N - 1) {}

        ' allocate the memory on the GPU
        Dim dev_a As Integer() = MyGPU.Allocate(Of Integer)(a)
        Dim dev_b As Integer() = MyGPU.Allocate(Of Integer)(b)
        Dim dev_c As Integer() = MyGPU.Allocate(Of Integer)(c)

        ' fill the arrays 'a' and 'b' on the CPU
        For i As Integer = 0 To N - 1
            a(i) = i
            b(i) = 2 * i
        Next

        ' copy the arrays 'a' and 'b' to the GPU
        MyGPU.CopyToDevice(a, dev_a)
        MyGPU.CopyToDevice(b, dev_b)


        For i As Integer = 0 To 128
            MyGPU.Launch(1, 1).adiciona(dev_a, dev_b, dev_c)
        Next

 end if
 <Cudafy()> _
  Shared Sub adiciona(thread As GThread, a As Integer(), b As Integer(), c As Integer())

    Dim tid As Integer = thread.blockIdx.x
    While tid < N
        c(tid) = a(tid) + b(tid)
        tid += thread.gridDim.x
    End While
   End Sub
Public Shared Function Loader() As Boolean

    DeviceType = eGPUType.Cuda
    CudafyModes.Target = DeviceType
    CudafyTranslator.Language = If(CudafyModes.Target = eGPUType.Cuda, eLanguage.Cuda, eLanguage.OpenCL)
    Dim CompatibleDevice As GPGPUProperties() = CudafyHost.GetDeviceProperties(CudafyModes.Target, True).ToArray

    If Not CompatibleDevice.Any Then        '  não possui um full-CUDA device
        MsgBox("I do not found any OpenCL or CUDA compatible device")
        Return False
    End If

    Dim selectedDevice As GPGPUProperties = CompatibleDevice(0)
    If IsNothing(selectedDevice) Then
        MsgBox("I cannot allocate a compatible device")
        Return False
    End If


    CudafyModes.DeviceId = selectedDevice.DeviceId
    Thread_per_Block = selectedDevice.MaxThreadsPerBlock
    Blocks_per_Grid = selectedDevice.MaxThreadsSize.x
    Shared_Mem_per_Block = selectedDevice.SharedMemoryPerBlock

    MyGPU = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId)
    Arch = MyGPU.GetArchitecture

    Return True

 End Function
Imports Cudafy
Imports Cudafy.Host
Imports Cudafy.Translator

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim GPU As GPGPU = CudafyHost.GetDevice(eGPUType.OpenCL, CudafyModes.DeviceId)
        Dim Modulo As CudafyModule = CudafyTranslator.Cudafy(ePlatform.All, GPU.GetArchitecture())

        GPU.LoadModule(Modulo)

        Dim Resultado As Integer
        Dim ResultadoGPU As Integer() = gpu.Allocate(Of Integer)()

        GPU.Launch().Adicionar(2, 7, ResultadoGPU)
        GPU.CopyFromDevice(ResultadoGPU, Resultado)
        MessageBox.Show("2 + 7 = " & Resultado)

        GPU.Launch().Subtrair(2, 7, ResultadoGPU)
        GPU.CopyFromDevice(ResultadoGPU, Resultado)
        MessageBox.Show("2 - 7 = " & Resultado)

        GPU.Free(ResultadoGPU)
    End Sub

    <Cudafy()>
    Private Shared Sub Adicionar(a As Integer, b As Integer, c As Integer())
        c(0) = a + b
    End Sub

    <Cudafy()>
    Private Shared Sub Subtrair(a As Integer, b As Integer, c As Integer())
        c(0) = a - b
    End Sub
End Class