namespace internal¶
// namespaces namespace xf::data_analytics::clustering::internal::kmeansScan
storeCenters2Array¶
#include "xf_data_analytics/clustering/kmeansTrain.hpp"
template < typename DT, int Dim, int Kcluster, int uramDepth, int KU, int DV > void storeCenters2Array ( hls::stream <ap_uint <sizeof (DT)*8>> centerStrm [DV], hls::stream <bool>& eCenterStrm, const int dims, ap_uint <sizeof (DT)*8*DV> centers [KU][uramDepth] )
storeCenters2Array is used for storing centers to local memory.
Parameters:
DT | data type, supporting float and double |
Dim | the maximum number of dimensions, dims<=Dim |
Kcluster | the maximum number of cluster,kcluster<=Kcluster |
uramDepth | the depth of uram |
KU | unroll factor of Kcluster |
DV | unroll factor of Dim |
centerStrm | input centers streams |
ecenterStrm | the end flag of centerStrm |
dims | the number of dimensions |
centers | local memory for storing centers |
scanAndStoreCenters¶
#include "xf_data_analytics/clustering/kmeansTrain.hpp"
template < typename DT, int Dim, int Kcluster, int uramDepth, int KU, int DV > void scanAndStoreCenters ( ap_uint <512>* data, const ap_uint <32> offset, const int dims, const int kcluster, ap_uint <sizeof (DT)*8*DV> centers [KU][uramDepth] )
scanAndStoreCenters is used for scanning initial centers from DDR and storing to local memory.
Parameters:
DT | data type, supporting float and double |
Dim | the maximum number of dimensions, dims<=Dim |
Kcluster | the maximum number of cluster,kcluster<=Kcluster |
uramDepth | the depth of uram |
KU | unroll factor of Kcluster |
DV | unroll factor of Dim |
data | initial centers on DDR |
offset | the start position of initial centers in data |
dims | the number of dimensions |
kcluster | the number of clusters |
centers | local memory for storing centers |
writeCenters¶
#include "xf_data_analytics/clustering/kmeansTrain.hpp"
template < typename DT, int Dim, int Kcluster, int uramDepth, int KU, int DV > void writeCenters ( ap_uint <sizeof (DT)*8*DV> centersArray [KU][uramDepth], const int dims, const int kcluster, const int it, ap_uint <512>* kcenters )
writeCenters writes best centers to DDR.
Parameters:
DT | data type, supporting float and double |
Dim | the maximum number of dimensions, dims<=Dim |
Kcluster | the maximum number of cluster,kcluster<=Kcluster |
uramDepth | the depth of uram |
KU | unroll factor of Kcluster |
DV | unroll factor of Dim |
centersArray | best centers |
dims | the number of dimensions |
kcluster | the number of clusters |
it | iterations |
kcenters | centers in DDR |
updateC0¶
#include "xf_data_analytics/clustering/kmeansTrain.hpp"
template < typename DT, int Dim, int Kcluster, int uramDepth, int KU, int DV > void updateC0 ( hls::stream <ap_uint <sizeof (DT)*8>> sampleStrm [DV], hls::stream <bool>& endSampleStrm, hls::stream <ap_uint <32>>& tagStrm, hls::stream <bool>& etagStrm, const int dims, ap_uint <sizeof (DT)*8*DV> betterCenters [KU][uramDepth] )
updateC0 is used for updating centers
Parameters:
DT | data type, supporting float and double |
Dim | the maximum number of dimensions, dims<=Dim |
Kcluster | the maximum number of cluster,kcluster<=Kcluster |
uramDepth | the depth of uram |
KU | unroll factor of Kcluster |
DV | unroll factor of Dim |
sampleStrm | input sample streams |
endSampleStrm | the end flag of input sample streams |
tagStrm | input tag streams,each tag is the id which each sample belongs to cluster. |
etagStrm | the end flag of tag streams |
dims | the number of dimensions. |
betterCenters | updated centers. |
convertPort¶
#include "xf_data_analytics/clustering/kmeansTrain.hpp"
template < int sz, int sn, int Dim, int DV > void convertPort ( hls::stream <ap_uint <sz>> sampleStrm [sn], hls::stream <bool>& endSampleStrm, hls::stream <ap_uint <sz>> s1Strm [DV], hls::stream <bool>& es1Strm, hls::stream <ap_uint <sz>> s2Strm [DV], hls::stream <bool>& es2Strm )
convertPort converts sn streams to DV streams, in which the s1 and s2 are same.
Parameters:
sz | the width input/output stream |
sn | the number of input streams |
Dim | the number of dimensions |
DV | the number of output streams |
sampleStrm | input streams. |
endSampleStrm | the end flag of input streams |
s1Strm | duplicate stream. |
es1Strm | the end flag of s1Strm. |
s2Strm | duplicate stream. |
es2Strm | the end flag of s1Strm. |
isConverged¶
#include "xf_data_analytics/clustering/kmeansTrain.hpp"
template < typename DT, int Dim, int Kcluster, int uramDepth, int KU, int DV > bool isConverged ( ap_uint <sizeof (DT)*8*DV> centers [KU][uramDepth], ap_uint <sizeof (DT)*8*DV> betterCenters [KU][uramDepth], const int dims, const int kcluster, const DT eps )
isConverged is used for checking whether new centers is close to previous centers and copy betterCenters to centers with clearing betterCenters in order to reduce resource.
Parameters:
DT | data type, supporting float and double |
Dim | the maximum number of dimensions,dynamic number of dimension should be not greater than the maximum. |
Kcluster | the maximum number of cluster,dynamic number of cluster should be not greater than the maximum. |
uramDepth | the depth of uram where centers are stored. uramDepth should be not less than ceiling(Kcluster/KU)
|
KU | unroll factor of Kcluster, KU centers are took part in calculating distances concurrently with one sample. After Kcluster/KU+1 times at most, ouput the minimum distance of a sample and Kcluster centers. |
DV | unroll factor of Dim, DV elements in a center are took part in calculating distances concurrently with one sample. |
centers | previous centers. |
betterCenters | new centers |
dims | the number of dimensions. |
kcluster | the number of clusters. |
eps | distance thredhold. |
kMeansTrainIter¶
#include "xf_data_analytics/clustering/kmeansTrain.hpp"
template < typename DT, int Dim, int Kcluster, int uramDepth, int KU, int DV > void kMeansTrainIter ( ap_uint <512>* data, ap_uint <sizeof (DT)*8*DV> centers [KU][uramDepth], const int nsample, const int dims, const int kcluster, const int offset, ap_uint <sizeof (DT)*8*DV> betterCenters [KU][uramDepth] )
kMeansTrainIter is used for one iteration of training: scan samples + predict + update centers.
Parameters:
DT | data type, supporting float and double |
Dim | the maximum number of dimensions,dynamic number of dimension should be not greater than the maximum. |
Kcluster | the maximum number of cluster,dynamic number of cluster should be not greater than the maximum. |
uramDepth | the depth of uram where centers are stored. uramDepth should be not less than ceiling(Kcluster/KU)
|
KU | unroll factor of Kcluster, KU centers are took part in calculating distances concurrently with one sample. After Kcluster/KU+1 times at most, ouput the minimum distance of a sample and Kcluster centers. |
DV | unroll factor of Dim, DV elements in a center are took part in calculating distances concurrently with one sample. |
centers | input centers used for calculating distance. |
nsample | the number of input samples. |
dims | the number of dimensions. |
kcluster | the number of clusters. |
offset | the start position of samples in data, offset = 1 + ceiling(kcluster*dims*8*sizeof(DT)/512). |
betterCenters | updated centers as better centers |
kMeansTrainImp¶
#include "xf_data_analytics/clustering/kmeansTrain.hpp"
template < typename DT, int Dim, int Kcluster, int KU, int DV > void kMeansTrainImp ( ap_uint <512>* data, ap_uint <512>* kcenters )
kMeansTrainImp is used for implementation k means training. It parsers all dynamic configures from compressed input data at first, then stores the initial centers to local memory. When iterations is up to maximum number or new centers are very close to previous centers, the last centers as best centers are ouput.
Parameters:
DT | data type, supporting float and double |
Dim | the maximum number of dimensions,dynamic number of dimension should be not greater than the maximum. |
Kcluster | the maximum number of cluster,dynamic number of cluster should be not greater than the maximum. |
KU | unroll factor of Kcluster, KU centers are took part in calculating distances concurrently with one sample. After Kcluster/KU+1 times at most, ouput the minimum distance of a sample and Kcluster centers. |
DV | unroll factor of Dim, DV elements in a center are took part in calculating distances concurrently with one sample. |
data | input data from host |
kcenters | the output best centers |