Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linalg Refactor - CPU dot #3230

Merged
merged 10 commits into from Jun 9, 2016

Conversation

OXPHOS
Copy link
Member

@OXPHOS OXPHOS commented May 30, 2016

  • I'll separate classes into different .h and .cpp later
  • Not much work in GPU part yet.
  • Works for Eigen backend, dot(a, b)

@lambday @vigsterkr @karlnapf

@OXPHOS OXPHOS changed the title linalg - CPUdot Linalg Refactor - CPU dot May 30, 2016
@karlnapf
Copy link
Member

Cool!
I guess next step would be to test a GPU dot product, and then two cases:

  • GPU lib is available (and dot is computed on GPU after a transfer)
    • GPU lib is not available (fall back to CPU)

@lambday should also comment

struct CPU_Vector : public BaseVector<T>
{
//<SGVector<T>>* CPUptr;
SGVector<T> vec;
Copy link
Member

@lambday lambday May 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just hold a reference to the SGVector instead instead? We won't be passing this CPUVector around via any API (apart from linalg API which is internal), so an extra refcount is not really needed I think.

@lambday
Copy link
Member

lambday commented May 30, 2016

Alright this looks okay! Needs some more polishing.

Apart from what @karlnapf already mentioned,

  • Split the files, make sure it works after splitting
  • Use the pimpl pattern to remove the dependency from ViennaCL in the headers
  • Draft a small POC of how the Factory class should work. This class would be responsible for creating the instances of CPUVectors or GPUVectors. Things to keep in mind - we want the construction to be as lightweight as possible, i.e. avoid reference-counting if it is not really needed, etc
  • Change the name LinalgRefactor to something that's gonna stay. We need a global instance of that class. The methods should be state-less and thread-safe. Make sure that they are.
  • Benchmark MUST. Write a small example in which (a) we do the dot using eigen3 directly and (b) we use this linalg dot (you use benchmarking libraries google-benchmark/hayai etc) - take small to large vectors, run 1000 times, check how much we're paying for all this flexibility.

@OXPHOS
Copy link
Member Author

OXPHOS commented Jun 1, 2016

@vigsterkr @lambday There're many ways to put ifdef in .cpp for dot(). I currently didn't use opaque pointer because I can only think of Class - Member Function - Class, kinda complicated..?

But on a second thought I don't think my current implementation is interchangeable..

@lambday
Copy link
Member

lambday commented Jun 1, 2016

@OXPHOS please put one class per file. So there will be

  1. BaseVector.h
  2. CPUVector.h
  3. CPUVector.cpp
  4. GPUVector.h
  5. GPUVector.cpp
  6. Linalg.h
  7. Linalg.cpp
  8. CPUBackend.h
  9. CPUBackend.cpp
  10. GPUBackend.h
  11. GPUBackend.cpp

When you split things like that, it would be easier to refactor things with opaque ptrs.

@OXPHOS
Copy link
Member Author

OXPHOS commented Jun 1, 2016

@lambday please check. thx!

#include <shogun/lib/config.h>
#include <shogun/lib/SGVector.h>

#ifndef _BASEVECTOR_H__
Copy link
Member

@lambday lambday Jun 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get rid of the leading _. those are reserved for system headers. We should just use BASEVECTOR_H__

@OXPHOS
Copy link
Member Author

OXPHOS commented Jun 2, 2016

@lambday dunno why it's failing some tests..also this doesn't seem to be thread safe?

*/
T compute(GPU_Vector<T> a, GPU_Vector<T> b)
{
return viennacl::linalg::inner_prod(*(a.GPUptr), *(b.GPUptr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this GPUptr? It's not declared or defined in GPU_Vector class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be working with the VCLMemoryArray shared ptr thing that it has?


CPUVector(const CPUVector<T> &vector);

bool onGPU() { return false; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline bool onGPU() const
{
    return false;
}

@OXPHOS
Copy link
Member Author

OXPHOS commented Jun 8, 2016

@lambday
Copy link
Member

lambday commented Jun 8, 2016

Hi @OXPHOS

  • Doesn't matter. Use whichever you want. But license has to be there.
  • Can you bypass requiring the operator[] by casting it to viennacl vector type and using it's access operator?

@OXPHOS
Copy link
Member Author

OXPHOS commented Jun 8, 2016

@lambday both done.

@@ -37,6 +38,7 @@ namespace shogun
Version* sg_version=NULL;
CMath* sg_math=NULL;
CRandom* sg_rand=NULL;
std::unique_ptr<SGLinalg> sg_linalg(nullptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please try using shogun's Unique here? if that works then we won't need c++11 guard around all these

*
* @param linalg linalg object to use
*/
void set_global_linlg(SGLinalg* linalg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it defined somewhere? I see definition of get_global_linalg() in the cpp but not this one.

Also, maybe this is not needed. Just remove this for now :)

@lambday
Copy link
Member

lambday commented Jun 9, 2016

@OXPHOS really nice job with this :) Let me merge this for now. Travis fails seem unrelated, Plus this is a feature branch.

Check my minor comments. Maybe you can send a patch for those one later.

@lambday lambday merged commit cf33090 into shogun-toolbox:feature/linalg_refactor Jun 9, 2016
@OXPHOS OXPHOS mentioned this pull request Jun 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants