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: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ add_subdirectory(src)
# Add Library
get_sources(IntelliStream_SOURCE_FILES)
get_headers(IntelliStream_HEADER_FILES)
add_library(IntelliStream SHARED ${IntelliStream_SOURCE_FILES} ${IntelliStream_HEADER_FILES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
add_library(IntelliStream SHARED ${IntelliStream_SOURCE_FILES} ${IntelliStream_HEADER_FILES} ${CMAKE_CURRENT_BINARY_DIR})
set_property(TARGET IntelliStream PROPERTY CXX_STANDARD 20)

target_include_directories(IntelliStream PUBLIC "include")
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ auto B = torch::rand({(long) aCol, (long) bCol});*/
AMMBench::CPPAlgoTable cppAlgoTable;
std::string cppAlgoTag = cfg->tryString("cppAlgoTag", "mm", true);
AMMBench::AbstractCPPAlgoPtr cppAlgoPtr = cppAlgoTable.findCppAlgo(cppAlgoTag);
INTELLI_WARNING("single thread");
INTELLI_WARNING("single thread, algo "+cppAlgoTag);
if (eMeter != nullptr) {
eMeter->startMeter();
}
Expand Down
2 changes: 1 addition & 1 deletion commit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BRANCH=core-bind-bug
BRANCH=uint64_t-bug
git init
git checkout -b $BRANCH
git add .
Expand Down
3 changes: 2 additions & 1 deletion commit_info
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
1. update docs
1. fix the uint64_t bugs
2. Note; please note the int8 is just a toy
3 changes: 3 additions & 0 deletions include/AMMBench.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
#include <CPPAlgos/EWSCPPAlgo.h>
#include <CPPAlgos/CoOccurringFDCPPAlgo.h>
#include <CPPAlgos/BetaCoOFDCPPAlgo.h>

#include <CPPAlgos/INT8CPPAlgo.h>

#include <CPPAlgos/TugOfWarCPPAlgo.h>
/**
* @}
Expand Down
2 changes: 1 addition & 1 deletion include/CPPAlgos/BCRSCPPAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace AMMBench {
* @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);
virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize);

};

Expand Down
2 changes: 1 addition & 1 deletion include/CPPAlgos/BetaCoOFDCPPAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace AMMBench {
* @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);
virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize);

};

Expand Down
2 changes: 1 addition & 1 deletion include/CPPAlgos/CRSV2CPPAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace AMMBench {
* @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);
virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize);

};

Expand Down
2 changes: 1 addition & 1 deletion include/CPPAlgos/CoOccurringFDCPPAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace AMMBench {
* @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);
virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize);

};

Expand Down
2 changes: 1 addition & 1 deletion include/CPPAlgos/CountSketchCPPAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace AMMBench {
* @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);
torch::Tensor amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize) ;

};

Expand Down
2 changes: 1 addition & 1 deletion include/CPPAlgos/EWSCPPAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace AMMBench {
* @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);
virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize);

};

Expand Down
60 changes: 60 additions & 0 deletions include/CPPAlgos/INT8CPPAlgo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*! \file INT8CPPAlgo.h*/
//
// Created by tony on 25/05/23.
//

#ifndef INTELLISTREAM_INCLUDE_CPPALGOS_INT8CPPALGO_H_
#define INTELLISTREAM_INCLUDE_CPPALGOS_INT8CPPALGO_H_
#include <Utils/AbstractC20Thread.hpp>
#include <Utils/ConfigMap.hpp>
#include <torch/torch.h>
#include <torch/script.h>
#include <memory>
#include <vector>
#include <CPPAlgos/AbstractCPPAlgo.h>
namespace AMMBench {
/**
* @ingroup AMMBENCH_CppAlgos The algorithms written in c++
* @{
*/
/**
* @class INT8CPPAlgo CPPAlgos/INT8CPPAlgo.h
* @brief The INT8 MM class of c++ algos
*/
class INT8CPPAlgo: public AMMBench::AbstractCPPAlgo {
public:
INT8CPPAlgo() {

}
~INT8CPPAlgo() {

}
/**
* @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, uint64_t sketchSize);

};
/**
* @ingroup AMMBENCH_CppAlgos
* @typedef INT8MatrixCppAlgoPtr
* @brief The class to describe a shared pointer to @ref INT8CPPAlgo

*/
typedef std::shared_ptr<class AMMBench::INT8CPPAlgo> INT8CPPAlgoPtr;
/**
* @ingroup AMMBENCH_CppAlgos
* @def newINT8CppAlgo
* @brief (Macro) To creat a new @ref INT8CppAlgo shared pointer.
*/
#define newINT8CPPAlgo std::make_shared<AMMBench::INT8CPPAlgo>
}
/**
* @}
*/

#endif //INTELLISTREAM_INCLUDE_CPPALGOS_ABSTRACTCPPALGO_H_
1 change: 1 addition & 0 deletions src/CPPAlgos/AbstractCPPAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#include <CPPAlgos/AbstractCPPAlgo.h>
torch::Tensor AMMBench::AbstractCPPAlgo::amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize) {
std::cout << sketchSize;
INTELLI_INFO("I am mm");
return torch::matmul(A, B);
}
4 changes: 2 additions & 2 deletions src/CPPAlgos/BCRSCPPAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#include <CPPAlgos/BCRSCPPAlgo.h>

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

int64_t k=(int64_t)k2;
assert(n == B.size(0));
//TORCH_CHECK(n == B.size(0));
//TORCH_CHECK(k < n);
Expand Down
14 changes: 7 additions & 7 deletions src/CPPAlgos/BetaCoOFDCPPAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ torch::Tensor paramerizedReduceRank(const torch::Tensor& SV, float delta, int l,
return SV_shrunk;
}

torch::Tensor BetaCoOFDCPPAlgo::amm(const torch::Tensor A, const torch::Tensor B, int l) {
torch::Tensor BetaCoOFDCPPAlgo::amm(const torch::Tensor A, const torch::Tensor B, uint64_t l2) {
torch::Tensor B_t = B.t();
float beta = 1.0;

TORCH_CHECK(A.size(1) == B_t.size(1), "Shapes of A and B are incompatible");
int mx = A.size(0);
int my = B_t.size(0);
int n = A.size(1);

int64_t mx = A.size(0);
int64_t my = B_t.size(0);
int64_t n = A.size(1);
int64_t l=(int64_t)l2;
// Initialize sketch matrices
torch::Tensor BX = torch::zeros({ mx, l });
torch::Tensor BY = torch::zeros({ my, l });

// The first l iterations
for (int i = 0; i < l; ++i) {
for (int64_t i = 0; i < l; ++i) {
BX.slice(1, i, i + 1) = A.slice(1, i, i + 1);
BY.slice(1, i, i + 1) = B_t.slice(1, i, i + 1);
}
Expand All @@ -51,7 +51,7 @@ torch::Tensor BetaCoOFDCPPAlgo::amm(const torch::Tensor A, const torch::Tensor B
zero_columns = zero_columns.slice(0, 1);

// Iteration l to n: insert if available, else shrink sketch matrices
for (int i = l; i < n; ++i) {
for (int64_t i = l; i < n; ++i) {
// Acquire the index of a zero-valued column
if (!is_empty_tensor(zero_columns)) {
int idx = get_first_element(zero_columns).toInt();
Expand Down
1 change: 1 addition & 0 deletions src/CPPAlgos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_sources(
CoOccurringFDCPPAlgo.cpp
BetaCoOFDCPPAlgo.cpp
CountSketchCPPAlgo.cpp
INT8CPPAlgo.cpp
TugOfWarCPPAlgo.cpp
)

7 changes: 5 additions & 2 deletions src/CPPAlgos/CPPAlgoTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@
#include <CPPAlgos/EWSCPPAlgo.h>
#include <CPPAlgos/CoOccurringFDCPPAlgo.h>
#include <CPPAlgos/BetaCoOFDCPPAlgo.h>
#include <CPPAlgos/TugOfWarCPPAlgo.h>

#include <CPPAlgos/INT8CPPAlgo.h>

#include <CPPAlgos/TugOfWarCPPAlgo.h>
namespace AMMBench {
AMMBench::CPPAlgoTable::CPPAlgoTable() {
algoMap["mm"] = newAbstractCPPAlgo();
algoMap["crs"] = newCRSCPPAlgo();
algoMap["crsV2"] = newCRSV2CPPAlgo();
algoMap["count-sketch"] = newCountSketchCPPAlgo();
algoMap["countSketch"] = newCountSketchCPPAlgo();
algoMap["bcrs"] = newBCRSCPPAlgo();
algoMap["ews"] = newEWSCPPAlgo();
algoMap["CoOFD"] = newCoOccurringFDCPPAlgo();
algoMap["bcoofd"] = newBetaCoOFDCPPAlgo();
algoMap["int8"] = newINT8CPPAlgo();
algoMap["tug-of-war"] = newTugOfWarCPPAlgo();
}

Expand Down
4 changes: 2 additions & 2 deletions src/CPPAlgos/CRSV2CPPAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <CPPAlgos/CRSV2CPPAlgo.h>

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

int64_t k=(int64_t)k2;
assert(n == B.size(0));
//TORCH_CHECK(n == B.size(0));
//TORCH_CHECK(k < n);
Expand Down
10 changes: 5 additions & 5 deletions src/CPPAlgos/CoOccurringFDCPPAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ torch::Tensor medianReduceRank(const torch::Tensor& SV, float delta) {
return torch::clamp(SV - delta, 0);
}

torch::Tensor CoOccurringFDCPPAlgo::amm(const torch::Tensor A, const torch::Tensor B, int l) {
torch::Tensor CoOccurringFDCPPAlgo::amm(const torch::Tensor A, const torch::Tensor B, uint64_t l2) {
torch::Tensor B_t = B.t();

TORCH_CHECK(A.size(1) == B_t.size(1), "Shapes of A and B are incompatible");
int mx = A.size(0);
int my = B_t.size(0);
int n = A.size(1);

int64_t mx = A.size(0);
int64_t my = B_t.size(0);
int64_t n = A.size(1);
int64_t l= (int64_t) l2;
// Initialize sketch matrices
torch::Tensor BX = torch::zeros({ mx, l });
torch::Tensor BY = torch::zeros({ my, l });
Expand Down
5 changes: 3 additions & 2 deletions src/CPPAlgos/CountSketchCPPAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include <CPPAlgos/CountSketchCPPAlgo.h>

namespace AMMBench {
torch::Tensor AMMBench::CountSketchCPPAlgo::amm(torch::Tensor A, torch::Tensor B, int k) {
torch::Tensor AMMBench::CountSketchCPPAlgo::amm(torch::Tensor A, torch::Tensor B, uint64_t k2) {
INTELLI_INFO("I am counter sketch");
int64_t m1 = A.size(0);
int64_t n = A.size(1);
int64_t m2 = B.size(1);

int64_t k=(int64_t) k2;
// Initialize sketch matrices
torch::Tensor Ca = torch::zeros({m1, k});
torch::Tensor Cb = torch::zeros({k, m2});
Expand Down
4 changes: 2 additions & 2 deletions src/CPPAlgos/EWSCPPAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include <CPPAlgos/EWSCPPAlgo.h>

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

int64_t k=(int64_t) k2;
TORCH_CHECK(n == B.size(0));
TORCH_CHECK(k < n);

Expand Down
45 changes: 45 additions & 0 deletions src/CPPAlgos/INT8CPPAlgo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

// Created by tony on 25/05/23.
//

#include <CPPAlgos/INT8CPPAlgo.h>
torch::Tensor AMMBench::INT8CPPAlgo::amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize) {
std::cout << sketchSize;
float scalingA,scalingB;
// int16_t mulab;

/*auto AINT8=(A*scalingA).to(torch::kInt8);
auto BTINT8=(Bt*scalingB).to(torch::kInt8);*/
// return C;
/*
for(int64_t i=0;i<rows;i++)
{
for(int64_t j=0;j<cols;j++)
{
ta=AINT8[i];
tb=BTINT8[j];

int32_t ru=0;
float ruf=0.0;

for(int64_t k=0;k<sumS;k++)
{

int8_t tak=ta[k].item<int8_t>();
int8_t tbk=tb[k].item<int8_t>();
mulab=tak*tbk;
ru+=mulab;
}
ruf=ru;
C[i][j]=ruf;
}
}*/
scalingA=torch::abs(A).max().item<float>()/127.0;
scalingB=torch::abs(B).max().item<float>()/127.0;
auto ta=(A/scalingA).to(torch::kInt8);
auto tb= (B/scalingB).to(torch::kInt8);
// torch::matmul(ta, tb);
return torch::zeros({A.size(0), B.size(1)});
return torch::matmul(ta, tb).to(torch::kFloat)*scalingA*scalingB;
//return C*scalingA*scalingB/127.0/127.0;
}
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ add_catch_test(ews_test SystemTest/EWSTest.cpp IntelliStream)
add_catch_test(weighted_cr_test SystemTest/WeightedCRTest.cpp IntelliStream)
add_catch_test(block_partition_test SystemTest/BlockPartitionTest.cpp IntelliStream)
add_catch_test(tug_of_war_test SystemTest/TugOfWarTest.cpp IntelliStream)
add_catch_test(int8_test SystemTest/INT8Test.cpp IntelliStream)

24 changes: 24 additions & 0 deletions test/SystemTest/INT8Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by tony on 05/06/23.
//
#include <vector>

#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <AMMBench.h>
#include <iostream>
TEST_CASE("Test int8", "[short]")
{
torch::manual_seed(114514);
AMMBench::INT8CPPAlgo int8mm;
auto A = torch::rand({4, 4});
auto B = torch::rand({4, 4});
auto realC = torch::matmul(A, B);
auto ammC = int8mm.amm(A, B, 20);
std::cout<<"int8:"<<std::endl;
std::cout<<ammC<<std::endl;
std::cout<<"fp32:"<<std::endl;
std::cout<<realC<<std::endl;
double froError = INTELLI::UtilityFunctions::relativeFrobeniusNorm(realC, ammC);
REQUIRE(froError < 0.5);
}