Quantitative Analysis
Parallel Processing
Numerical Analysis
C++ Multithreading
Python for Excel
Python Utilities
Services
Author

I. Introduction into GPU programming.
II. Exception safe dynamic memory handling in Cuda project.
1. Allocating and deallocating device memory. ots::cuda::memory::Device class.
2. Accessing device memory. ots::cuda::memory::Host class.
3. Crossing host/device boundary. ots::cuda::memory::DeviceHandler class.
4. Accessing memory in __device__ code. ots::cuda::memory::Block class.
5. Handling two dimensional memory blocks. Do not use cudaMallocPitch.
6. Allocation of memory from Host scope.
7. Tagged data. Compiler assisted data verification.
III. Calculation of partial sums in parallel.
IV. Manipulation of piecewise polynomial functions in parallel.
V. Manipulation of localized piecewise polynomial functions in parallel.
Downloads. Index. Contents.

Accessing device memory. ots::cuda::memory::Host class.


he Host class is responsible for allocating/deallocating a block of memory on host. The motivation for existence is discussed in the previous section. The following is a partial code.

template <typename dataType>

class Host

{

public:

typedef typename Index::type index;

private:

class Impl : boost::noncopyable

{

private:

index theSize;

dataType* theData;

void init( index size );

void destroy();

public:

Impl() : theSize(0),theData(NULL) {}

explicit Impl( index size ) : theSize(0),theData(NULL) { init(size); }

explicit Impl( const boost::python::object& x ) : theSize(0),theData(NULL) { init(x); }

~Impl() { destroy(); }

void put( index at, dataType x );

dataType get( index at ) const;

void copyFrom( const Device<dataType>& x )

};

boost::shared_ptr<Impl> theImpl;

public:

explicit Host( index size ) : theImpl(new Impl(size)) {}

Host() : theImpl(new Impl()) {}

Host( const Host& x ) : theImpl(x.theImpl) {}

Host& operator=( const Host& x ) { theImpl=x.theImpl; return *this; }

void copyFrom( const Host<dataType>& x ) { theImpl=x.theImpl; }

void copyFrom( const Device<dataType>& x ) { theImpl->copyFrom(x); }

void put( index at, dataType x ) { theImpl->put(at,x); }

dataType get( index at ) const { return theImpl->get(at); }

void dispose() { theImpl=boost::shared_ptr<Impl>(new Impl()); }

};

This is a standard bridge pattern implementation of a handler to be passed by value. The pointer theData holds a host-based address of a memory block.

We use this class to pass values into the function Device::copyFrom. The alternative use is to read data from Device by using the function Host::copyFrom.





Downloads. Index. Contents.


















Copyright 2007