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
2 changes: 2 additions & 0 deletions include/AMMBench.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
#include <MatrixLoader/GaussianMatrixLoader.h>
#include <MatrixLoader/ExponentialMatrixLoader.h>
#include <MatrixLoader/BinomialMatrixLoader.h>
#include <MatrixLoader/PoissonMatrixLoader.h>
#include <MatrixLoader/BetaMatrixLoader.h>
#include <MatrixLoader/MatrixLoaderTable.h>
/**
* @}
Expand Down
93 changes: 93 additions & 0 deletions include/MatrixLoader/BetaMatrixLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// Created by haolan on 6/6/23.
//

#ifndef INTELLISTREAM_BETAMATRIXLOADER_H
#define INTELLISTREAM_BETAMATRIXLOADER_H
#include <MatrixLoader/AbstractMatrixLoader.h>
namespace AMMBench {
/**
* @ingroup AMMBENCH_MatrixLOADER
* @{
*/
/**
* @ingroup AMMBENCH_MatrixLOADER_Beta The Beta generator
* @{
*/
/**
* @class BetaMatrixLoader MatrixLoader/BetaMatrixLoader.h
* @brief The Beta class of matrix loader
* @ingroup AMMBENCH_MatrixLOADER_Beta
* @note:
* - Must have a global config by @ref setConfig
* @note Default behavior
* - create
* - call @ref setConfig, this function will also generate the tensor A and B correspondingly
* - call @ref getA and @ref getB (assuming we are benchmarking torch.mm(A,B))
* @note: require config parameters and default values
* - "aRow" The rows in matrix A, U64, 100
* - "aCol" The cols in matrix B, U64, 1000
* - "bCol" The rows in matrix B, U64, 500
* - "seed" The seed of inline random generator,U64,114514
* - "a" parameters of beta distribution, Double, 2.0
* - "b" parameters of beta distribution, Double, 2.0
* @note: default name tags
* "random": @ref BetaMatrixLoader
*/
class BetaMatrixLoader : public AbstractMatrixLoader {
protected:
torch::Tensor A, B;
uint64_t aRow, aCol, bCol, seed;
double a, b;
/**
* @brief Inline logic of reading a config file
* @param cfg the config
*/
void paraseConfig(INTELLI::ConfigMapPtr cfg);
/**
* @brief inline logic of generating A and B
*/
void generateAB();
public:
BetaMatrixLoader() = default;

~BetaMatrixLoader() = default;
/**
* @brief Set the GLOBAL config map related to this loader
* @param cfg The config map
* @return bool whether the config is successfully set
* @note
*/
virtual bool setConfig(INTELLI::ConfigMapPtr cfg);
/**
* @brief get the A matrix
* @return the generated A matrix
*/
virtual torch::Tensor getA();
/**
* @brief get the B matrix
* @return the generated B matrix
*/
virtual torch::Tensor getB();
};
/**
* @ingroup AMMBENCH_MatrixLOADER_Beta
* @typedef BetaMatrixLoaderPtr
* @brief The class to describe a shared pointer to @ref BetaMatrixLoader

*/
typedef std::shared_ptr<class AMMBench::BetaMatrixLoader> BetaMatrixLoaderPtr;
/**
* @ingroup AMMBENCH_MatrixLOADER_Beta
* @def newBetaMatrixLoader
* @brief (Macro) To creat a new @ref BetaMatrixLoader under shared pointer.
*/
#define newBetaMatrixLoader std::make_shared<AMMBench::BetaMatrixLoader>
/**
* @}
*/
/**
* @}
*/
}
#endif //INTELLISTREAM_BETAMATRIXLOADER_H
5 changes: 4 additions & 1 deletion include/MatrixLoader/BinomialMatrixLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ namespace AMMBench {
* - "aCol" The cols in matrix B, U64, 1000
* - "bCol" The rows in matrix B, U64, 500
* - "seed" The seed of inline random generator,U64,114514
* - "trials" parameters of binomial distribution, U64, 10
* - "probability" parameters of binomial distribution, Double, 0.5
* @note: default name tags
* "random": @ref BinomialMatrixLoader
*/
class BinomialMatrixLoader : public AbstractMatrixLoader {
protected:
torch::Tensor A, B;
uint64_t aRow, aCol, bCol, seed;
uint64_t aRow, aCol, bCol, seed, trials;
double probability;
/**
* @brief Inline logic of reading a config file
* @param cfg the config
Expand Down
90 changes: 90 additions & 0 deletions include/MatrixLoader/PoissonMatrixLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// Created by haolan on 6/6/23.
//

#ifndef INTELLISTREAM_POISSONMATRIXLOADER_H
#define INTELLISTREAM_POISSONMATRIXLOADER_H
#include <MatrixLoader/AbstractMatrixLoader.h>
namespace AMMBench {
/**
* @ingroup AMMBENCH_MatrixLOADER
* @{
*/
/**
* @ingroup AMMBENCH_MatrixLOADER_Poisson The Poisson generator
* @{
*/
/**
* @class PoissonMatrixLoader MatrixLoader/PoissonMatrixLoader.h
* @brief The Poisson class of matrix loader
* @ingroup AMMBENCH_MatrixLOADER_Poisson
* @note:
* - Must have a global config by @ref setConfig
* @note Default behavior
* - create
* - call @ref setConfig, this function will also generate the tensor A and B correspondingly
* - call @ref getA and @ref getB (assuming we are benchmarking torch.mm(A,B))
* @note: require config parameters and default values
* - "aRow" The rows in matrix A, U64, 100
* - "aCol" The cols in matrix B, U64, 1000
* - "bCol" The rows in matrix B, U64, 500
* - "seed" The seed of inline random generator,U64,114514
* @note: default name tags
* "random": @ref PoissonMatrixLoader
*/
class PoissonMatrixLoader : public AbstractMatrixLoader {
protected:
torch::Tensor A, B;
uint64_t aRow, aCol, bCol, seed;
/**
* @brief Inline logic of reading a config file
* @param cfg the config
*/
void paraseConfig(INTELLI::ConfigMapPtr cfg);
/**
* @brief inline logic of generating A and B
*/
void generateAB();
public:
PoissonMatrixLoader() = default;

~PoissonMatrixLoader() = default;
/**
* @brief Set the GLOBAL config map related to this loader
* @param cfg The config map
* @return bool whether the config is successfully set
* @note
*/
virtual bool setConfig(INTELLI::ConfigMapPtr cfg);
/**
* @brief get the A matrix
* @return the generated A matrix
*/
virtual torch::Tensor getA();
/**
* @brief get the B matrix
* @return the generated B matrix
*/
virtual torch::Tensor getB();
};
/**
* @ingroup AMMBENCH_MatrixLOADER_Poisson
* @typedef PoissonMatrixLoaderPtr
* @brief The class to describe a shared pointer to @ref PoissonMatrixLoader

*/
typedef std::shared_ptr<class AMMBench::PoissonMatrixLoader> PoissonMatrixLoaderPtr;
/**
* @ingroup AMMBENCH_MatrixLOADER_Poisson
* @def newPoissonMatrixLoader
* @brief (Macro) To creat a new @ref PoissonMatrixLoader under shared pointer.
*/
#define newPoissonMatrixLoader std::make_shared<AMMBench::PoissonMatrixLoader>
/**
* @}
*/
/**
* @}
*/
}
#endif //INTELLISTREAM_POISSONMATRIXLOADER_H
48 changes: 48 additions & 0 deletions src/MatrixLoader/BetaMatrixLoader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Created by haolan on 6/6/23.
//
#include <MatrixLoader/BetaMatrixLoader.h>
#include <Utils/IntelliLog.h>
void AMMBench::BetaMatrixLoader::paraseConfig(INTELLI::ConfigMapPtr cfg) {
aRow = cfg->tryU64("aRow", 100, true);
aCol = cfg->tryU64("aCol", 1000, true);
bCol = cfg->tryU64("bCol", 500, true);
a = cfg->tryDouble("a", 2, true);
b = cfg->tryDouble("b", 2, true);
seed = cfg->tryU64("seed", 114514, true);
INTELLI_INFO(
"Generating [" + to_string(aRow) + "x" + to_string(aCol) + "]*[" + to_string(aCol) + "x" + to_string(bCol)
+ "]" + " Parameter: " + to_string(a) + ", " + to_string(b));
}
void AMMBench::BetaMatrixLoader::generateAB() {
torch::manual_seed(seed);

auto tensor1 = torch::randn({(long) aRow, (long) aCol}).abs_();
auto tensor2 = torch::randn({(long) aRow, (long) aCol}).abs_();

tensor1 = tensor1.pow(1. / a);
tensor2 = tensor2.pow(1. / b);

A = tensor1 / (tensor1 + tensor2);

tensor1 = torch::randn({(long) aCol, (long) bCol}).abs_();
tensor2 = torch::randn({(long) aCol, (long) bCol}).abs_();

tensor1 = tensor1.pow(1. / a);
tensor2 = tensor2.pow(1. / b);

B = tensor1 / (tensor1 + tensor2);
}

//do nothing in abstract class
bool AMMBench::BetaMatrixLoader::setConfig(INTELLI::ConfigMapPtr cfg) {
paraseConfig(cfg);
generateAB();
return true;
}
torch::Tensor AMMBench::BetaMatrixLoader::getA() {
return A;
}
torch::Tensor AMMBench::BetaMatrixLoader::getB() {
return B;
}
7 changes: 3 additions & 4 deletions src/MatrixLoader/BinomialMatrixLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ void AMMBench::BinomialMatrixLoader::paraseConfig(INTELLI::ConfigMapPtr cfg) {
aCol = cfg->tryU64("aCol", 1000, true);
bCol = cfg->tryU64("bCol", 500, true);
seed = cfg->tryU64("seed", 114514, true);
trials = cfg->tryU64("trials", 10, true);
probability = cfg->tryDouble("probability", 0.5, true);
INTELLI_INFO(
"Generating [" + to_string(aRow) + "x" + to_string(aCol) + "]*[" + to_string(aCol) + "x" + to_string(bCol)
+ "]");
+ "]" + " Parameter: " + to_string(trials) + ", " + to_string(probability));
}
void AMMBench::BinomialMatrixLoader::generateAB() {
torch::manual_seed(seed);
A = torch::zeros({(long) aRow, (long) aCol});
B = torch::zeros({(long) aCol, (long) bCol});
// parameter
const int trials = 10;
const double probability = 0.5;

for(int i = 0; i < trials; i++) {
// Create a tensor filled with random numbers between 0 and 1
Expand Down
2 changes: 2 additions & 0 deletions src/MatrixLoader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ add_sources(
GaussianMatrixLoader.cpp
ExponentialMatrixLoader.cpp
BinomialMatrixLoader.cpp
PoissonMatrixLoader.cpp
BetaMatrixLoader.cpp
MatrixLoaderTable.cpp
)
4 changes: 4 additions & 0 deletions src/MatrixLoader/MatrixLoaderTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <MatrixLoader/SparseMatrixLoader.h>
#include <MatrixLoader/ExponentialMatrixLoader.h>
#include <MatrixLoader/GaussianMatrixLoader.h>
#include <MatrixLoader/PoissonMatrixLoader.h>
#include <MatrixLoader/BinomialMatrixLoader.h>
#include <MatrixLoader/BetaMatrixLoader.h>
namespace AMMBench {
/**
* @note revise me if you need new loader
Expand All @@ -18,6 +20,8 @@ AMMBench::MatrixLoaderTable::MatrixLoaderTable() {
loaderMap["gaussian"] = newGaussianMatrixLoader();
loaderMap["exponential"] = newExponentialMatrixLoader();
loaderMap["binomial"] = newBinomialMatrixLoader();
loaderMap["poisson"] = newPoissonMatrixLoader();
loaderMap["beta"] = newBetaMatrixLoader();
}

} // AMMBench
32 changes: 32 additions & 0 deletions src/MatrixLoader/PoissonMatrixLoader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by haolan on 6/6/23.
//
#include <MatrixLoader/PoissonMatrixLoader.h>
#include <Utils/IntelliLog.h>
void AMMBench::PoissonMatrixLoader::paraseConfig(INTELLI::ConfigMapPtr cfg) {
aRow = cfg->tryU64("aRow", 100, true);
aCol = cfg->tryU64("aCol", 1000, true);
bCol = cfg->tryU64("bCol", 500, true);
seed = cfg->tryU64("seed", 114514, true);
INTELLI_INFO(
"Generating [" + to_string(aRow) + "x" + to_string(aCol) + "]*[" + to_string(aCol) + "x" + to_string(bCol)
+ "]");
}
void AMMBench::PoissonMatrixLoader::generateAB() {
torch::manual_seed(seed);
A = torch::poisson(torch::ones({(long) aRow, (long) aCol}));
B = torch::poisson(torch::ones({(long) aCol, (long) bCol}));
}

//do nothing in abstract class
bool AMMBench::PoissonMatrixLoader::setConfig(INTELLI::ConfigMapPtr cfg) {
paraseConfig(cfg);
generateAB();
return true;
}
torch::Tensor AMMBench::PoissonMatrixLoader::getA() {
return A;
}
torch::Tensor AMMBench::PoissonMatrixLoader::getB() {
return B;
}