完整的 .NET OpenCL 实现

发布于 2024-11-01 06:56:22 字数 1539 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

陌伤ぢ 2024-11-08 06:56:22

好吧,您所说的所有库都是 opencl 本机库的简单包装器。它们构成了相对少量的额外抽象,并且非常接近一般的 opencl 函数。因此,如果您总体上熟悉 opencl,您很快就会熟悉这些库。

我认为“OpenCL.NET”实现已经完成,它不含任何非 OpenCL 的内容。但用过几次后,我发现它的水平太低了。

我创建了自己的包装器,它通过极大地简化主机部分为我提供了很好的工作,这是我的一个项目的主机部分(如果您有兴趣,我可以在 github 或任何其他 svn 服务中发布我的 OpenCl 包装器):

using System;
using System.Net;
using System.Collections.Generic;
using System.IO;

using Shared;
using Shared.IO;
using Shared.OpenCL;

namespace Testing
{
    public class ApplicationClass
    {
        static Random rand = new Random();

        static Single[] RandomArray(Int32 length)
        {
            Single[] result = new Single[length];

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = (Single)rand.NextDouble();
            }

            return result;
        }

        static void Main(string[] args)
        {
            DeviceGlobalMemory output = new Byte[4096];

            DeviceGlobalMemory indeces = RandomArray(102400);
            DeviceGlobalMemory ops = new Byte[3072];
            DeviceGlobalMemory data = RandomArray(1048576);

            Console.Write("Creating kernel...");

            Kernel kernel = Kernel.Create("Kernel", File.ReadAllText("Test.c"), data, indeces, ops, output);

            Console.Write("Executing kernel...");

            Event e = kernel.Execute(256, 256);

            kernel.CommandQueue.Finish();

            Console.WriteLine("done, operation took {0}", Profiler.DurationSeconds(e));

            UnmanagedReader reader = new UnmanagedReader(new DeviceBufferStream(output));

            for (int i = 0; i < 256; i++)
            {
                if (i % 4 == 0) Console.WriteLine();
                if (i % 16 == 0) Console.WriteLine();

                Console.Write("{0}\t", reader.Read<Single>());
            }
        }
    }
}

Well, all libraries you've stated are simple wrappers for opencl native libraries. They pose relatively small amount of additional abstractions and are very close to general opencl functions. So if you are familiar with opencl in general you will get familiar with these libraries in no time.

I think the 'OpenCL.NET' implementation is complete, it is free of anything that is not OpenCL. But after using it several times I've found it too low level.

I've created my own wrapper it serves me good job by simplifying the host part dramatically here's the host part of one of my projects (if you are interested I can publish my OpenCl wrapper in github or any other svn service):

using System;
using System.Net;
using System.Collections.Generic;
using System.IO;

using Shared;
using Shared.IO;
using Shared.OpenCL;

namespace Testing
{
    public class ApplicationClass
    {
        static Random rand = new Random();

        static Single[] RandomArray(Int32 length)
        {
            Single[] result = new Single[length];

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = (Single)rand.NextDouble();
            }

            return result;
        }

        static void Main(string[] args)
        {
            DeviceGlobalMemory output = new Byte[4096];

            DeviceGlobalMemory indeces = RandomArray(102400);
            DeviceGlobalMemory ops = new Byte[3072];
            DeviceGlobalMemory data = RandomArray(1048576);

            Console.Write("Creating kernel...");

            Kernel kernel = Kernel.Create("Kernel", File.ReadAllText("Test.c"), data, indeces, ops, output);

            Console.Write("Executing kernel...");

            Event e = kernel.Execute(256, 256);

            kernel.CommandQueue.Finish();

            Console.WriteLine("done, operation took {0}", Profiler.DurationSeconds(e));

            UnmanagedReader reader = new UnmanagedReader(new DeviceBufferStream(output));

            for (int i = 0; i < 256; i++)
            {
                if (i % 4 == 0) Console.WriteLine();
                if (i % 16 == 0) Console.WriteLine();

                Console.Write("{0}\t", reader.Read<Single>());
            }
        }
    }
}
月下凄凉 2024-11-08 06:56:22

OpenTK 还有另一个绑定库 https://www.nuget.org/packages/Cloo.clSharp< /a>.到 2023 年,它仍然可以在 netcore(和 linux/macos)上运行。

他们将其定位为“与原始绑定相比,它提供了更清晰的 OpenCL API(如果您需要它们,也可以使用它们)”,并且“Cloo 是一个开源、易于使用的托管库,它使 .NET/Mono 应用程序能够充分利用 OpenCL 框架。”

这些样品看起来非常有前途。

There's another bindings library from OpenTK https://www.nuget.org/packages/Cloo.clSharp. And it still works in 2023 on netcore (and linux/macos).

They position it as "It provides a much cleaner OpenCL API compared to raw bindings (which are also available in case you need them)" and "Cloo is an open source, easy to use, managed library which enables .NET/Mono applications to take full advantage of the OpenCL framework."

The samples look very promising.

月依秋水 2024-11-08 06:56:22

我还有一组开源 OpenCL 绑定。网。我主要为自己编写此代码,因此它可以忠实地反映 OpenCL API,同时又对 .NET 友好。这个库永远不会有任何 OOP 抽象,而且它的性能非常好。

http://openclnet.codeplex.com

希望这会有所帮助。

I also have a set of open source OpenCL bindings for. NET. I wrote this for myself primarily so it would mirror the OpenCL API faithfully while being .NET friendly. There will never be any OOP abstractions for this library, and it's quite performant.

http://openclnet.codeplex.com

Hope this helps.

∝单色的世界 2024-11-08 06:56:22

多年来我使用了一些不同的 C# OpenCL 包装器,现在正在使用 NOpenCL。它写得很好,并且遵循 MIT 许可证。

https://github.com/tunnelvisionlabs/NOpenCL

I have used some different C# OpenCL wrappers over the years and am using NOpenCL now. It is well written and is under the MIT License.

https://github.com/tunnelvisionlabs/NOpenCL

是伱的 2024-11-08 06:56:22

我同意olegz的回答。
我刚刚开始使用 OpenCL,但 Cloo 似乎是一个非常好的选择。我发现它的使用非常简单,并且从许多来源听说它的功能也非常丰富。

查看以下站点,其中还包含一些 Cloo 示例:
http://www.cmsoft.com.br/

I agree with olegz answer.
I've only started using OpenCL but Cloo seems to be a very good choice. I find it quite straightforward to use and from many sources I hear that it's also very rich in functionality.

Check out the following site which also includes some examples for Cloo:
http://www.cmsoft.com.br/

眼泪也成诗 2024-11-08 06:56:22

我一直在使用 OpenCLTemplate。

您可以在这里找到很棒的教程:
http:// /www.cmsoft.com.br/index.php?option=com_content&view=category&layout=blog&id=41&Itemid=75

它对我来说效果很好。我建议你也应该看看Cloo。

I have been using OpenCLTemplate.

You can find a great tutorial here:
http://www.cmsoft.com.br/index.php?option=com_content&view=category&layout=blog&id=41&Itemid=75

It worked fine for me. I suggest you should check out Cloo also.

飞烟轻若梦 2024-11-08 06:56:22

对于 F#,我找到了这个:https://github.com/GabrieleCocco/FSCL.Compiler ( FSharp 到 OpenCL 编译器)

for F# i found this one: https://github.com/GabrieleCocco/FSCL.Compiler (FSharp to OpenCL Compiler)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文