【问题标题】:Cloo OpenCL c# ProblemCloo OpenCL c# 问题
【发布时间】:2011-04-27 05:07:03
【问题描述】:

我正在尝试运行一个简单的 Cloo 程序,但它不起作用,谁能告诉我为什么?

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。

【问题讨论】:

  • 你看过程序构建日志吗?它有没有说什么有趣的东西?以及从哪里抛出异常(我假设是 commands.Execute,但只是为了确定)?
  • 最后,你的问题解决了吗?

标签: c# opencl opentk cloo


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    Clootils 通过分配控制台来解决这个问题。检查 Clootils/Program.cs 以了解实施细节。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-17
      • 2017-07-06
      • 1970-01-01
      • 2014-03-24
      • 2017-07-06
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多