Code Monkey home page Code Monkey logo

cudapp's Introduction

cuda++

cuda++ is an easy-to-use wrapper for the CUDA C API.

1) Samples

There's no documentation yet, but see below for some examples of how cuda++ makes your life easier. You can also browse the source code which is easy to understand and neatly commented.

// Device properties and routines are neatly wrapped
//
cuda::initialize( cuda::device::count - 1 );
// Modern exception handling
//
try
{
	float* ptr = nullptr;
	
	cuda::run<dimt<1>>( [ = ] __device__() 
	{ 
		*ptr = 0; 
	} );

	cuda::device::sync();
}
catch ( std::exception ex )
{
	std::cout << "Caught exception: " << ex.what();
	exit( 0 );
}
// Easily allocate shared memory
//
cuda::resource<myarray_t> output;
cuda::resource<myarray_t> myarray = cuda::make_resource<myarray_t>( { 1.0f, 2.0f } );

cuda::resource<float> carray( 2 );
carray[ 0 ] = 10.0f;
carray[ 1 ] = 5.0f;
carray >> cuda::gpu;
// Simple to run kernels with built-in work distribution
//
float* d_a = !carray;
myarray_t* d_b = !myarray;
myarray_t* d_o = !output;

cuda::run<dimt<2>>( [ = ] __device__()
{
	auto idx = cuda::work_idx();
	printf( "[%d] Hello from GPU!\n", idx.x );
	d_o->raw[ idx.x ] = d_a[ idx.x ] * d_b->raw[ idx.x ];
} );

output << cuda::gpu;
printf( "[%f, %f] * [%f, %f] = [%f, %f]\n", carray[ 0 ], carray[ 1 ], myarray->a, myarray->b, output->a, output->b );

2) Requirements

--extended-lambda must be added as an additional option to the CUDA C/C++ compiler.

cudapp's People

Contributors

can1357 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.