首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在C#中不正确地包括了cloo?

在C#中不正确地包括了cloo?
EN

Stack Overflow用户
提问于 2013-08-15 10:34:33
回答 1查看 1.5K关注 0票数 0

我正在尝试构建演示程序,但是我得到了这个错误

我在mono和visual studio 2010中尝试过同样的问题

错误发生在网上。

代码语言:javascript
复制
program.Build(null, null, null, IntPtr.Zero);

编辑

C#

代码语言:javascript
复制
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

代码语言:javascript
复制
kernel void helloWorld(global read_only int* message, int messageSize) {
    for (int i = 0; i < messageSize; i++) {
        printf("%d", message[i]);
    }
}

编辑

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-15 11:08:35

是的,打印可能不是很好的支持。我建议你用一些简单的数字运算来表演你的“你好世界”。也许是这样:

代码语言:javascript
复制
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;  
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18250926

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档