1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#pragma once
#include "matrix_wrapper.h"
#include "vector_wrapper.h"
namespace amunmt {
namespace GPU {
struct NthOut
{
unsigned ind;
float score;
__device__ __host__
NthOut() {}
__device__ __host__
NthOut(unsigned init)
:ind(init)
,score(init)
{}
__device__ __host__
NthOut(unsigned &vInd, float vScore)
:ind(vInd)
,score(vScore)
{}
__device__ __host__
NthOut& operator+=(const NthOut& rhs)
{
ind += rhs.ind;
score += rhs.score;
return *this;
}
};
/////////////////////////////////////////////////////////////////////////////////////////
struct NthOutBatch
{
unsigned ind;
float score;
//unsigned hypoInd;
//unsigned vocabInd;
__device__ __host__
NthOutBatch(const float& rhs)
{
// only to be used to init variable in matrix.h gSum
assert(rhs == 0.0f);
ind = rhs;
score = rhs;
//hypoInd = rhs;
//vocabInd = rhs;
}
__device__ __host__
NthOutBatch() {}
__device__ __host__
NthOutBatch(unsigned vInd, float vScore, unsigned vHypoInd, unsigned vVocabInd)
:ind(vInd)
,score(vScore)
//,hypoInd(vHypoInd)
//,vocabInd(vVocabInd)
{}
__device__ __host__
NthOutBatch& operator=(const NthOutBatch& rhs)
{
ind = rhs.ind;
score = rhs.score;
//hypoInd = rhs.hypoInd;
//vocabInd = rhs.vocabInd;
return *this;
}
__device__ __host__
NthOutBatch& operator+=(const NthOutBatch& rhs)
{
ind += rhs.ind;
score += rhs.score;
//hypoInd += rhs.hypoInd;
//vocabInd += rhs.vocabInd;
return *this;
}
};
/////////////////////////////////////////////////////////////////////////////////////////
inline std::ostream& operator<<(std::ostream &out, const NthOut &obj)
{
out << "(" << obj.ind << "," << obj.score << ")";
return out;
}
inline std::ostream& operator<<(std::ostream &out, const NthOutBatch &obj)
{
out << "("
<< obj.ind << ","
<< obj.score << ","
//<< obj.hypoInd << ","
//<< obj.vocabInd
<< ")";
return out;
}
/////////////////////////////////////////////////////////////////////////////////////////
__global__ void gMaxElement(mblas::VectorWrapper<NthOut> out,
const mblas::MatrixWrapper<float> probsWrap,
const mblas::VectorWrapper<unsigned> batchPositionWrap,
unsigned numBatches);
__global__ void gMaxElementUpdate(mblas::VectorWrapper<NthOut> out,
mblas::MatrixWrapper<float> probsWrap,
mblas::VectorWrapper<NthOut> resWrap,
const mblas::VectorWrapper<unsigned> batchPositionWrap,
const mblas::VectorWrapper<unsigned> cumBeamSizesWrap,
unsigned numBlocks);
__global__ void gGetValueByKey(mblas::MatrixWrapper<float> out,
const mblas::MatrixWrapper<float> in,
unsigned* indices, unsigned n);
}
}
|