-
Notifications
You must be signed in to change notification settings - Fork 0
Home
keveman edited this page Nov 14, 2010
·
36 revisions
Carbon is a simple language embedded in C++. The syntax is a subset of Boost.Phoenix. Carbon has been implemented with Thrust in mind. Therefore its main purpose is to act as a lambda library for Thrust. Carbon makes it more convenient to specify simple functors as arguments to Thrust functions like thrust::transform and thrust::reduce. Here is an example :
SAXPY without Carbon
struct saxpy_functor : public thrust::binary_function<float,float,float>
{
const float a;
saxpy_functor(float _a) : a(_a) {}
__host__ __device__
float operator()(const float& x, const float& y) const {
return a * x + y;
}
};
void saxpy_fast(float A, thrust::device_vector<float>& X, thrust::device_vector<float>& Y)
{
// Y <- A * X + Y
thrust::transform(X.begin(), X.end(), Y.begin(), Y.begin(), saxpy_functor(A));
}
struct saxpy_functor : public thrust::binary_function<float,float,float>
{
const float a;
saxpy_functor(float _a) : a(_a) {}
__host__ __device__
float operator()(const float& x, const float& y) const {
return a * x + y;
}
};
void saxpy_fast(float A, thrust::device_vector<float>& X, thrust::device_vector<float>& Y)
{
// Y <- A * X + Y
thrust::transform(X.begin(), X.end(), Y.begin(), Y.begin(), saxpy_functor(A));
}