Skip to content

Commit a342408

Browse files
committed
Tried solving codezonediitj#10
1 parent acf949d commit a342408

5 files changed

+73
-64
lines changed

adaboost/core/data_structures_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef ADABOOST_CORE_DATA_STRUCTURES_IMPL_CPP
22
#define ADABOOST_CORE_DATA_STRUCTURES_IMPL_CPP
33

4-
#include<adaboost/core/data_structures.hpp>
5-
#include<adaboost/utils/utils.hpp>
4+
//#include<adaboost/core/data_structures.hpp>
5+
//#include<adaboost/utils/utils.hpp>
66
#include<iostream>
77

88
namespace adaboost

adaboost/core/operations.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ namespace adaboost
1616
template <class data_type_vector>
1717
void fill(data_type_vector value);
1818

19+
/*
20+
* Used for filling the vector with a given value.
21+
* If block size is passed 0 then the values are
22+
* filled on the CPU otherwise they are filled on
23+
* GPU.
24+
*
25+
* @param value The value with which the vector is
26+
* to be populated.
27+
* @param block_size The number of threads to be
28+
* launched per block on GPU.
29+
*/
30+
template <class data_type_vector>
31+
void fill(data_type_vector value,
32+
unsigned block_size=0);
33+
1934
/* @overload
2035
* Used for filling the matrix with a given value.
2136
*
@@ -25,6 +40,20 @@ namespace adaboost
2540
template <class data_type_matrix>
2641
void fill(data_type_matrix value);
2742

43+
/*
44+
* Used for filling the matrix with a given value.
45+
* If block size x and block size y is passed 0 and 0 then the values are
46+
* filled on the CPU otherwise they are filled on
47+
* GPU.
48+
*
49+
* @param value The value with which the matrix is
50+
* to be populated.
51+
*/
52+
template <class data_type_matrix>
53+
void fill(data_type_matrix value,
54+
unsigned block_size_x=0,
55+
unsigned block_size_y=0);
56+
2857
/*
2958
* This function computes the sum of
3059
* elements of the given vector and the

adaboost/core/operations_impl.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace adaboost
4848
}
4949

5050
template <class data_type_vector>
51-
void fill(data_type_vector value);
51+
void fill(data_type_vector value)
5252
{
5353
for(unsigned int i = 0; i < this->size; i++)
5454
{
@@ -58,7 +58,7 @@ namespace adaboost
5858

5959

6060
template <class data_type_matrix>
61-
void fill(data_type_matrix value);
61+
void fill(data_type_matrix value)
6262
{
6363
for(unsigned int i = 0; i < this->rows; i++)
6464
{
@@ -69,6 +69,44 @@ namespace adaboost
6969
}
7070
}
7171

72+
template <class data_type_matrix>
73+
void fill(data_type_matrix value,
74+
unsigned block_size_x=0,
75+
unsigned block_size_y=0);{
76+
if(block_size_x == 0 || block_size_y == 0)
77+
{
78+
this->adaboost::core::Matrix<data_type_matrix>::fill(value);
79+
}
80+
else
81+
{
82+
dim3 gridDim((this->cols_gpu + block_size_x - 1)/block_size_x,
83+
(this->rows_gpu + block_size_y - 1)/block_size_y);
84+
dim3 blockDim(block_size_x, block_size_y);
85+
fill_matrix_kernel<data_type_matrix>
86+
<<<gridDim, blockDim>>>
87+
(this->data_gpu,
88+
this->cols_gpu,
89+
value);
90+
}
91+
}
92+
93+
template <class data_type_vector>
94+
void fill(data_type_vector value,
95+
unsigned block_size=0){
96+
if(block_size == 0)
97+
{
98+
this->adaboost::core::Vector<data_type_vector>::fill(value);
99+
}
100+
else
101+
{
102+
fill_vector_kernel<data_type_vector>
103+
<<<
104+
(this->size_gpu + block_size - 1)/block_size,
105+
block_size
106+
>>>(this->data_gpu, this->size_gpu, value);
107+
}
108+
}
109+
72110

73111
template <class data_type_vector, class data_type_matrix>
74112
void multiply(const Vector<data_type_vector>& vec,

adaboost/cuda/cuda_data_structures.hpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
#ifndef CUDA_ADABOOST_CORE_DATA_STRUCTURES_HPP
24
#define CUDA_ADABOOST_CORE_DATA_STRUCTURES_HPP
35

@@ -54,20 +56,6 @@ namespace adaboost
5456
*/
5557
VectorGPU(unsigned _size);
5658

57-
/*
58-
* Used for filling the vector with a given value.
59-
* If block size is passed 0 then the values are
60-
* filled on the CPU otherwise they are filled on
61-
* GPU.
62-
*
63-
* @param value The value with which the vector is
64-
* to be populated.
65-
* @param block_size The number of threads to be
66-
* launched per block on GPU.
67-
*/
68-
void fill(data_type_vector value,
69-
unsigned block_size=0);
70-
7159
/*
7260
* Copies the data from GPU to CPU.
7361
*/
@@ -129,10 +117,6 @@ namespace adaboost
129117

130118
MatrixGPU(unsigned _rows, unsigned _cols);
131119

132-
void fill(data_type_matrix value,
133-
unsigned block_size_x=0,
134-
unsigned block_size_y=0);
135-
136120
void copy_to_host();
137121

138122
void copy_to_device();

adaboost/cuda/cuda_data_structures_impl.hpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,6 @@ namespace adaboost
6161
}
6262
}
6363

64-
template <class data_type_vector>
65-
void VectorGPU<data_type_vector>::
66-
fill(data_type_vector value,
67-
unsigned block_size)
68-
{
69-
if(block_size == 0)
70-
{
71-
this->adaboost::core::Vector<data_type_vector>::fill(value);
72-
}
73-
else
74-
{
75-
fill_vector_kernel<data_type_vector>
76-
<<<
77-
(this->size_gpu + block_size - 1)/block_size,
78-
block_size
79-
>>>(this->data_gpu, this->size_gpu, value);
80-
}
81-
}
82-
8364
template <class data_type_vector>
8465
void
8566
VectorGPU<data_type_vector>::copy_to_host()
@@ -250,29 +231,6 @@ namespace adaboost
250231
data[row*cols + col] = value;
251232
}
252233

253-
template <class data_type_matrix>
254-
void MatrixGPU<data_type_matrix>::
255-
fill(data_type_matrix value,
256-
unsigned block_size_x,
257-
unsigned block_size_y)
258-
{
259-
if(block_size_x == 0 || block_size_y == 0)
260-
{
261-
this->adaboost::core::Matrix<data_type_matrix>::fill(value);
262-
}
263-
else
264-
{
265-
dim3 gridDim((this->cols_gpu + block_size_x - 1)/block_size_x,
266-
(this->rows_gpu + block_size_y - 1)/block_size_y);
267-
dim3 blockDim(block_size_x, block_size_y);
268-
fill_matrix_kernel<data_type_matrix>
269-
<<<gridDim, blockDim>>>
270-
(this->data_gpu,
271-
this->cols_gpu,
272-
value);
273-
}
274-
}
275-
276234
template <class data_type_matrix>
277235
void MatrixGPU<data_type_matrix>::
278236
copy_to_host()

0 commit comments

Comments
 (0)