Giter Club home page Giter Club logo

cudanativelib.jl's Introduction

CUDAnativelib

Build status (Linux x86-64):

Based on CUDAnative.jl and Cxx.jl this package provides an interface to NVIDIA's device libraries from Julia.

It is also meant as an example on how to interface to legacy C++ CUDA from Julia on the device level.

Contributions to this package are welcomed.

CUDA support

Julia v0.6 currently uses LLVM 3.9.1, this means we only supports CUDA 7.0 & 7.5. Full CUDA 8.0 support requires at least LLVM 4.0, but we provide some compatibility headers to partially support CUDA 8 on LLVM 3.9.1. If this does not work for you we recommend to parallely install CUDA 7.X and use the environment variable CUDA_HOME to change the CUDA version CUDAnativelib uses.

Example

using CUDAdrv, CUDAnative
using CUDAnativelib
using .CURANDkernel # notice the dot prefix

function fillRandom(out)
  i = (blockIdx().x-1) * blockDim().x + threadIdx().x
  if i <= length(out)
    # Initialise state
    state = new(curandState_t)
    curand_init(0, i, 0, state) # one should use a decent seed here ;)
    @inbounds out[i] = curand_uniform(eltype(out), state) # @inbounds is optional
    delete(state)
  end
  return nothing
end

##
# Uncomment the following lines to see how the above function is lowered
# Also note how we use multiple dispatch to select the right `curand_uniform` function.
##

# code_warntype(STDOUT, fillRandom, (CuDeviceArray{Float32,1},))
# code_warntype(STDOUT, fillRandom, (CuDeviceArray{Float64,1},))

# CUDAnative.code_llvm(STDOUT, fillRandom, (CuDeviceArray{Float32,1},))
# CUDAnative.code_llvm(STDOUT, fillRandom, (CuDeviceArray{Float64,1},))

dev = CuDevice(0)
ctx = CuContext(dev)
N = 100
out = CuArray{Float32}(N)
@cuda (N,1) fillRandom(out)
c = Array(out) # force sync

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.