C#:在 GPU 上执行操作,而不是 CPU(计算 Pi)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1249892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:14:40  来源:igfitidea点击:

C#: Perform Operations on GPU, not CPU (Calculate Pi)

c#.netapigpu

提问by Alex

I've recently read a lot about software (mostly scientific/math and encryption related) that moves part of their calculation onto the GPU which causes a 100-1000 (!) fold increase in speed for supported operations.

我最近阅读了很多关于软件(主要是科学/数学和加密相关)的内容,这些软件将部分计算转移到 GPU 上,这会导致支持操作的速度提高 100-1000 (!) 倍。

Is there a library, API or other way to run something on the GPU via C#? I'm thinking of simple Pi calculation. I have a GeForce 8800 GTX if that's relevant at all (would prefer card independent solution though).

是否有库、API 或其他方式可以通过 C# 在 GPU 上运行某些内容?我正在考虑简单的 Pi 计算。我有一个 GeForce 8800 GTX,如果这完全相关的话(不过我更喜欢独立于卡的解决方案)。

采纳答案by Charlie Salts

It's a very new technology, but you might investigate CUDA. Since your question is tagged with C#, here is a .Net wrapper.

这是一项非常新的技术,但您可能会研究CUDA。由于您的问题是用 C# 标记的,因此这里有一个.Net 包装器

As a bonus, it appears that your 8800 GTX supports CUDA.

作为奖励,您的 8800 GTX 似乎支持 CUDA。

回答by Tchami

You might want to look at this question

你可能想看看这个问题

You're probably looking for Accelerator, but if you are interested in game development in general I'll suggest you take a look at XNA

你可能正在寻找Accelerator,但如果你对游戏开发感兴趣,我建议你看看 XNA

回答by Michael Borgwardt

CUDA.NETshould be exactly what you're looking for, and it seems to support your specific graphics card.

CUDA.NET应该正是您要找的,而且它似乎支持您的特定显卡。

回答by Malte Clasen

You can access the latest Direct3D APIs from .NET using the Windows API Code Pack. Direct3D 11 comes with Compute Shaders. These are roughly comparable to CUDA, but work also on non-NVIDIA GPUs.

您可以使用Windows API 代码包从 .NET 访问最新的 Direct3D API 。Direct3D 11 带有计算着色器。这些与 CUDA 大致相当,但也适用于非 NVIDIA GPU。

Note that Managed DirectX and XNA are limited to the Direct3D 9 feature set, which is somewhat difficult to use for GPGPU.

请注意,托管 DirectX 和 XNA 仅限于 Direct3D 9 功能集,这对于 GPGPU 使用有些困难。

回答by Darwyn

There is a set of .Net bindings for Nvidia's CUDA api, it's called CUDA.net. You can refer to the reference guideto look at some sample C# code.

Nvidia 的 CUDA api 有一组 .Net 绑定,称为CUDA.net。您可以参考参考指南来查看一些示例 C# 代码。

The preferred way to access your co-proccesor (GPU) would be using OpenCLso that your code would be portable with ATI cards, but I believe there may be additional coding required and I'm not sure how much support OpenCL has for the .Net platform.

访问协处理器 (GPU) 的首选方法是使用OpenCL,以便您的代码可以通过 ATI 卡移植,但我相信可能需要额外的编码,我不确定 OpenCL 对 .网络平台。

If you want to use C++, here's a quick overviewon how to get some sample code compiling with Visual Studio.

如果你想使用 C++,这里有一个关于如何使用 Visual Studio 编译一些示例代码的快速概述

回答by Reed Copsey

Another option that hasn't been mentioned for GPU calculation from C# is Brahma.

在 C# 中的 GPU 计算中没有提到的另一个选项是Brahma

Brahmaprovides a LINQ-based abstraction for GPU calculations - it's basically LINQ to GPU. It works over OpenGL and DirectX without extra libraries (but requires SM3). Some of the samples are fairly amazing.

Brahma为 GPU 计算提供了一个基于 LINQ 的抽象——它基本上是 LINQ to GPU。它无需额外的库即可在 OpenGL 和 DirectX 上运行(但需要 SM3)。有些样品相当惊人。

回答by Alex

FYI: Accelerator (http://research.microsoft.com/en-us/projects/Accelerator/) was working great for a couple of tests.

仅供参考:Accelerator ( http://research.microsoft.com/en-us/projects/Accelerator/) 在几个测试中运行良好。