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 commit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BRANCH=NIGHTLY_TEST
BRANCH=count-sketch-cpp
git init
git checkout -b $BRANCH
git add .
Expand Down
4 changes: 1 addition & 3 deletions commit_info
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
1. add pure c++ algorithms
2. add normalized error and error bound evaluation at benchmark
3. update scripts
1. FIX CONFLICTS WITH MAIN
1 change: 1 addition & 0 deletions include/AMMBench.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
#include <CPPAlgos/CPPAlgoTable.h>
#include <CPPAlgos/CRSCPPAlgo.h>
#include <CPPAlgos/CRSV2CPPAlgo.h>
#include <CPPAlgos/CountSketchCPPAlgo.h>
#include <CPPAlgos/BCRSCPPAlgo.h>
#include <CPPAlgos/EWSCPPAlgo.h>
#include <CPPAlgos/CoOccurringFDCPPAlgo.h>
Expand Down
58 changes: 58 additions & 0 deletions include/CPPAlgos/CountSketchCPPAlgo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Created by luv on 5/28/23.
//

#ifndef INTELLISTREAM_COUNTSKETCHCPPALGO_H
#define INTELLISTREAM_COUNTSKETCHCPPALGO_H

#include <CPPAlgos/AbstractCPPAlgo.h>

namespace AMMBench {
/**
* @ingroup AMMBENCH_CppAlgos The algorithms writtrn in c++
* @{
*/
/**
* @class CountSketchCPPAlgo CPPAlgos/CountSketchCPPAlgo.h
* @brief The cloumn row sampling (CRS) class of c++ algos
*
*/
class CountSketchCPPAlgo : public AMMBench::AbstractCPPAlgo {
public:
CountSketchCPPAlgo() {

}

~CountSketchCPPAlgo() {

}

/**
* @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 CountSketchCPPAlgo

*/
typedef std::shared_ptr<class AMMBench::CountSketchCPPAlgo> CountSketchCPPAlgoPtr;
/**
* @ingroup AMMBENCH_CppAlgos
* @def newCRSV2CppAlgo
* @brief (Macro) To creat a new @ref CRSV2CppAlgounder shared pointer.
*/
#define newCountSketchCPPAlgo std::make_shared<AMMBench::CountSketchCPPAlgo>
}
/**
* @}
*/
#endif //INTELLISTREAM_COUNTSKETCHCPPALGO_H
4 changes: 3 additions & 1 deletion src/CPPAlgos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ add_sources(
EWSCPPAlgo.cpp
CoOccurringFDCPPAlgo.cpp
BetaCoOFDCPPAlgo.cpp
)
CountSketchCPPAlgo.cpp
)

7 changes: 6 additions & 1 deletion src/CPPAlgos/CPPAlgoTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
#include <CPPAlgos/CPPAlgoTable.h>
#include <CPPAlgos/CRSCPPAlgo.h>
#include <CPPAlgos/CRSV2CPPAlgo.h>

#include <CPPAlgos/CountSketchCPPAlgo.h>

#include <CPPAlgos/BCRSCPPAlgo.h>
#include <CPPAlgos/EWSCPPAlgo.h>
#include <CPPAlgos/CoOccurringFDCPPAlgo.h>
#include <CPPAlgos/BetaCoOFDCPPAlgo.h>

namespace AMMBench {
AMMBench::CPPAlgoTable::CPPAlgoTable() {
algoMap["mm"] = newAbstractCPPAlgo();
algoMap["crs"] = newCRSCPPAlgo();
algoMap["crsV2"] = newCRSV2CPPAlgo();
algoMap["count-sketch"] = newCountSketchCPPAlgo();
algoMap["bcrs"] = newBCRSCPPAlgo();
algoMap["ews"] = newEWSCPPAlgo();
algoMap["CoOFD"] = newCoOccurringFDCPPAlgo();
algoMap["bcoofd"] = newBetaCoOFDCPPAlgo();
}

} // AMMBench
} // AMMBench
2 changes: 1 addition & 1 deletion src/CPPAlgos/CRSV2CPPAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ namespace AMMBench {

return torch::matmul(b, B);
}
} // AMMBench
} // AMMBench
33 changes: 33 additions & 0 deletions src/CPPAlgos/CountSketchCPPAlgo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Created by haolan on 5/26/23.
//

#include <CPPAlgos/CountSketchCPPAlgo.h>

namespace AMMBench {
torch::Tensor AMMBench::CountSketchCPPAlgo::amm(torch::Tensor A, torch::Tensor B, int k) {
int64_t m1 = A.size(0);
int64_t n = A.size(1);
int64_t m2 = B.size(1);

// Initialize sketch matrices
torch::Tensor Ca = torch::zeros({m1, k});
torch::Tensor Cb = torch::zeros({k, m2});

torch::Tensor L = torch::randint(k, {n});
torch::Tensor G = torch::randint(2, {n});

// Modify the random column with random sign
for (int64_t i = 0; i < n; ++i) {
if (G[i].item<int>() == 1) {
Ca.index({torch::indexing::Slice(), L[i]}).add_(A.index({torch::indexing::Slice(), i}));
Cb.index({L[i], torch::indexing::Slice()}).add_(B.index({i, torch::indexing::Slice()}));
} else {
Ca.index({torch::indexing::Slice(), L[i]}).sub_(A.index({torch::indexing::Slice(), i}));
Cb.index({L[i], torch::indexing::Slice()}).sub_(B.index({i, torch::indexing::Slice()}));
}
}

return torch::matmul(Ca, Cb);
}
} // AMMBench
17 changes: 15 additions & 2 deletions test/SystemTest/SketchTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,22 @@ auto B = torch::rand({(long) aCol, (long) bCol});*/
TEST_CASE("Test the counter sketch", "[short]")
{
int a = 0;
runSingleThreadTest("scripts/config_counterSketch.csv");
runSingleThreadTest("scripts/config_countSketch.csv");
// place your test here
REQUIRE(a == 0);
}

TEST_CASE("Test Count Sketch in cpp", "[short]")
{
torch::manual_seed(114514);
AMMBench::CountSketchCPPAlgo cs;
auto A = torch::rand({400, 400});
auto B = torch::rand({400, 400});
auto realC = torch::matmul(A, B);
auto ammC = cs.amm(A, B, 20);
double froError = INTELLI::UtilityFunctions::relativeFrobeniusNorm(realC, ammC);
REQUIRE(froError < 0.5);
}
TEST_CASE("Test Co-Occurring FD in cpp", "[short]")
{
torch::manual_seed(114514);
Expand All @@ -75,4 +87,5 @@ TEST_CASE("Test Beta-Co-Occurring FD in cpp", "[short]")
auto ammC = bcoofd.amm(A, B, 20);
double froError = INTELLI::UtilityFunctions::relativeFrobeniusNorm(realC, ammC);
REQUIRE(froError < 0.2);
}
}