cu-matrix-inl.h
Go to the documentation of this file.
1 // cudamatrix/cu-matrix-inl.h
2 
3 // Copyright 2009-2012 Karel Vesely
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 // Do not include this file directly. It is included by cu-matrix.h.
21 
22 #ifndef KALDI_CUDAMATRIX_CU_MATRIX_INL_H_
23 #define KALDI_CUDAMATRIX_CU_MATRIX_INL_H_
24 
25 namespace kaldi {
26 
27 template<typename Real>
29  const MatrixIndexT row_offset,
30  const MatrixIndexT num_rows,
31  const MatrixIndexT col_offset,
32  const MatrixIndexT num_cols) {
33  if (num_rows == 0 || num_cols == 0) {
34  KALDI_ASSERT(num_rows == 0 && num_cols == 0);
35  // Everything will have been set to zero in CuMastrixBase's default
36  // initializer, so nothing to do.
37  } else {
38  KALDI_ASSERT(row_offset >= 0 && col_offset >= 0 &&
39  num_rows >= 0 && num_cols >= 0 &&
40  row_offset + num_rows <= mat.num_rows_ &&
41  col_offset + num_cols <= mat.num_cols_);
42  this->data_ = mat.data_ + static_cast<size_t>(col_offset) +
43  static_cast<size_t>(row_offset) * static_cast<size_t>(mat.stride_);
44  this->num_cols_ = num_cols;
45  this->num_rows_ = num_rows;
46  this->stride_ = mat.stride_;
47  }
48 }
49 
50 template<typename Real>
51 inline CuSubMatrix<Real>::CuSubMatrix(const Real *data,
52  const MatrixIndexT num_rows,
53  const MatrixIndexT num_cols,
54  const MatrixIndexT stride):
55  CuMatrixBase<Real>(const_cast<Real*>(data), num_rows, num_cols, stride) {
56  // in general if you use SubMatrix or CuSubMatrix, const-correctness is not
57  // preserved (preserving it would require us duplicating the class and it
58  // would have been a hassle).
59 
60  // Note: we used to check that stride >= num_cols. We no longer check for
61  // this as there are some situations where having stride < num_cols is useful,
62  // but beware because most if not all CUBLAS calls will crash when given
63  // such an input, even in a situation where it makes sense.
64  KALDI_ASSERT((num_rows != 0) == (num_cols != 0) && stride >= 0 &&
65  num_rows >= 0 && num_cols >= 0 && stride >= 0);
66 }
67 
68 
69 } // namespace kaldi
70 
71 #endif
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
CuSubMatrix(const CuMatrixBase< Real > &mat, const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols)
Definition: cu-matrix-inl.h:28
Real * data_
GPU data pointer (or regular matrix data pointer,.
Definition: cu-matrix.h:777
uint64 data_
MatrixIndexT stride_
Definition: cu-matrix.h:787
int32 MatrixIndexT
Definition: matrix-common.h:98
Matrix for CUDA computing.
Definition: matrix-common.h:69
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT num_cols_
Definition: cu-matrix.h:785
MatrixIndexT num_rows_
Definition: cu-matrix.h:786