0

我在两个不同的系统上尝试过这段代码:

using System;
using System.Collections.Generic;
using System.Linq;
using Cloo;

namespace MinimalExample
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Enumerable.Range(0, 10).ToArray();
            var output = new int[input.Length];
            var platform = ComputePlatform.Platforms.First();
            var context = new ComputeContext(
                platform.Devices,
                new ComputeContextPropertyList(platform), 
                null,
                IntPtr.Zero
            );
            var queue = new ComputeCommandQueue(
                context,
                platform.Devices.First(),
                ComputeCommandQueueFlags.None
            );
            var program = new ComputeProgram(
                context,
                "void kernel some_test(constant int* a, global int* b) { " + 
                     int i = get_global_id(0);
                     b[i] = a[i];
                 }");
            program.Build(null, string.Empty, null, IntPtr.Zero);
            using (var kernel = program.CreateKernel("some_test"))
            using (var inBuff = new ComputeBuffer<int>(context, ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.UseHostPointer, input))
            using (var outBuff = new ComputeBuffer<int>(context, ComputeMemoryFlags.WriteOnly | ComputeMemoryFlags.UseHostPointer, output))
            {
                kernel.SetMemoryArgument(0, inBuff);
                kernel.SetMemoryArgument(1, outBuff);
                var events = new List<ComputeEventBase>();
                queue.Execute(kernel, null, new long[] { input.Length }, null, events);
                queue.Finish();
            }
            if (output.All(x => x == 0)) throw new Exception("Output buffer not written.");
        }
    }
}
  • 在我的桌面系统上,该程序不会抛出(output具有您在阅读内核代码时所期望的值)。该系统具有支持 OpenCL 2.1 的 AMD GPU。

  • 在我的笔记本电脑上,这个程序在最后一行抛出。这意味着内核没有按照我的预期运行,或者根本没有运行。该系统有一个支持 OpenCL 2.1 的 Intel CPU 和一个支持 OpenCL 1.2 的 Nvidia GPU,它们都表现出相同的行为。从 Nvidia 下载的 OpenCL 样本似乎可以自检并正常通过。

Cloo 检查不成功的返回码并在任何地方返回错误时抛出。但以防万一,我直接检查了 OpenCL 返回给 Cloo 的代码,实际上它们都表明只是“成功”。

如果我尝试不同的标志和地址空间组合似乎并不重要——一个系统从不抛出,一个系统总是抛出。

我在这里想念什么?

4

0 回答 0