Skip to content

Instantly share code, notes, and snippets.

@OXPHOS
Created May 24, 2016 14:24
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/16c7a4d31cb4f5553fd8e7bc70ca5114 to your computer and use it in GitHub Desktop.
Save OXPHOS/16c7a4d31cb4f5553fd8e7bc70ca5114 to your computer and use it in GitHub Desktop.
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