通过 c# 使用 GPU

发布于 2024-07-11 05:56:59 字数 1815 浏览 8 评论 0原文

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

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

发布评论

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

评论(13

胡大本事 2024-07-18 05:57:00

[编辑 2017 年 10 月,因为这个答案已经很旧了]

这些答案中的大多数都已经很旧了,所以我想我应该给出我认为每个项目的最新摘要:

  • GPU.Net (TidePowerd) - 我在 6 个月前尝试过这个,并且确实得到了虽然需要一些工作,但它确实有效。 在编译时将 C# 内核代码转换为 cuda。 不幸的是,他们的网站已经关闭,他们的 github 已经好几年没有更新了,这可能表明该项目已经死了……

  • Cudafy - 开源且非常易于使用。 在运行时将 C# 内核代码转换为 cuda(具有序列化和缓存的能力)。 可以轻松地在CPU上运行相同的内核代码(主要用于调试)。 支持多个 GPU。 这里提供的示例比其他示例更多。 其他答案引用的样板代码很少,就我而言,至少有助于我理解代码的工作原理。 不过仅限 Cuda/Nvidia。 不幸的是,他们似乎也有几年没有更新他们的解决方案(2015 年最新提交——支持 cuda 7.0)。

  • 混合器。 将 C# 编译为 CUDA 的商业解决方案。 在 Visual Studio 市场 上提供免费社区版,并在 github

  • AleaGPU 商业解决方案,为消费类 GPU 提供免费社区版本。 详情请参阅丹尼尔的评论。

  • Brahma - 通过 OpenCL 运行 LINQ 表达式(因此也支持 AMD)。 没有太多文档/示例。 最后更新于 2011 年。

  • C$ - 上次开发是在 10 多年前...

  • Microsoft Accelerator - 同样看起来它不再被积极开发。

  • 其他一些(C++ AMPOpenTK -- 已死/Cloo) - 其中许多只是绑定 - 即使您能够从 C# 调用 GPU,但是您的内核代码(实际在 GPU 上运行的代码)需要用 C 或 OpenCL 编写,这意味着您必须使用(并学习)另一种语言。

正如我所说,我会推荐 Cudafy,而不是其他所有软件 - 如果它可以在 OpenCL 和 Cuda 上运行,那就完美了。

2013 年 9 月编辑
Cudafy 现在允许您针对 CUDA 和 OpenCL 进行编译,因此将在所有 GPU 上运行相同的 C# 代码。 这听起来棒极了,尽管我还没有测试过 OpenCL 编译。

[Edit OCT 2017 as even this answer gets quite old]

Most of these answers are quite old, so I thought I'd give an updated summary of where I think each project is:

  • GPU.Net (TidePowerd) - I tried this 6 months ago or so, and did get it working though it took a little bit of work. Converts C# kernel code to cuda at compile time. Unfortunately their website has been down and their github hasn't been updated for a couple of years, which might indicate the project is dead....

  • Cudafy - Open source and very easy to use. Converts C# kernel code to cuda at runtime (with ability to serialize and cache). Can easily run the same kernel code on the CPU (mostly for debugging). Supports multiple GPUs. More examples available than others here. The boilerplate code referred to by other answers is minimal, and in my case at least helped with my understanding of how the code works. Cuda/Nvidia only though. Unfortunately, it seems that they didn't update their solutions for a couple of years too (latest commit in 2015 -- support of cuda 7.0).

  • Hybridizer. Commercial solution compiling C# to CUDA. Provides a free community edition on visual studio marketplace and samples on github.

  • AleaGPU Commercial solution with a free community edition for consumer GPUS. See Daniel's comments for details.

  • Brahma - runs LINQ expressions via OpenCL (so supports AMD too). Not much documentation / examples. Last update in 2011.

  • C$ - last development was over 10 years ago...

  • Microsoft Accelerator - similarly doesn't look like it is being actively developed any longer.

  • some others (C++ AMP, OpenTK -- dead/Cloo) - many of these are just bindings - ie enable you to call the GPU from C#, but your kernel code (code which is actually run on the GPU) needs to be written in C or OpenCL, meaning you must use (and learn) another language.

As I said, I would recommend Cudafy over all the others - if it could run on OpenCL as well as Cuda it would be perfect.

EDIT SEP 2013
Cudafy now allows you to compile for both CUDA and OpenCL, so will run the same C# code on on all GPUs. This sounds fantastic, though I haven't tested the OpenCL compiling yet.

雪花飘飘的天空 2024-07-18 05:57:00

Microsoft Research Accelerator was a .NET GP GPU library.

小…红帽 2024-07-18 05:57:00

我发现 Brahma...它还有一个 GPGPU 提供程序,允许方法在GPU...谢谢你的问题...今天学到了一些新东西。 :)

I found Brahma... It also has a GPGPU provider that allows methods to run on the GPU... Thanks for the question... Learnt something new today. :)

此刻的回忆 2024-07-18 05:57:00

这是另一个:CUDAfy。 这听起来像 GPU.Net,因为像方法属性这样简单的东西就可以导致整个方法在 GPU 上运行。 但与 GPU.Net 不同的是,CUDAfy 是免费且开源的。

GPU.Net 似乎不需要样板代码(根据他们的文档,它是“由构建工具自动注入的”),而 CUDAfy 则需要。


这里是构建与 CUDAfy 的应用程序。

Here's another one: CUDAfy. It sounds like GPU.Net, in that something as simple as a method-attribute can cause the entire method to run on the GPU. But unlike GPU.Net, CUDAfy is free and open-source.

GPU.Net appears to require no boilerplate code, though (According to their docs, it's "injected automatically by the build-tool"), while CUDAfy does.


Here is an example of building an application with CUDAfy.

暖伴 2024-07-18 05:57:00

我可以推荐 XNA Game Studio 作为可能的探索途径吗? 它显然是为编写游戏而准备的,但它可以让您对图形卡进行托管访问,并且比以前在 Managed DirectX 中提供的功能更好地访问功能枚举函数和着色器开发。 还有一些方法可以将 WinForms 和 XNA 组合到混合应用程序中:

http://www.ziggyware。 com/news.php?readmore=866

您必须付出一些努力来学习着色器编程(XNA 支持 HLSL),但这可能是比学习特定于供应商的解决方案(例如 nVidia 的 CUDA)更简单的方法。 优点是您可以在 100% 托管的环境中进行编程。 以下是一些 HLSL 链接:

http://www.ziggyware.com/weblinks.php?cat_id =9

GPGPU 站点也是通用 GPU 编程的推荐目的地:

http://gpgpu.org/

祝你好运!

Could I recommend XNA Game Studio as a possible avenue for exploration? It is obviously geared up for writing games, but gives you managed access to your graphics card and much better access to capability enumeration functions and shader development than was previously available in, say, Managed DirectX. There are also ways of combining WinForms and XNA into hybrid applications:

http://www.ziggyware.com/news.php?readmore=866

You'll have to put some effort into learning shader programming (XNA supports HLSL), but this may be a simpler approach than learning a vendor-specific solution such as nVidia's CUDA. The advantage is that you can program in a 100% managed environment. Here are some HLSL links:

http://www.ziggyware.com/weblinks.php?cat_id=9

The GPGPU site is also a recommended destination for general purpose GPU programming:

http://gpgpu.org/

Best of luck!

天暗了我发光 2024-07-18 05:57:00

嗯,这是一个相当老的问题,自从被问到以来,事情发生了很大的变化。
使用 .Net 编写 GPU 代码的另一种选择,在 Alea GPU 的答案中没有人提到。 它涵盖了 C#、F# 和 VB。

适用于.NET和Mono的专业GPU软件开发环境。
真正的跨平台

在 F# 官方网站中,Alea 是在 GPGPU 编程中使用 F# 的第一选择。< br>
要了解这个框架,我建议查看其完整的示例列表。

Well this is a pretty old question, and since it's been asked things have changed a lot.
Another option for using .Net to write GPU code, which no one has mentioned in answers in Alea GPU. It covers C#, F# and VB.

Professional GPU software development environment for .NET and Mono.
Truly cross-platform

In F# official site, Alea is the first option for using F# in GPGPU programming.
To get to know this framework I suggest take a look at its comprehensive list of examples.

溺孤伤于心 2024-07-18 05:57:00

除了 Brahma 之外,还可以看看 C$(发音为“C Bucks”)。 从他们的 CodePlex 网站

[C$] 的目标是创建一种统一的语言和系统,以便在现代 GPU 和 CPU 上进行无缝并行编程。

它基于 C#,延迟评估,并针对多个加速器模型:

目前列表
预期架构包括 GPU、
多核 CPU、多 GPU(SLI、
CrossFire)和多 GPU + 多 CPU
混合架构。

In addition to Brahma, take a look at C$ (pronounced "C Bucks"). From their CodePlex site:

The aim of [C$] is creating a unified language and system for seamless parallel programming on modern GPU's and CPU's.

It's based on C#, evaluated lazily, and targets multiple accelerator models:

Currently the list of
intended architectures includes GPU,
Multi-core CPU, Multi-GPU (SLI,
CrossFire), and Multi-GPU + Multi-CPU
Hybrid Architecture.

冬天的雪花 2024-07-18 05:57:00

有一个新的 Microsoft 解决方案 - C++ AMP(简介 此处)。

从 C# 中使用将通过 P/Invoke,如演示的 这里适用于桌面应用程序,以及此处 用于(不要称呼它)Metro 应用程序。

编辑:我应该注意到,C++ AMP 有一个 开放规范,这意味着它不一定仅适用于 MS 编译器,或仅适用于 Windows。

编辑:显然,该技术现在处于“维护模式”, 意味着他们正在修复错误,但不积极开发。

There's a new Microsoft solution in town - C++ AMP (intro here).

Use from C# would be via P/Invoke, as demoed here for desktop apps, and here for (don't-call-it) Metro apps.

Edit: I should note that C++ AMP has an open specification, which means it's not necessarily just for the MS compiler, or just for Windows.

Edit: Apparently, the technology is now in "maintenance mode," meaning they're fixing bugs, but not actively developing.

心舞飞扬 2024-07-18 05:57:00

如果您的 GPU 都是同一品牌,您也许可以通过 Nvidia 的 CUDA 或 ATI 的 Stream 从供应商处获得 GPGPU 支持。 AFAIK,他们提供了 DLL,您可以通过 P/Invoke 使用它们。

If your GPUs are all the same brand, you might be able to get GPGPU support from the vendor, either through Nvidia's CUDA or ATI's Stream. AFAIK, they provide DLLs, which you could use through P/Invoke.

盗琴音 2024-07-18 05:57:00

CenterSpace Software 在其 NMath 库中提供 GPU 支持的计算,您可以将其添加到 C# 项目中。 这是一个商业产品。

CenterSpace Software has GPU-powered computation in their NMath libraries you can add to C# project. It's a commercial product.

南冥有猫 2024-07-18 05:57:00

以某种方式管理 DirectX,可能会起作用

Managed DirectX somehow, might work

唠甜嗑 2024-07-18 05:57:00

WPF 还使用 GPU,您可以使用 HLSL 添加自定义着色器。

WPF also uses the GPU and you can add custom shaders using HLSL.

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