GithubHelp home page GithubHelp logo

nimcl's Introduction

Nim OpenCL utilities

This is an attempt at a high level wrapper over OpenCL.

For now, things are added when needed and as such, they may not be perfectly coherent. Still, they should be enough to cover the simplest cases and get started.

Some API changes can also be expected as the library becomes more comprehensive.

Vector add example

The "hello, world!" of OpenCL:

const
  body = staticRead("vadd.cl")
  size = 1_000_000
var
  a = newSeq[float32](size)
  b = newSeq[float32](size)
  c = newSeq[float32](size)

for i in 0 .. a.high:
  a[i] = i.float32
  b[i] = (i * i).float32

let
  (device, context, queue) = singleDeviceDefaults()
  program = context.createAndBuild(body, device)
  add = program.createKernel("add_vector")
  gpuA = context.bufferLike(a)
  gpuB = context.bufferLike(b)
  gpuC = context.bufferLike(c)

add.args(gpuA, gpuB, gpuC, size.int32)

queue.write(a, gpuA)
queue.write(b, gpuB)
queue.run(add, size)
queue.read(c, gpuC)

echo c[1 .. 100]

# Clean up
release(queue)
release(add)
release(program)
release(gpuA)
release(gpuB)
release(gpuC)
release(context)

The kernel is just

__kernel void add_vector(__global float* a, __global float* b, __global float* c, int num_els) {
  int idx = get_global_id(0);
  if (idx < num_els) {
    c[idx] = a[idx] + b[idx];
  }
}

nimcl's People

Contributors

andreaferretti avatar mratsim avatar vindaar avatar zedeus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nimcl's Issues

`nimble install nimcl` fails

Just tried installing arraymancer which tried to install this package. Doesn't work with Nim @ #head.

# Windows

Downloading https://github.com/unicredit/nimcl using git
Error: unhandled exception: The process cannot access the file because it is being used by another process.
 [OSError]
# Linux

Downloading https://github.com/unicredit/nimcl using git
       Tip: 63 messages have been suppressed, use --verbose to show them.
     Error: Could not read package info file in /tmp/nimble_25895/githubcom_unicreditnimcl_0.1.2/nimcl.nimble;
        ...   Reading as ini file failed with:
        ...     Invalid section: .
        ...   Evaluating as NimScript file failed with:
        ...     tmp/nimble_25895/githubcom_unicreditnimcl_0.1.2/nimcl.nimble(11, 37) Error: undeclared identifier: 'stmt'.

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.