首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cloo OpenCL c#问题

Cloo OpenCL c#问题
EN

Stack Overflow用户
提问于 2010-10-18 22:40:59
回答 2查看 4.3K关注 0票数 5

我试图让一个简单的Cloo程序运行,但它没有工作,谁能告诉我为什么?

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Cloo;
using System.Runtime.InteropServices;

namespace HelloWorld
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {


ComputeContextPropertyList cpl = new ComputeContextPropertyList(ComputePlatform.Platforms[0]);
ComputeContext context = new ComputeContext(ComputeDeviceTypes.Gpu, cpl, null, IntPtr.Zero);

string kernelSource = @"
 kernel void VectorAdd(
  global read_only float* a,
  global read_only float* b,
  global write_only float* c )
 {
  int index = get_global_id(0);
  c[index] = a[index] + b[index];
 }
 ";
long count = 20;
float[] arrA = new float[count];
float[] arrB = new float[count];
float[] arrC = new float[count];

Random rand = new Random();

for (int i = 0; i < count; i++)
{
 arrA[i] = (float)(rand.NextDouble() * 100);
 arrB[i] = (float)(rand.NextDouble() * 100);
}

ComputeBuffer<float> a = new ComputeBuffer<float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, arrA);
ComputeBuffer<float> b = new ComputeBuffer<float>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer, arrB);
ComputeBuffer<float> c = new ComputeBuffer<float>(context, ComputeMemoryFlags.WriteOnly, arrC.Length);

ComputeProgram program = new ComputeProgram(context, new string[] { kernelSource });
program.Build(null, null, null, IntPtr.Zero);

ComputeKernel kernel = program.CreateKernel("VectorAdd");
kernel.SetMemoryArgument(0, a);
kernel.SetMemoryArgument(1, b);
kernel.SetMemoryArgument(2, c);

ComputeCommandQueue commands = new ComputeCommandQueue(context, context.Devices[0], ComputeCommandQueueFlags.None);

ComputeEventList events = new ComputeEventList();

commands.Execute(kernel, null, new long[] { count }, null, events);

arrC = new float[count];
GCHandle arrCHandle = GCHandle.Alloc(arrC, GCHandleType.Pinned);

commands.Read(c, false, 0, count, arrCHandle.AddrOfPinnedObject(), events);
commands.Finish();

arrCHandle.Free();

for (int i = 0; i < count; i++)
 richTextBox1.Text += "{" + arrA[i] + "} + {" + arrB[i] + "} = {" + arrC[i] + "} \n";

}
        }
    }

这是程序给我的错误

'Cloo.InvalidBinaryComputeException‘类型的未处理异常发生在Cloo.dll中

附加信息:检测到OpenCL错误代码: InvalidBinary.

EN

回答 2

Stack Overflow用户

发布于 2010-11-15 12:36:39

这看起来与与Cloo一起分发的VectorAddTest相同。

你在用ATI流吗?如果是,这可能是一个与此相关的问题:http://sourceforge.net/tracker/?func=detail&aid=2946105&group_id=290412&atid=1229014

Clootils通过分配控制台来解决这个问题。有关实现细节,请查看Clootils/Program.cs。

票数 2
EN

Stack Overflow用户

发布于 2011-06-17 14:31:06

更改内核名称--我认为名称VectorAdd与某些内容相冲突。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3964003

复制
相关文章

相似问题

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