-
Notifications
You must be signed in to change notification settings - Fork 1
Maxpool #16
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
base: tdnn-pool
Are you sure you want to change the base?
Maxpool #16
Changes from 2 commits
55cae0f
ecb5a86
b626325
f76586d
f284026
79f2c5f
5ca6aba
7d53314
a91c345
0d02c03
8d55431
d73c86d
7b0d46a
2e99da3
89ac55b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -773,6 +773,61 @@ static void _add_mat_blocks_trans(Real alpha, const Real* src, | |
| } | ||
| } | ||
|
|
||
| template<typename Real> | ||
| __global__ | ||
| static void _max_mat_blocks(Real alpha, const Real* src, | ||
| int32_cuda num_row_blocks, | ||
| int32_cuda num_col_blocks, Real* dst, MatrixDim d, | ||
| int src_stride) { | ||
| int32_cuda i = blockIdx.x * blockDim.x + threadIdx.x; | ||
| int32_cuda j = blockIdx.y * blockDim.y + threadIdx.y; | ||
| int32_cuda index = i + j * d.stride; | ||
| int32_cuda index_src = i + j * src_stride; | ||
| if (i < d.cols && j < d.rows) | ||
| for (int32_cuda p = 0; p < num_row_blocks; p++) { | ||
| for (int32_cuda q = 0; q < num_col_blocks; q++) { | ||
| dst[index] = fmax( | ||
| src[index_src + p * src_stride * d.rows + q * d.cols], | ||
| dst[index]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| template<typename Real> | ||
| __global__ | ||
| static void _max_mat_blocks_trans(Real alpha, const Real* src, | ||
| int32_cuda num_row_blocks, | ||
| int32_cuda num_col_blocks, Real* dst, | ||
| MatrixDim d, int src_stride) { | ||
| int32_cuda i = blockIdx.x * blockDim.x + threadIdx.x; | ||
| int32_cuda j = blockIdx.y * blockDim.y + threadIdx.y; | ||
| int32_cuda index = i + j * d.stride; | ||
| int32_cuda index_src = j + i * src_stride; | ||
| if (i < d.cols && j < d.rows) | ||
| for (int32_cuda p = 0; p < num_row_blocks; p++) { | ||
| for (int32_cuda q = 0; q < num_col_blocks; q++) { | ||
| dst[index] = fmax( | ||
| src[index_src + p * src_stride * d.cols + q * d.rows], | ||
| dst[index]); | ||
| } | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need alpha in these functions?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I would delete all the alpha. |
||
| } | ||
|
|
||
| template<typename Real> | ||
| __global__ | ||
| static void _max_mat_repeated(Real alpha, const Real* src, | ||
| MatrixDim src_dim, Real* dst, | ||
| MatrixDim dst_dim) { | ||
| int32_cuda i = blockIdx.x * blockDim.x + threadIdx.x; | ||
| int32_cuda j = blockIdx.y * blockDim.y + threadIdx.y; | ||
| int32_cuda src_i = i % src_dim.cols, | ||
| src_j = j % src_dim.rows, | ||
| dst_index = i + j * dst_dim.stride, | ||
| src_index = src_i + src_j * src_dim.stride; | ||
| if (i < dst_dim.cols && j < dst_dim.rows) | ||
| dst[dst_index] += alpha * src[src_index]; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to modify this line. |
||
| } | ||
|
|
||
| template<typename Real> | ||
| __global__ | ||
| static void _set_mat_mat_div_mat(const Real* A, const Real* B, const Real* C, | ||
|
|
@@ -3952,11 +4007,28 @@ void cudaF_add_mat_blocks(dim3 Gr, dim3 Bl, float alpha, const float* src, | |
| } | ||
| } | ||
|
|
||
| void cudaF_max_mat_blocks(dim3 Gr, dim3 Bl, float alpha, const float* src, | ||
| int32_cuda num_row_blocks, int32_cuda num_col_blocks, | ||
| float* dst, MatrixDim d, int src_stride, | ||
| int A_trans) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for alpha |
||
| if (A_trans) { | ||
| _max_mat_blocks_trans<<<Gr,Bl>>>(alpha, src, num_row_blocks, num_col_blocks, | ||
| dst, d, src_stride); | ||
| } else { | ||
| _max_mat_blocks<<<Gr,Bl>>>(alpha, src, num_row_blocks, num_col_blocks, dst, | ||
| d, src_stride); | ||
| } | ||
| } | ||
|
|
||
| void cudaF_add_mat_repeated(dim3 Gr, dim3 Bl, float alpha, const float* src, | ||
| MatrixDim src_dim, float *dst, MatrixDim dst_dim) { | ||
| _add_mat_repeated<<<Gr,Bl>>>(alpha, src, src_dim, dst, dst_dim); | ||
| } | ||
|
|
||
| void cudaF_max_mat_repeated(dim3 Gr, dim3 Bl, float alpha, const float* src, | ||
| MatrixDim src_dim, float *dst, MatrixDim dst_dim) { | ||
| _max_mat_repeated<<<Gr,Bl>>>(alpha, src, src_dim, dst, dst_dim); | ||
| } | ||
|
|
||
| void cudaF_set_mat_mat_div_mat(dim3 Gr, dim3 Bl, const float *A, const float *B, | ||
| const float *C, float *dst, MatrixDim d, | ||
|
|
@@ -4656,11 +4728,29 @@ void cudaD_add_mat_blocks(dim3 Gr, dim3 Bl, double alpha, const double* src, | |
| } | ||
| } | ||
|
|
||
| void cudaD_max_mat_blocks(dim3 Gr, dim3 Bl, double alpha, const double* src, | ||
| int32_cuda num_row_blocks, int32_cuda num_col_blocks, | ||
| double* dst, MatrixDim d, int src_stride, | ||
| int A_trans) { | ||
| if (A_trans) { | ||
| _max_mat_blocks_trans<<<Gr,Bl>>>(alpha, src, num_row_blocks, num_col_blocks, | ||
| dst, d, src_stride); | ||
| } else { | ||
| _max_mat_blocks<<<Gr,Bl>>>(alpha, src, num_row_blocks, num_col_blocks, dst, | ||
| d, src_stride); | ||
| } | ||
| } | ||
|
|
||
| void cudaD_add_mat_repeated(dim3 Gr, dim3 Bl, double alpha, const double* src, | ||
| MatrixDim src_dim, double *dst, MatrixDim dst_dim) { | ||
| _add_mat_repeated<<<Gr,Bl>>>(alpha, src, src_dim, dst, dst_dim); | ||
| } | ||
|
|
||
| void cudaD_max_mat_repeated(dim3 Gr, dim3 Bl, double alpha, const double* src, | ||
| MatrixDim src_dim, double *dst, MatrixDim dst_dim) { | ||
| _max_mat_repeated<<<Gr,Bl>>>(alpha, src, src_dim, dst, dst_dim); | ||
| } | ||
|
|
||
| void cudaD_set_mat_mat_div_mat(dim3 Gr, dim3 Bl, const double *A, | ||
| const double *B, const double *C, double *dst, | ||
| MatrixDim d, int stride_a, int stride_b, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -509,6 +509,9 @@ class CuMatrixBase { | |
| void AddMatBlocks(Real alpha, const CuMatrixBase<Real> &A, | ||
| MatrixTransposeType trans = kNoTrans); | ||
|
|
||
| void MaxMatBlocks(Real alpha, const CuMatrixBase<Real> &A, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comments containing function and parameter definition |
||
| MatrixTransposeType trans = kNoTrans); | ||
|
|
||
| /// (for each column c of *this), c = alpha * col + beta * c | ||
| void AddVecToCols(Real alpha, const CuVectorBase<Real> &col, Real beta = 1.0); | ||
| /// (for each row r of *this), r = alpha * row + beta * r | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need to initialize dst[index]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but dst is one of the input.
I am not sure how should initialize it?
I just imitate the function "_add_mat_blocks" in this file(line 722).