Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/AMMBench.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
#include <CPPAlgos/CPPAlgoTable.h>
#include <CPPAlgos/CRSCPPAlgo.h>
#include <CPPAlgos/CRSV2CPPAlgo.h>
#include <CPPAlgos/BCRSCPPAlgo.h>
#include <CPPAlgos/EWSCPPAlgo.h>
#include <CPPAlgos/CoOccurringFDCPPAlgo.h>
#include <CPPAlgos/BetaCoOFDCPPAlgo.h>
/**
* @}
*
Expand Down
2 changes: 1 addition & 1 deletion include/CPPAlgos/AbstractCPPAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <vector>
namespace AMMBench {
/**
* @ingroup AMMBENCH_CppAlgos The algorithms writtrn in c++
* @ingroup AMMBENCH_CppAlgos The algorithms written in c++
* @{
*/
/**
Expand Down
57 changes: 57 additions & 0 deletions include/CPPAlgos/BCRSCPPAlgo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Created by haolan on 5/29/23.
//

#ifndef INTELLISTREAM_BCRSCPPALGO_H
#define INTELLISTREAM_BCRSCPPALGO_H
#include <CPPAlgos/AbstractCPPAlgo.h>

namespace AMMBench {
/**
* @ingroup AMMBENCH_CppAlgos The algorithms written in c++
* @{
*/
/**
* @class CRSCPPlgo CPPAlgos/BCRSCPPAlgo.h
* @brief The Bernoulli column row sampling (CRS) class of c++ algos
*
*/
class BCRSCPPAlgo : public AMMBench::AbstractCPPAlgo {
public:
BCRSCPPAlgo() {

}

~BCRSCPPAlgo() {

}

/**
* @brief the virtual function provided for outside callers, rewrite in children classes
* @param A the A matrix
* @param B the B matrix
* @param sketchSize the size of sketc or sampling
* @return the output c matrix
*/
virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, int sketchSize);

};

/**
* @ingroup AMMBENCH_CppAlgos
* @typedef AbstractMatrixCppAlgoPtr
* @brief The class to describe a shared pointer to @ref BCRSCppAlgo

*/
typedef std::shared_ptr<class AMMBench::BCRSCPPAlgo> BCRSCPPAlgoPtr;
/**
* @ingroup AMMBENCH_CppAlgos
* @def newBCRSCppAlgo
* @brief (Macro) To creat a new @ref BCRSCppAlgounder shared pointer.
*/
#define newBCRSCPPAlgo std::make_shared<AMMBench::BCRSCPPAlgo>
}
/**
* @}
*/
#endif //INTELLISTREAM_BCRSCPPALGO_H
57 changes: 57 additions & 0 deletions include/CPPAlgos/BetaCoOFDCPPAlgo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Created by haolan on 5/30/23.
//

#ifndef INTELLISTREAM_BETACOOFDCPPALGO_H
#define INTELLISTREAM_BETACOOFDCPPALGO_H
#include <CPPAlgos/AbstractCPPAlgo.h>

namespace AMMBench {
/**
* @ingroup AMMBENCH_CppAlgos The algorithms written in c++
* @{
*/
/**
* @class CPPAlgos/BetaCoOFDCPPAlgo.h
* @brief The Beta Co-Occurring FD AMM class of c++ algos
*
*/
class BetaCoOFDCPPAlgo : public AMMBench::AbstractCPPAlgo {
public:
BetaCoOFDCPPAlgo() {

}

~BetaCoOFDCPPAlgo() {

}

/**
* @brief the virtual function provided for outside callers, rewrite in children classes
* @param A the A matrix
* @param B the B matrix
* @param sketchSize the size of sketc or sampling
* @return the output c matrix
*/
virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, int sketchSize);

};

/**
* @ingroup AMMBENCH_CppAlgos
* @typedef AbstractMatrixCppAlgoPtr
* @brief The class to describe a shared pointer to @ref BetaCoOFDCppAlgo

*/
typedef std::shared_ptr<class AMMBench::BetaCoOFDCPPAlgo> BetaCoOFDCPPAlgoPtr;
/**
* @ingroup AMMBENCH_CppAlgos
* @def newBetaCoOFDCppAlgo
* @brief (Macro) To creat a new @ref BetaCoOFDCppAlgounder shared pointer.
*/
#define newBetaCoOFDCPPAlgo std::make_shared<AMMBench::BetaCoOFDCPPAlgo>
}
/**
* @}
*/
#endif //INTELLISTREAM_BETACOOFDCPPALGO_H
4 changes: 2 additions & 2 deletions include/CPPAlgos/CRSCPPAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include <CPPAlgos/AbstractCPPAlgo.h>
namespace AMMBench {
/**
* @ingroup AMMBENCH_CppAlgos The algorithms writtrn in c++
* @ingroup AMMBENCH_CppAlgos The algorithms written in c++
* @{
*/
/**
* @class CRSCPPlgo CPPAlgos/CRSCPPAlgo.h
* @brief The cloumn row sampling (CRS) class of c++ algos
* @brief The column row sampling (CRS) class of c++ algos
*
*/
class CRSCPPAlgo : public AMMBench::AbstractCPPAlgo {
Expand Down
4 changes: 2 additions & 2 deletions include/CPPAlgos/CRSV2CPPAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

namespace AMMBench {
/**
* @ingroup AMMBENCH_CppAlgos The algorithms writtrn in c++
* @ingroup AMMBENCH_CppAlgos The algorithms written in c++
* @{
*/
/**
* @class CRSCPPlgo CPPAlgos/CRSV2CPPAlgo.h
* @brief The cloumn row sampling (CRS) class of c++ algos
* @brief The column row sampling (CRS) class of c++ algos, a second implementation
*
*/
class CRSV2CPPAlgo : public AMMBench::AbstractCPPAlgo {
Expand Down
57 changes: 57 additions & 0 deletions include/CPPAlgos/CoOccurringFDCPPAlgo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Created by haolan on 5/29/23.
//

#ifndef INTELLISTREAM_COOCCURRINGFDCPPALGO_H
#define INTELLISTREAM_COOCCURRINGFDCPPALGO_H
#include <CPPAlgos/AbstractCPPAlgo.h>

namespace AMMBench {
/**
* @ingroup AMMBENCH_CppAlgos The algorithms written in c++
* @{
*/
/**
* @class CPPAlgos/CoOccurringFDCPPAlgo.h
* @brief The Co-Occurring FD AMM class of c++ algos
*
*/
class CoOccurringFDCPPAlgo : public AMMBench::AbstractCPPAlgo {
public:
CoOccurringFDCPPAlgo() {

}

~CoOccurringFDCPPAlgo() {

}

/**
* @brief the virtual function provided for outside callers, rewrite in children classes
* @param A the A matrix
* @param B the B matrix
* @param sketchSize the size of sketc or sampling
* @return the output c matrix
*/
virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, int sketchSize);

};

/**
* @ingroup AMMBENCH_CppAlgos
* @typedef AbstractMatrixCppAlgoPtr
* @brief The class to describe a shared pointer to @ref CoOccurringFDCppAlgo

*/
typedef std::shared_ptr<class AMMBench::CoOccurringFDCPPAlgo> CoOccurringFDCPPAlgoPtr;
/**
* @ingroup AMMBENCH_CppAlgos
* @def newCoOccurringFDCppAlgo
* @brief (Macro) To creat a new @ref CoOccurringFDCppAlgounder shared pointer.
*/
#define newCoOccurringFDCPPAlgo std::make_shared<AMMBench::CoOccurringFDCPPAlgo>
}
/**
* @}
*/
#endif //INTELLISTREAM_COOCCURRINGFDCPPALGO_H
57 changes: 57 additions & 0 deletions include/CPPAlgos/EWSCPPAlgo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Created by haolan on 5/29/23.
//

#ifndef INTELLISTREAM_EWSCPPALGO_H
#define INTELLISTREAM_EWSCPPALGO_H
#include <CPPAlgos/AbstractCPPAlgo.h>

namespace AMMBench {
/**
* @ingroup AMMBENCH_CppAlgos The algorithms written in c++
* @{
*/
/**
* @class CPPAlgos/EWSCPPAlgo.h
* @brief The Element Wise Sampling (EWS) class of c++ algos
*
*/
class EWSCPPAlgo : public AMMBench::AbstractCPPAlgo {
public:
EWSCPPAlgo() {

}

~EWSCPPAlgo() {

}

/**
* @brief the virtual function provided for outside callers, rewrite in children classes
* @param A the A matrix
* @param B the B matrix
* @param sketchSize the size of sketc or sampling
* @return the output c matrix
*/
virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, int sketchSize);

};

/**
* @ingroup AMMBENCH_CppAlgos
* @typedef AbstractMatrixCppAlgoPtr
* @brief The class to describe a shared pointer to @ref EWSCppAlgo

*/
typedef std::shared_ptr<class AMMBench::EWSCPPAlgo> EWSCPPAlgoPtr;
/**
* @ingroup AMMBENCH_CppAlgos
* @def newEWSCppAlgo
* @brief (Macro) To creat a new @ref EWSCppAlgounder shared pointer.
*/
#define newEWSCPPAlgo std::make_shared<AMMBench::EWSCPPAlgo>
}
/**
* @}
*/
#endif //INTELLISTREAM_EWSCPPALGO_H
35 changes: 35 additions & 0 deletions src/CPPAlgos/BCRSCPPAlgo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by haolan on 5/29/23.
//
#include <CPPAlgos/BCRSCPPAlgo.h>

namespace AMMBench {
torch::Tensor BCRSCPPAlgo::amm(torch::Tensor A, torch::Tensor B, int k) {
A = A.t();
auto A_size = A.sizes();
int64_t n = A_size[0];
//int64_t m = A_size[1];

assert(n == B.size(0));
//TORCH_CHECK(n == B.size(0));
//TORCH_CHECK(k < n);

//INTELLI_INFO("Running Bernoulli CRS CPP");

// probability distribution
torch::Tensor sample = torch::rand({n}); // default: uniform
sample = sample.div(sample.sum() / k); // sum = k as per the paper

// diagonal scaling matrix P (nxn)
torch::Tensor P = torch::diag(1.0 / torch::sqrt(sample));

// random diagonal sampling matrix K (nxn)
sample = (torch::rand({n}) < sample).to(torch::kFloat32);
torch::Tensor K = torch::diag(sample);

torch::Tensor a = torch::matmul(torch::matmul(A.t(), P), K);
torch::Tensor b = torch::matmul(torch::matmul(a, K), P);

return torch::matmul(b, B);
}
}
Loading