Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

package cu provides an idiomatic interface to the CUDA Driver API.

License

NotificationsYou must be signed in to change notification settings

gorgonia/cu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Packagecu is a package that interfaces with theCUDA Driver API. This package was directly inspired by Arne Vansteenkiste'scu package.

Why Write This Package?

The main reason why this package was written (as opposed to just using the already-excellentcu package) was because of errors. Specifically, the main difference between this package and Arne's package is that this package returns errors instead of panicking.

Additionally another goal for this package is to have an idiomatic interface for CUDA. For example, instead of exposingcuCtxCreate to beCtxCreate, a nicer, more idiomatic nameMakeContext is used. The primary goal is to make calling the CUDA API as comfortable as calling Go functions or methods. Additional convenience functions and methods are also created in this package in the pursuit of that goal.

Lastly, this package uses the latestCUDA toolkit whereas the original packagecu uses a number of deprecated APIs.

Installation

This package is go-gettable:go get -u gorgonia.org/cu

This package mostly depends on built-in packages. There are two external dependencies:

  • errors, which is licenced under aMIT-like licence. This package is used for wrapping errors and providing a debug trail.
  • assert, which is licenced under aMIT-like licence. This package is used for quick and easy testing.

However, packagecu DOES depend on one major external dependency: CUDA. Specifically, it requires the CUDA driver. Thankfully nvidia has made this rather simple - everything that is required can be installed with one click:CUDA Toolkit.

To verify that this library works, install and run thecudatest program, which accompanies this package:

go install gorgonia.org/cu/cmd/cudatest@latestcudatest

You should see something like this if successful:

CUDA version: 10020CUDA devices: 1Device 0========Name      :"TITAN RTX"Clock Rate:1770000 kHzMemory    :25393561600 bytesCompute   : 7.5

Windows

To setup CUDA in Windows:

  1. Install CUDA Toolkit
  2. Add%CUDA_PATH%/bin to your%PATH% environment variable (runningnvcc from console should work)
  3. Make a symlinkmklink /D C:\cuda "c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA" (alternatively, install CUDA toolkit toC:\cuda\)

To setup the compiler chain (MSYS2):

  1. Install MSYS2 (seehttps://www.msys2.org/)
  2. Inc:\msys64\msys2_shell.cmd uncomment the line withset MSYS2_PATH_TYPE=inherit (this makes Windows PATH variable visible)
  3. Installgo in MSYS2 (64 bit) withpacman -S go

Alternatively, if you already have Go setup and only need to install cgo dependencies:

  1. Install TDM-GCC (seehttps://jmeubank.github.io/tdm-gcc/download/)
  2. Ensuregcc is in%PATH% environment variable (runninggcc from console should work)

FAQ

Here is a common list of problems that you may encounter.

ld: cannot find -lcuda (Linux)

Checklist:

  • Installed CUDA and applied the relevantpost-installation steps?
  • Checked that the sample programs in the CUDA install all works?
  • Checked the output ofld -lcuda --verbose?
  • Checked that there is alibcuda.so in the given search paths?
  • Checked that the permissions onlibcuda.so is correct?

Note, depending on how you install CUDA on Linux, sometimes the.so file is not properly linked. For example: in CUDA 10.2 on Ubuntu, the default.deb installation installs the shared object file to/usr/lib/x86_64-linux-gnu/libcuda.so.1. Howeverld searches only forlibcuda.so. So the solution is to symlinklibcuda.so.1 tolibcuda.so, like so:

sudo ln -s /PATH/TO/libcuda.so.1 /PATH/TO/libcuda.so

Be careful when usingln. This author spent several hours being tripped up by permissions issues.

Progress

The work to fully represent the CUDA Driver API is a work in progress. At the moment, it is not complete. However, most of the API that are required for GPGPU purposes are complete. None of the texture, surface and graphics related APIs are handled yet. Please feel free to send a pull request.

Roadmap

  • Remaining API to be ported over
  • All texture, surface and graphics related API have an equivalent Go prototype.
  • Batching of common operations (see for exampleDevice.Attributes(...)
  • Generic queueing/batching of API calls (by some definition of generic)

Contributing

This author loves pull requests from everyone. Here's how to contribute to this package:

  1. Fork then clone this repo:git clone git@github.com:YOUR_USERNAME/cu.git
  2. Work on your edits.
  3. Commit with a good commit message.
  4. Push to your fork thensubmit a pull request.

We understand that this package is an interfacing package with a third party API. As such, tests may not always be viable. However, please do try to include as much tests as possible.

Licence

The package is licenced with a MIT-like licence. Ther is one file (cgoflags.go) where code is directly copied and two files (execution.go andmemory.go) where code was partially copied from Arne Vansteenkiste's package, which is unlicenced (but to be safe, just assume a GPL-like licence, asmumax/3 is licenced under GPL).


[8]ページ先頭

©2009-2025 Movatter.jp