Created
May 24, 2016 14:24
-
-
Save OXPHOS/16c7a4d31cb4f5553fd8e7bc70ca5114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace linalg | |
{ | |
// Always return CPU T type | |
template<class T> | |
T dot(SGVector<T> a, SGVector<T> b) | |
{ | |
Base<T> base_a = factory(a); // Factory: use ifdef to check if GPUbackend exists and GPU is turned on | |
Base<T> base_b = factory(b); | |
return base_a.dot(base_b) | |
} | |
template<class T> | |
T dot(Base<T> a, Base<T> b) | |
} | |
template<class T> | |
class Base | |
{ | |
Base(SGVector<T> x) | |
{ | |
//convert and save x | |
//doesn't need to do anything here | |
} | |
virtual T dot(Base y) | |
{ | |
return T(0); | |
} | |
}; | |
//////////////Backends//////////////// | |
//GPU class | |
template<class T> | |
class DeriveA: public Base | |
{ | |
gpu_ptr *m_data; | |
DeriveA(SGVector<T> x) | |
{ | |
//Send x to GPU | |
//get gpu_ptr | |
} | |
T dot(DeriveA& y) | |
{ | |
//Actually do the work | |
} | |
T dot(Base& y) | |
{ | |
try | |
{ | |
DerivedA d_y = dynamic_cast<DerivedA&>(y); | |
return dot(d_y); | |
} | |
catch() | |
{ | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment