-
Notifications
You must be signed in to change notification settings - Fork 211
/
gbt_predict_dense_default_impl.i
165 lines (143 loc) · 5.23 KB
/
gbt_predict_dense_default_impl.i
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* file: gbt_predict_dense_default_impl.i */
/*******************************************************************************
* Copyright 2014-2021 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
//++
// Implementation of auxiliary functions for gradient boosted trees prediction
// (defaultDense) method.
//--
*/
#ifndef __GBT_PREDICT_DENSE_DEFAULT_IMPL_I__
#define __GBT_PREDICT_DENSE_DEFAULT_IMPL_I__
#include "src/algorithms/dtrees/dtrees_model_impl.h"
#include "src/algorithms/dtrees/dtrees_train_data_helper.i"
#include "src/algorithms/dtrees/dtrees_predict_dense_default_impl.i"
#include "src/algorithms/dtrees/dtrees_feature_type_helper.h"
#include "src/algorithms/dtrees/gbt/gbt_internal.h"
namespace daal
{
namespace algorithms
{
namespace gbt
{
namespace prediction
{
namespace internal
{
typedef float ModelFPType;
typedef uint32_t FeatureIndexType;
const FeatureIndexType VECTOR_BLOCK_SIZE = 64;
template <typename algorithmFPType, typename DecisionTreeType, CpuType cpu>
inline void predictForTreeVector(const DecisionTreeType & t, const FeatureTypes & featTypes, const algorithmFPType * x, algorithmFPType v[])
{
const ModelFPType * const values = t.getSplitPoints() - 1;
const FeatureIndexType * const fIndexes = t.getFeatureIndexesForSplit() - 1;
const FeatureIndexType nFeat = featTypes.getNumberOfFeatures();
FeatureIndexType i[VECTOR_BLOCK_SIZE];
services::internal::service_memset_seq<FeatureIndexType, cpu>(i, FeatureIndexType(1), VECTOR_BLOCK_SIZE);
const FeatureIndexType maxLvl = t.getMaxLvl();
if (featTypes.hasUnorderedFeatures())
{
for (FeatureIndexType itr = 0; itr < maxLvl; itr++)
{
PRAGMA_IVDEP
PRAGMA_VECTOR_ALWAYS
for (FeatureIndexType k = 0; k < VECTOR_BLOCK_SIZE; k++)
{
const FeatureIndexType idx = i[k];
const FeatureIndexType splitFeature = fIndexes[idx];
const ModelFPType valueFromDataSet = x[splitFeature + k * nFeat];
const ModelFPType splitPoint = values[idx];
i[k] = idx * 2 + (featTypes.isUnordered(splitFeature) ? valueFromDataSet != splitPoint : valueFromDataSet > splitPoint);
}
}
}
else
{
for (FeatureIndexType itr = 0; itr < maxLvl; itr++)
{
PRAGMA_IVDEP
PRAGMA_VECTOR_ALWAYS
for (FeatureIndexType k = 0; k < VECTOR_BLOCK_SIZE; k++)
{
const FeatureIndexType idx = i[k];
i[k] = idx * 2 + (x[fIndexes[idx] + k * nFeat] > values[idx]);
}
}
}
PRAGMA_IVDEP
PRAGMA_VECTOR_ALWAYS
for (FeatureIndexType k = 0; k < VECTOR_BLOCK_SIZE; k++)
{
v[k] = values[i[k]];
}
}
template <typename algorithmFPType, typename DecisionTreeType, CpuType cpu>
inline algorithmFPType predictForTree(const DecisionTreeType & t, const FeatureTypes & featTypes, const algorithmFPType * x)
{
const ModelFPType * const values = (const ModelFPType *)t.getSplitPoints() - 1;
const FeatureIndexType * const fIndexes = t.getFeatureIndexesForSplit() - 1;
const FeatureIndexType maxLvl = t.getMaxLvl();
FeatureIndexType i = 1;
if (featTypes.hasUnorderedFeatures())
{
for (FeatureIndexType itr = 0; itr < maxLvl; itr++)
{
i = i * 2 + (featTypes.isUnordered(fIndexes[i]) ? int(x[fIndexes[i]]) != int(values[i]) : x[fIndexes[i]] > values[i]);
}
}
else
{
for (FeatureIndexType itr = 0; itr < maxLvl; itr++)
{
i = i * 2 + (x[fIndexes[i]] > values[i]);
}
}
return values[i];
}
template <typename algorithmFPType>
struct TileDimensions
{
size_t nRowsTotal = 0;
size_t nTreesTotal = 0;
size_t nCols = 0;
size_t nRowsInBlock = 0;
size_t nTreesInBlock = 0;
size_t nDataBlocks = 0;
size_t nTreeBlocks = 0;
TileDimensions(const NumericTable & data, size_t nTrees)
: nTreesTotal(nTrees), nRowsTotal(data.getNumberOfRows()), nCols(data.getNumberOfColumns())
{
nRowsInBlock = nRowsTotal;
if (nRowsTotal > 2 * VECTOR_BLOCK_SIZE)
{
nRowsInBlock = 2 * VECTOR_BLOCK_SIZE;
if (daal::threader_get_threads_number() > nRowsTotal / nRowsInBlock)
{
nRowsInBlock = VECTOR_BLOCK_SIZE;
}
}
nDataBlocks = nRowsTotal / nRowsInBlock;
nTreesInBlock = nTreesTotal;
nTreeBlocks = 1;
}
};
} /* namespace internal */
} /* namespace prediction */
} /* namespace gbt */
} /* namespace algorithms */
} /* namespace daal */
#endif