Git Product home page Git Product logo

hybridizer-basic-samples's Introduction

Hybridizer Essentials is a compiler targeting CUDA-enabled GPUS from .Net. Using parallelization patterns, such as Parallel.For, or ditributing parallel work by hand, the user can benefit from the compute power of GPUS without entering the learning curve of CUDA, all within Visual Studio.

hybridizer-basic-samples

This repo illustrates a few samples for Hybridizer

These samples may be used with Hybridizer Essentials. However, C# code can run with any version of Hybridizer. They illustrate features of the solution and are a good starting point for experimenting and developing software based on Hybridizer.

All new code is added to the repo of the latest CUDA version (currently 10.0). Older CUDA versions are still supported, but don't get the new samples.

WARNING

CUDA 9/9.1/9.2 and the latest update of visual studio do not work together (v141 toolset). see devtalk.nvidia.com. Install the v140 toolset before trying to compile samples with visual 2017, or use CUDA 10.0

Requirements

Before you start, you first need to check if you have the right environment. You need an install of Visual Studio (2012 or later). You need a CUDA-enabled GPU and CUDA (8.0 or later) installed (with the CUDA driver). Obviously, you need to install Hybridizer Essentials.

Run

Checkout repository, and open Visual Studio. Require and validate license from Hybridizer->License Settings Tool window. Open HybridizerBasicSamples solution. Build solution and run example of your choice. After an update, you might need to reload the solution.

Example

using System;
using System.Linq;
using System.Threading.Tasks;

using Hybridizer.Runtime.CUDAImports;

namespace HybridizerExample
{
    class Program
    {
        [EntryPoint]
        public static void Add(float[] a, float[] b, int N)
        {
            Parallel.For(0, N, i => a[i] += b[i]);
        }

        static void Main(string[] args)
        {
            // Arrange
            const int N = 1024 * 1024 * 32;
            float[] a = Enumerable.Range(0, N).Select(i => (float)i).ToArray();
            float[] b = Enumerable.Range(0, N).Select(i => 1.0F).ToArray();

            // Run
            HybRunner.Cuda().Wrap(new Program()).Add(a, b, N);

            cuda.DeviceSynchronize();


            // Assert
            for(int i = 0; i < N; ++i)
            {
                if(a[i] != (float)i + 1.0F)
                {
                    Console.Error.WriteLine("Error at {0} : {1} != {2}", i, a[i], (float)i + 1.0F);
                    Environment.Exit(6); // abort
                }
            }

            Console.Out.WriteLine("OK");
        }
    }
}
hybridizer-cuda Program.cs -o a.exe -run

OK

Documentation

Samples are explained in the wiki.

You can find API documentation in our DocFX generated documentation

Notes

After building the csproj, you have to build the generated vcxproj manually or put it in your build dependencies using the configuration manager. After installing an update, you may need to unload/reload the solution, or even close and restart visual studio.

hybridizer-basic-samples's People

Contributors

axelanglet avatar fduguet avatar regisp avatar

Watchers

James Cloos avatar

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.