Skip to content

Non-default streams for filling matrix #32

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

Merged
merged 10 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions adaboost/core/data_structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ namespace adaboost
* @param result For storing the result.
*/
template <class data_type_vector>
void product(const Vector<data_type_vector>& vec1,
const Vector<data_type_vector>& vec2,
void product(Vector<data_type_vector>& vec1,
Vector<data_type_vector>& vec2,
data_type_vector& result);

/* @overload
Expand All @@ -189,8 +189,8 @@ namespace adaboost
* @param result A vector for storing the result.
*/
template <class data_type_vector, class data_type_matrix>
void multiply(const Vector<data_type_vector>& vec,
const Matrix<data_type_matrix>& mat,
void multiply(Vector<data_type_vector>& vec,
Matrix<data_type_matrix>& mat,
Vector<data_type_vector>& result);

/* @overload
Expand All @@ -201,8 +201,8 @@ namespace adaboost
* @param result A matrix for storing the result.
*/
template <class data_type_matrix>
void multiply(const Matrix<data_type_matrix>& mat1,
const Matrix<data_type_matrix>& mat2,
void multiply(Matrix<data_type_matrix>& mat1,
Matrix<data_type_matrix>& mat2,
Matrix<data_type_matrix>& result);

} // namespace core
Expand Down
12 changes: 6 additions & 6 deletions adaboost/core/data_structures_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ namespace adaboost
}

template <class data_type_vector>
void product(const Vector<data_type_vector>& vec1,
const Vector<data_type_vector>& vec2,
void product(Vector<data_type_vector>& vec1,
Vector<data_type_vector>& vec2,
data_type_vector& result)
{
adaboost::utils::check(vec1.get_size() == vec2.get_size(),
Expand All @@ -168,8 +168,8 @@ namespace adaboost
}

template <class data_type_vector, class data_type_matrix>
void multiply(const Vector<data_type_vector>& vec,
const Matrix<data_type_matrix>& mat,
void multiply(Vector<data_type_vector>& vec,
Matrix<data_type_matrix>& mat,
Vector<data_type_vector>& result)
{
adaboost::utils::check(vec.get_size() == mat.get_rows(),
Expand All @@ -186,8 +186,8 @@ namespace adaboost
}

template <class data_type_matrix>
void multiply(const Matrix<data_type_matrix>& mat1,
const Matrix<data_type_matrix>& mat2,
void multiply(Matrix<data_type_matrix>& mat1,
Matrix<data_type_matrix>& mat2,
Matrix<data_type_matrix>& result)
{
adaboost::utils::check(mat1.get_cols() == mat2.get_rows(),
Expand Down
8 changes: 4 additions & 4 deletions adaboost/core/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace adaboost
*/

template <class data_type_vector>
void fill(const data_type_vector value, const Vector<data_type_vector>&vec);
void fill(data_type_vector value, Vector<data_type_vector>&vec);


/*
Expand All @@ -27,7 +27,7 @@ namespace adaboost
*/

template <class data_type_matrix>
void fill(const data_type_matrix value, const Matrix<data_type_matrix>&mat);
void fill(data_type_matrix value, Matrix<data_type_matrix>&mat);


/*
Expand All @@ -51,7 +51,7 @@ namespace adaboost
template <class data_type>
void Sum(
data_type (*func_ptr)(data_type),
const Vector<data_type>& vec,
Vector<data_type>& vec,
unsigned start,
unsigned end,
data_type& result);
Expand All @@ -73,7 +73,7 @@ namespace adaboost
template <class data_type_1, class data_type_2>
void Argmax(
data_type_2 (*func_ptr)(data_type_1),
const Vector<data_type_1>& vec,
Vector<data_type_1>& vec,
data_type_1& result);

} // namespace core
Expand Down
9 changes: 4 additions & 5 deletions adaboost/core/operations_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include<adaboost/utils/utils.hpp>
#include<adaboost/core/operations.hpp>
#include<iostream>
#include<cmath>

namespace adaboost
Expand All @@ -12,15 +11,15 @@ namespace adaboost
{

template <class data_type_vector>
void fill(const data_type_vector value, const Vector<data_type_vector>&vec)
void fill(data_type_vector value, Vector<data_type_vector>&vec)
{
data_type_vector* vecPtr = vec.get_data_pointer();
std::fill(vecPtr, vecPtr + vec.get_size(), value);
}


template <class data_type_matrix>
void fill(data_type_matrix value, const Matrix<data_type_matrix>&mat)
void fill(data_type_matrix value, Matrix<data_type_matrix>&mat)
{
data_type_matrix* matPtr = mat.get_data_pointer();
std::fill(matPtr, matPtr + mat.get_rows()*mat.get_cols(), value);
Expand All @@ -30,7 +29,7 @@ namespace adaboost
template <class data_type>
void Sum(
data_type (*func_ptr)(data_type),
const Vector<data_type>& vec,
Vector<data_type>& vec,
unsigned start,
unsigned end,
data_type& result)
Expand All @@ -49,7 +48,7 @@ namespace adaboost
template <class data_type_1, class data_type_2>
void Argmax(
data_type_2 (*func_ptr)(data_type_1),
const Vector<data_type_1>& vec,
Vector<data_type_1>& vec,
data_type_1& result)
{
data_type_2 max_val = func_ptr(vec.at(0));
Expand Down
17 changes: 17 additions & 0 deletions adaboost/cuda/core/functions.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef ADABOOST_UTILS_FUNCTION_PARAMS_CU
#define ADABOOST_UTILS_FUNCTION_PARAMS_CU

namespace adaboost
{
namespace cuda
{
namespace core
{

__device__ func_t<float, float> p_func;

}
}
}

#endif
40 changes: 30 additions & 10 deletions adaboost/cuda/core/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,58 @@ namespace adaboost
* @param vec The Vector.
* @param block_size Number of threads to be launched per block on GPU.
*/

template <class data_type_vector>
void fill(const data_type_vector value, const VectorGPU<data_type_vector>&vec, unsigned block_size);
void fill(data_type_vector value, VectorGPU<data_type_vector>& vec, unsigned block_size);

/*
* This function fills the matrix with a given value.
*
* If block size x and block size y is passed 0 and 0, values are filled on CPU otherwise they are filled on GPU.
*
* @param value The value with which the matrix is to be populated.
* @param vec The Matrix.
* @param mat The Matrix.
*/

template <class data_type_matrix>
void fill(const data_type_matrix value, const MatrixGPU<data_type_matrix>&mat, unsigned block_size_x, unsigned block_size_y);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since in current function, we are only taking one parameter, it number of streams. Instead of taking block_size_x and block_size_y. So the API is different now.

Copy link
Member

Choose a reason for hiding this comment

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

Please do not deprecate APIs until utmost necessary. Please keep both APIs, we will use whatever required while implementing the AdaBoost algorithm.
Just copy the original fill and related tests function from master branch and add it to the right places to avoid conflicts. Do not modify the changes in your patch, just pick the right code from master and paste it in your branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, please have a look

void fill(data_type_matrix value, MatrixGPU<data_type_matrix>& mat, unsigned block_size_x, unsigned block_size_y);

/*
* This function fills the matrix with a given value.
*
* @param value The value with which the matrix is to be populated.
* @param mat The Matrix.
* @num_streams Number of streams being used to fill the matrix
*/
template <class data_type_matrix>
void fill(data_type_matrix value, MatrixGPU<data_type_matrix>& mat, unsigned num_streams);

/*
* This function computes
* dot product of two vectors on
* GPU.
*
* @param vec1 First vector whose product is to be calculated
* @param vec2 Second vector whose product is to be calculated
* @param result Location to store answer
* @param block_size Number of threads to be launched per block on GPU.
*/

template <class data_type_vector>
void product_gpu(const VectorGPU<data_type_vector>& vec1,
const VectorGPU<data_type_vector>& vec2,
void product_gpu(VectorGPU<data_type_vector>& vec1,
VectorGPU<data_type_vector>& vec2,
data_type_vector& result,
unsigned block_size=0);

/*
* This function computes
* dot product of two matrices on
* GPU.
*
* @param mat1 First matrix whose product is to be calculated
* @param vec2 Second matrix whose product is to be calculated
* @param result Location to store answer
*/
template <class data_type_matrix>
void multiply_gpu(const MatrixGPU<data_type_matrix>& mat1,
const MatrixGPU<data_type_matrix>& mat2,
void multiply_gpu(MatrixGPU<data_type_matrix>& mat1,
MatrixGPU<data_type_matrix>& mat2,
MatrixGPU<data_type_matrix>& result);


Expand Down
Loading