cu-matrixdim.h
Go to the documentation of this file.
1 // cudamatrix/cu-matrixdim.h
2 
3 // Copyright 2009-2012 Karel Vesely
4 // 2013 Johns Hopkins University (author: Daniel Povey)
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 
22 
23 #ifndef KALDI_CUDAMATRIX_CU_MATRIXDIM_H_
24 #define KALDI_CUDAMATRIX_CU_MATRIXDIM_H_
25 
26 /*
27  * Typedefs needed for ANSI-C interface of CUDA wrappers
28  */
29 #include <cstdint>
30 typedef uint32_t uint32_cuda;
31 typedef int32_t int32_cuda;
32 typedef int32_t MatrixIndexT_cuda; // you'd have to change this if you changed MatrixIndexT from int32.
33 
34 template<typename Real>
35 struct MatrixElement {
38  Real weight;
39 };
40 
41 extern "C" {
46  typedef struct MatrixDim_ {
50  } MatrixDim;
51 
52 // we define the following constants here because this file is included
53 // both by the C++ code and also CUDA code.
54 
55 
56 // The size of a CUDA 1-d block, e.g. for vector operations..
57 #define CU1DBLOCK 256
58 
59 // The size of edge of CUDA square block, e.g. for matrix operations.
60 // Must be defined the same in cu-kernels-ansi.h
61 #define CU2DBLOCK 16
62 
63 
68  typedef struct CuBlockMatrixData_ {
69  int32_cuda row_offset; // sum of #rows of previous M_i
70  int32_cuda col_offset; // sum of #cols of previous M_i
71  MatrixDim matrix_dim; // dimension of this M_i
72  void *matrix_data; // data for M_i. This is a pointer to either float* or
73  // double*. Because C doesn't support templates and to
74  // avoid extra coding to support the two cases, we
75  // decided to make this a void* pointer.
77 
78  typedef struct Int32Pair {
81  } Int32Pair;
82 
83  inline bool operator<(const Int32Pair &a, const Int32Pair &b) {
84  if (a.first < b.first)
85  return true;
86  if (a.first > b.first)
87  return false;
88  return a.second < b.second;
89  }
90 }
91 
92 #endif
int32_cuda row_offset
Definition: cu-matrixdim.h:69
int32_cuda rows
Definition: cu-matrixdim.h:47
struct CuBlockMatrixData_ CuBlockMatrixData
This structure is used in cu-block-matrix.h to store information about a block-diagonal matrix...
int32_cuda row
Definition: cu-matrixdim.h:36
int32_cuda column
Definition: cu-matrixdim.h:37
Structure containing size of the matrix plus stride.
Definition: cu-matrixdim.h:46
int32_t int32_cuda
Definition: cu-matrixdim.h:31
This structure is used in cu-block-matrix.h to store information about a block-diagonal matrix...
Definition: cu-matrixdim.h:68
int32_cuda col_offset
Definition: cu-matrixdim.h:70
int32_cuda cols
Definition: cu-matrixdim.h:48
struct MatrixDim_ MatrixDim
Structure containing size of the matrix plus stride.
MatrixDim matrix_dim
Definition: cu-matrixdim.h:71
bool operator<(const Int32Pair &a, const Int32Pair &b)
Definition: cu-matrixdim.h:83
uint32_t uint32_cuda
Definition: cu-matrixdim.h:30
struct Int32Pair Int32Pair
int32_cuda second
Definition: cu-matrixdim.h:80
int32_cuda stride
Definition: cu-matrixdim.h:49
int32_t MatrixIndexT_cuda
Definition: cu-matrixdim.h:32
int32_cuda first
Definition: cu-matrixdim.h:79