• Stars
    star
    468
  • Rank 93,767 (Top 2 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

cu GoDoc

Package cu is a package that interfaces with the CUDA Driver API. This package was directly inspired by Arne Vansteenkiste's cu package.

Why Write This Package?

The main reason why this package was written (as opposed to just using the already-excellent cu 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 exposing cuCtxCreate to be CtxCreate, a nicer, more idiomatic name MakeContext 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 latest CUDA toolkit whereas the original package cu 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 a MIT-like licence. This package is used for wrapping errors and providing a debug trail.
  • assert, which is licenced under a MIT-like licence. This package is used for quick and easy testing.

However, package cu 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 the cudatest program, which accompanies this package:

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

You should see something like this if successful:

CUDA version: 10020
CUDA devices: 1

Device 0
========
Name      :	"TITAN RTX"
Clock Rate:	1770000 kHz
Memory    :	25393561600 bytes
Compute   : 	7.5

Windows

To setup CUDA in Windows:

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

To setup the compiler:

  1. Install MSYS2 (see https://www.msys2.org/)
  2. In c:\msys64\msys2_shell.cmd uncomment the line with set MSYS2_PATH_TYPE=inherit (this makes Windows PATH variable visible)
  3. Install go in MSYS2 (64 bit) with pacman -S go

FAQ

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

ld: cannot find -lcuda (Linux)

Checklist:

  • Installed CUDA and applied the relevant post-installation steps?
  • Checked that the sample programs in the CUDA install all works?
  • Checked the output of ld -lcuda --verbose?
  • Checked that there is a libcuda.so in the given search paths?
  • Checked that the permissions on libcuda.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. However ld searches only for libcuda.so. So the solution is to symlink libcuda.so.1 to libcuda.so, like so:

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

Be careful when using ln. 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 example Device.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 [email protected]:YOUR_USERNAME/cu.git
  2. Work on your edits.
  3. Commit with a good commit message.
  4. Push to your fork then submit 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 and memory.go) where code was partially copied from Arne Vansteenkiste's package, which is unlicenced (but to be safe, just assume a GPL-like licence, as mumax/3 is licenced under GPL).

More Repositories

1

gorgonia

Gorgonia is a library that helps facilitate machine learning in Go.
Go
5,520
star
2

tensor

package tensor provides efficient and generic n-dimensional arrays in Go that are useful for machine learning and deep learning purposes
Go
313
star
3

agogo

A reimplementation of AlphaGo in Go (specifically AlphaZero)
Go
207
star
4

golgi

Golgi is a library built on top of Gorgonia that provides neural network components
Go
39
star
5

bindgen

libbindgen is a package that generates bindings and idiomatic Go interfaces to C-libraries
Go
27
star
6

vecf64

package vecf64 provides common functions and methods for slices of float64
Assembly
21
star
7

gorgonia.github.io

The source code (and website) for gorgonia.org
CSS
13
star
8

vecf32

Package vecf32 provides common functions and methods for slices of float32
Assembly
11
star
9

parser

A simple parser that turns a formulae written in unicode into an ExprGraph
Go
10
star
10

vulkan

Vulkan back-end for Gorgonia (early development)
Go
8
star
11

examples

Examples of neural networks and other things written in Gorgonia
5
star
12

qol

Neural Network Quality of Life Stuff
Go
5
star
13

shapes

Package shapes provides an algebra for handling shapes
Go
4
star
14

dawson

package dawson is a package that provides utilities for testing involving floats
Go
3
star
15

exp

experimental things for Gorgonia, to sketch things out
Go
3
star
16

randomkit

randomkit is a repository for random number generation.
Go
2
star
17

dev

Scripts and helpers for developing Gorgonia
Shell
2
star
18

internal

internal use libraries
Go
1
star
19

dtype

Package dtype provides a definition of a Dtype, which is a part of the type system that Gorgonia uses.
Go
1
star