We are pleased to announce the first release of Komrade, an open-source high-level template library for developing CUDA applications with an interface similar to the C++ Standard Template Library (STL). We believe Komrade can enhance developer productivity without sacrificing speed or flexibility.
The komrade::host_vector and komrade::device_vector containers simplify memory management and transfers between host and device. Komrade provides efficient templated algorithms for:
[*] sorting - komrade::sort and komrade::sort_by_key
[*] transformations - komrade::transform
[*] reductions - komrade::reduce and komrade::transform_reduce
[*] scans - komrade::inclusive_scan and komrade::transform_inclusive_scan
[*] And many more!
Refer to http://code.google.com/p/komrade/wiki/Documentation for a complete listing.
As the following example shows, Komrade applications are concise and readable.
[codebox]
#include <komrade/host_vector.h>
#include <komrade/device_vector.h>
#include <komrade/generate.h>
#include <komrade/sort.h>
int main(void)
{
// generate random data on the host
komrade::host_vector<int> h_vec(20);
komrade::generate(h_vec.begin(), h_vec.end(), rand);
// transfer to device and sort
komrade::device_vector<int> d_vec = h_vec;
komrade::sort(d_vec.begin(), d_vec.end());
return 0;
}
[/codebox]
Komrade provides high-level primitives for composing interesting computations.
This example computes the norm of a vector.
[codebox]
#include <komrade/transform_reduce.h>
#include <komrade/functional.h>
#include <komrade/device_vector.h>
#include <komrade/host_vector.h>
// square computes the square of a number f(x) → x*x
template
struct square
{
__host__ __device__
T operator()(const T& x) const {
return x * x;
}
};
int main(void)
{
// initialize host array
float x[4] = {1.0, 2.0, 3.0, 4.0};
// transfer to device
komrade::device_vector<float> d_x(x, x + 4);
// setup arguments
square<float> unary_op;
komrade::plus<float> binary_op;
float init = 0;
// compute norm
float norm = std::sqrt( komrade::transform_reduce(d_x.begin(), d_x.end(), unary_op, init, binary_op) );
std::cout << norm << std::endl;
return 0;
}
[/codebox]
Download Komrade here, and check out the tutorial to get started.
Komrade is open source under the Apache 2.0 license and available now @ http://komrade.googlecode.com
Komrade requires CUDA 2.2 beta, which is available to registered developers. See [topic=“92580”]this thread[/topic] for details.