Skip to content

Instantly share code, notes, and snippets.

@OXPHOS
Created May 31, 2016 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OXPHOS/42f06dfc38325399982faf2f9468b7fa to your computer and use it in GitHub Desktop.
Save OXPHOS/42f06dfc38325399982faf2f9468b7fa to your computer and use it in GitHub Desktop.
#include <shogun/lib/config.h>
#include <shogun/mathematics/linalg/linalgRefactor.h>
#include <shogun/lib/SGVector.h>
#include <shogun/mathematics/eigen3.h>
#include <iostream>
#include <memory>
template <class T> CPU_Vector<T>::CPU_Vector(const SGVector<T> &vector)
{
CPUptr = const_cast<SGVector<T>*>(&vector);
}
template <class T> struct GPU_Vector<T>::GPUArray
{
#ifdef HAVE_VIENNACL
std::shared_ptr<VCLMemoryArray> ptr;
//#elif HAVE_CUDA
// shared_ptr<CUDAArray> ptr;
#else
T temp;
std::shared_ptr<void> ptr;
#endif
};
template <class T> GPU_Vector<T>::GPU_Vector(const SGVector<T> &vector)
//:gpuarray(std::unique_ptr<GPUArray>(new GPUArray()))
{
gpuarray = SG_MALLOC(GPUArray, 1);
#ifdef HAVE_VIENNACL
// *gpuarray.ptr = ;
//#elif HAVE_CUDA
// *gpuarray.ptr = ;
#else
throw std::runtime_error("Unable to locate GPU support libraries.");
#endif
}
template <class T> GPU_Vector<T>::~GPU_Vector()
{
SG_FREE(gpuarray);
}
template struct GPU_Vector<bool>;
template struct GPU_Vector<char>;
template struct GPU_Vector<int8_t>;
template struct GPU_Vector<uint8_t>;
template struct GPU_Vector<int16_t>;
template struct GPU_Vector<uint16_t>;
template struct GPU_Vector<int32_t>;
template struct GPU_Vector<uint32_t>;
template struct GPU_Vector<int64_t>;
template struct GPU_Vector<uint64_t>;
template struct GPU_Vector<float32_t>;
template struct GPU_Vector<float64_t>;
template struct GPU_Vector<floatmax_t>;
template struct GPU_Vector<complex128_t>;
template struct CPU_Vector<bool>;
template struct CPU_Vector<char>;
template struct CPU_Vector<int8_t>;
template struct CPU_Vector<uint8_t>;
template struct CPU_Vector<int16_t>;
template struct CPU_Vector<uint16_t>;
template struct CPU_Vector<int32_t>;
template struct CPU_Vector<uint32_t>;
template struct CPU_Vector<int64_t>;
template struct CPU_Vector<uint64_t>;
template struct CPU_Vector<float32_t>;
template struct CPU_Vector<float64_t>;
template struct CPU_Vector<floatmax_t>;
template struct CPU_Vector<complex128_t>;
#include <shogun/lib/config.h>
#include <shogun/lib/SGVector.h>
#include <shogun/mathematics/eigen3.h>
#include <iostream>
#include <memory>
using namespace shogun;
template <class T>
struct BaseVector
{
BaseVector(){ }
virtual bool onGPU() = 0;
};
template <class T>
struct CPU_Vector : public BaseVector<T>
{
SGVector<T>* CPUptr;
CPU_Vector(const SGVector<T>& vector);
bool onGPU() { return false; }
};
template <class T> struct GPU_Vector : public BaseVector<T>
{
private:
struct GPUArray;
//std::unique_ptr<GPUArray> gpuarray;
GPUArray* gpuarray;
public:
GPU_Vector(const SGVector<T> &vector);
bool onGPU() { return true; }
~GPU_Vector();
};
using namespace shogun;
TEST(LinalgRefactor, split_header_and_cpp)
{
const index_t size = 10;
SGVector<int32_t> a(size);
for (index_t i = 0; i < size; ++i) a[i] = i;
GPU_Vector<int32_t> a_GPU(a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment