blob: 1d19c6174b6483ed04b6163752119ecbc0204c7f (
plain)
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
|
#pragma once
#include <vector>
#include <algorithm>
#include <cuda.h>
#include "gpu/mblas/matrix.h"
#include "nth_element_kernels.h"
namespace amunmt {
namespace GPU {
class NthElement {
public:
NthElement() = delete;
NthElement(const NthElement ©) = delete;
NthElement(uint maxBeamSize, uint maxBatchSize);
virtual ~NthElement();
void getNBestList(const std::vector<uint>& beamSizes, mblas::Matrix& Probs,
std::vector<float>& outCosts, std::vector<uint>& outKeys,
const bool isFirst=false);
void GetPairs(uint number,
std::vector<uint>& outKeys,
std::vector<float>& outValues);
void getValueByKey(std::vector<float>& out, const mblas::Matrix &d_in) const;
private:
const uint BLOCK_SIZE = 512;
mblas::TMatrix<NthOut> d_out;
mblas::TMatrix<NthOut> d_res;
//HostVector<NthOut> h_res;
std::vector<NthOut> h_res;
mblas::TMatrix<float> d_breakdown;
mblas::TMatrix<uint> d_batchPosition;
mblas::TMatrix<uint> d_cumBeamSizes;
uint maxBeamSize_, maxBatchSize_;
void getNBestList(mblas::Matrix &probs,
const HostVector<uint>& batchFirstElementIdxs,
const HostVector<uint>& cummulatedBeamSizes);
};
} // namespace GPU
}
|