簡體   English   中英

在C#中錯誤地包含cloo?

[英]Incorrectly including cloo in C#?

我正在嘗試構建這個演示,但是我收到了這個錯誤

在此輸入圖像描述

我已經嘗試過單聲道和visual studio 2010,同樣的問題

錯誤發生在線上

program.Build(null, null, null, IntPtr.Zero);

編輯

C#

using System;
using Cloo;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.IO;

namespace ClooTest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            // pick first platform
            ComputePlatform platform = ComputePlatform.Platforms[0];

            // create context with all gpu devices
            ComputeContext context = new ComputeContext(ComputeDeviceTypes.Gpu,
                                                        new ComputeContextPropertyList(platform), null, IntPtr.Zero);

            // create a command queue with first gpu found
            ComputeCommandQueue queue = new ComputeCommandQueue
            (
                context,
                context.Devices[0], 
                ComputeCommandQueueFlags.None
            );

            // load opencl source
            StreamReader streamReader = new StreamReader("kernels.cl");
            string clSource = streamReader.ReadToEnd();
            streamReader.Close();

            // create program with opencl source
            ComputeProgram program = new ComputeProgram(context, clSource);

            // compile opencl source
            program.Build(null, null, null, IntPtr.Zero);

            // load chosen kernel from program
            ComputeKernel kernel = program.CreateKernel("helloWorld");

            // create a ten integer array and its length
            int[] message = new int[] { 1, 2, 3, 4, 5 };
            int messageSize = message.Length;

            // allocate a memory buffer with the message (the int array)
            ComputeBuffer<int> messageBuffer = new ComputeBuffer<int>(context,
                                                                      ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer, message);

            kernel.SetMemoryArgument(0, messageBuffer); // set the integer array
            kernel.SetValueArgument(1, messageSize); // set the array size

            // execute kernel
            queue.ExecuteTask(kernel, null);

            // wait for completion
            queue.Finish();
        }
    }
}

OpenCL的

kernel void helloWorld(global read_only int* message, int messageSize) {
    for (int i = 0; i < messageSize; i++) {
        printf("%d", message[i]);
    }
}

編輯 調試

是的打印可能不是很好支持。 我建議用一些簡單的數字運算來執行你的“Hello world”。 也許是這樣的:

kernel void IncrementNumber(global float4 *celldata_in, global float4 *celldata_out) {
    int index = get_global_id(0);

    float4 a = celldata_in[index];
    a.w = a.w + 1;

    celldata_out[index] = a;  
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM