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
3 changes: 3 additions & 0 deletions include/AMMBench.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
#include <MatrixLoader/AbstractMatrixLoader.h>
#include <MatrixLoader/RandomMatrixLoader.h>
#include <MatrixLoader/SparseMatrixLoader.h>
#include <MatrixLoader/GaussianMatrixLoader.h>
#include <MatrixLoader/ExponentialMatrixLoader.h>
#include <MatrixLoader/BinomialMatrixLoader.h>
#include <MatrixLoader/MatrixLoaderTable.h>
/**
* @}
Expand Down
90 changes: 90 additions & 0 deletions include/MatrixLoader/BinomialMatrixLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// Created by haolan on 6/5/23.
//

#ifndef INTELLISTREAM_BINOMIALMATRIXLOADER_H
#define INTELLISTREAM_BINOMIALMATRIXLOADER_H
#include <MatrixLoader/AbstractMatrixLoader.h>
namespace AMMBench {
/**
* @ingroup AMMBENCH_MatrixLOADER
* @{
*/
/**
* @ingroup AMMBENCH_MatrixLOADER_Binomial The Binomial generator
* @{
*/
/**
* @class BinomialMatrixLoader MatrixLoader/BinomialMatrixLoader.h
* @brief The Binomial class of matrix loader
* @ingroup AMMBENCH_MatrixLOADER_Binomial
* @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 BinomialMatrixLoader
*/
class BinomialMatrixLoader : 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:
BinomialMatrixLoader() = default;

~BinomialMatrixLoader() = 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_Binomial
* @typedef BinomialMatrixLoaderPtr
* @brief The class to describe a shared pointer to @ref BinomialMatrixLoader

*/
typedef std::shared_ptr<class AMMBench::BinomialMatrixLoader> BinomialMatrixLoaderPtr;
/**
* @ingroup AMMBENCH_MatrixLOADER_Binomial
* @def newBinomialMatrixLoader
* @brief (Macro) To creat a new @ref BinomialMatrixLoader under shared pointer.
*/
#define newBinomialMatrixLoader std::make_shared<AMMBench::BinomialMatrixLoader>
/**
* @}
*/
/**
* @}
*/
}
#endif //INTELLISTREAM_BINOMIALMATRIXLOADER_H
90 changes: 90 additions & 0 deletions include/MatrixLoader/ExponentialMatrixLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// Created by haolan on 6/5/23.
//

#ifndef INTELLISTREAM_EXPONENTIALMATRIXLOADER_H
#define INTELLISTREAM_EXPONENTIALMATRIXLOADER_H
#include <MatrixLoader/AbstractMatrixLoader.h>
namespace AMMBench {
/**
* @ingroup AMMBENCH_MatrixLOADER
* @{
*/
/**
* @ingroup AMMBENCH_MatrixLOADER_Exponential The Exponential generator
* @{
*/
/**
* @class ExponentialMatrixLoader MatrixLoader/ExponentialMatrixLoader.h
* @brief The Exponential class of matrix loader
* @ingroup AMMBENCH_MatrixLOADER_Exponential
* @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 ExponentialMatrixLoader
*/
class ExponentialMatrixLoader : 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:
ExponentialMatrixLoader() = default;

~ExponentialMatrixLoader() = 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_Exponential
* @typedef ExponentialMatrixLoaderPtr
* @brief The class to describe a shared pointer to @ref ExponentialMatrixLoader

*/
typedef std::shared_ptr<class AMMBench::ExponentialMatrixLoader> ExponentialMatrixLoaderPtr;
/**
* @ingroup AMMBENCH_MatrixLOADER_Exponential
* @def newExponentialMatrixLoader
* @brief (Macro) To creat a new @ref ExponentialMatrixLoader under shared pointer.
*/
#define newExponentialMatrixLoader std::make_shared<AMMBench::ExponentialMatrixLoader>
/**
* @}
*/
/**
* @}
*/
}
#endif //INTELLISTREAM_EXPONENTIALMATRIXLOADER_H
90 changes: 90 additions & 0 deletions include/MatrixLoader/GaussianMatrixLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// Created by haolan on 6/5/23.
//

#ifndef INTELLISTREAM_GAUSSIANMATRIXLOADER_H
#define INTELLISTREAM_GAUSSIANMATRIXLOADER_H
#include <MatrixLoader/AbstractMatrixLoader.h>
namespace AMMBench {
/**
* @ingroup AMMBENCH_MatrixLOADER
* @{
*/
/**
* @ingroup AMMBENCH_MatrixLOADER_Gaussian The Gaussian Random generator
* @{
*/
/**
* @class GaussianMatrixLoader MatrixLoader/GaussianMatrixLoader.h
* @brief The Gaussian Random class of matrix loader
* @ingroup AMMBENCH_MatrixLOADER_Gaussian
* @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 GaussianMatrixLoader
*/
class GaussianMatrixLoader : 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:
GaussianMatrixLoader() = default;

~GaussianMatrixLoader() = 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_Gaussian
* @typedef GaussianMatrixLoaderPtr
* @brief The class to describe a shared pointer to @ref GaussianMatrixLoader

*/
typedef std::shared_ptr<class AMMBench::GaussianMatrixLoader> GaussianMatrixLoaderPtr;
/**
* @ingroup AMMBENCH_MatrixLOADER_Gaussian
* @def newGaussianMatrixLoader
* @brief (Macro) To creat a new @ref GaussianMatrixLoader under shared pointer.
*/
#define newGaussianMatrixLoader std::make_shared<AMMBench::GaussianMatrixLoader>
/**
* @}
*/
/**
* @}
*/
}
#endif //INTELLISTREAM_GAUSSIANMATRIXLOADER_H
51 changes: 51 additions & 0 deletions src/MatrixLoader/BinomialMatrixLoader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Created by haolan on 6/5/23.
//
#include <MatrixLoader/BinomialMatrixLoader.h>
#include <Utils/IntelliLog.h>
void AMMBench::BinomialMatrixLoader::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::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
torch::Tensor rand_tensor = torch::rand({(long) aRow, (long) aCol});

// Add the results of the Bernoulli trial to the binomial tensor
A += (rand_tensor < probability).to(torch::kInt);
}

for(int i = 0; i < trials; i++) {
// Create a tensor filled with random numbers between 0 and 1
torch::Tensor rand_tensor = torch::rand({(long) aCol, (long) bCol});

// Add the results of the Bernoulli trial to the binomial tensor
B += (rand_tensor < probability).to(torch::kInt);
}
}

//do nothing in abstract class
bool AMMBench::BinomialMatrixLoader::setConfig(INTELLI::ConfigMapPtr cfg) {
paraseConfig(cfg);
generateAB();
return true;
}
torch::Tensor AMMBench::BinomialMatrixLoader::getA() {
return A;
}
torch::Tensor AMMBench::BinomialMatrixLoader::getB() {
return B;
}
3 changes: 3 additions & 0 deletions src/MatrixLoader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ add_sources(
AbstractMatrixLoader.cpp
RandomMatrixLoader.cpp
SparseMatrixLoader.cpp
GaussianMatrixLoader.cpp
ExponentialMatrixLoader.cpp
BinomialMatrixLoader.cpp
MatrixLoaderTable.cpp
)
32 changes: 32 additions & 0 deletions src/MatrixLoader/ExponentialMatrixLoader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by haolan on 6/5/23.
//
#include <MatrixLoader/ExponentialMatrixLoader.h>
#include <Utils/IntelliLog.h>
void AMMBench::ExponentialMatrixLoader::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::ExponentialMatrixLoader::generateAB() {
torch::manual_seed(seed);
A = torch::exponential(torch::empty({(long) aRow, (long) aCol}));
B = torch::exponential(torch::empty({(long) aCol, (long) bCol}));
}

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