Skip to content

Commit

Permalink
Adding AOCL files
Browse files Browse the repository at this point in the history
  • Loading branch information
ABenC377 committed Oct 11, 2024
1 parent 9eb4646 commit 7f82b7d
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 69 deletions.
25 changes: 19 additions & 6 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 57 additions & 9 deletions include/doGemm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class doGemm {
void collectData() {
// ToDo -- I've hard coded false here as kernel selection was not working
// . Needs to be fixed
if (false) {
if (doDense_) {
// Square Problem Sizes...
// Re-initialise offload threshold structures
cpuGpu_always_ = cpuGpu_offloadThreshold();
Expand Down Expand Up @@ -301,13 +301,12 @@ class doGemm {
}
#endif
}

if (true) { // Square sparse matrix - sparse matrix multiplication
if (doSparse_) { // Square sparse matrix - sparse matrix multiplication
cpuGpu_always_ = cpuGpu_offloadThreshold();
cpuGpu_once_ = cpuGpu_offloadThreshold();
cpuGpu_unified_ = cpuGpu_offloadThreshold();
std::ofstream csvFile = initCSVFile(std::string(CSV_DIR) + "/" +
getKernelName() + "_sparse_square.csv");
getKernelName() + "_sparse_square_99.csv");
if (upperLimit_ >= 32) {
for (int dim = startDimention_; dim <= upperLimit_; dim++) {
callSparseKernels(csvFile, dim, 0.99);
Expand All @@ -316,10 +315,59 @@ class doGemm {
// Close file
csvFile.close();
#if CPU_ENABLED && GPU_ENABLED
if (doCPU_ && doGPU_) {
// Print offload results to stdout
printOffloadThreshold("Sparse Square");
}
if (doCPU_ && doGPU_) {
// Print offload results to stdout
printOffloadThreshold("Sparse Square 0.99");
}
#endif
cpuGpu_always_ = cpuGpu_offloadThreshold();
cpuGpu_once_ = cpuGpu_offloadThreshold();
cpuGpu_unified_ = cpuGpu_offloadThreshold();
csvFile = initCSVFile(std::string(CSV_DIR) + "/" +
getKernelName() + "_sparse_square_999.csv");
if (upperLimit_ >= 32) {
for (int dim = startDimention_; dim <= upperLimit_; dim++) {
callSparseKernels(csvFile, dim, 0.999);
}
}
#if CPU_ENABLED && GPU_ENABLED
if (doCPU_ && doGPU_) {
// Print offload results to stdout
printOffloadThreshold("Sparse Square 0.999");
}
#endif
cpuGpu_always_ = cpuGpu_offloadThreshold();
cpuGpu_once_ = cpuGpu_offloadThreshold();
cpuGpu_unified_ = cpuGpu_offloadThreshold();
csvFile = initCSVFile(std::string(CSV_DIR) + "/" +
getKernelName() + "_sparse_square_9999.csv");
if (upperLimit_ >= 32) {
for (int dim = startDimention_; dim <= upperLimit_; dim++) {
callSparseKernels(csvFile, dim, 0.9999);
}
}
#if CPU_ENABLED && GPU_ENABLED
if (doCPU_ && doGPU_) {
// Print offload results to stdout
printOffloadThreshold("Sparse Square 0.9999");
}
#endif
cpuGpu_always_ = cpuGpu_offloadThreshold();
cpuGpu_once_ = cpuGpu_offloadThreshold();
cpuGpu_unified_ = cpuGpu_offloadThreshold();
csvFile = initCSVFile(std::string(CSV_DIR) + "/" +
getKernelName() +
"_sparse_square_99999.csv");
if (upperLimit_ >= 32) {
for (int dim = startDimention_; dim <= upperLimit_; dim++) {
callSparseKernels(csvFile, dim, 0.99999);
}
}
#if CPU_ENABLED && GPU_ENABLED
if (doCPU_ && doGPU_) {
// Print offload results to stdout
printOffloadThreshold("Sparse Square 0.99999");
}
#endif
}
}
Expand Down Expand Up @@ -530,7 +578,7 @@ class doGemm {
spGemmCpu_.initialise(N, sparsity);
time_checksum_gflop cpuResult = spGemmCpu_.compute();
cpuResult.gflops = calcGflops(flops, iterations_, cpuResult.runtime);
writeLineToCsv(csvFile, "cpu", kernelName, N, N, N, probSize, iterations_,
writeLineToCsv(csvFile, "cpu", kernelName, N, N, N, probSize, iterations_,
cpuResult.runtime, cpuResult.gflops);
}
#endif
Expand Down
57 changes: 33 additions & 24 deletions include/doGemv.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ class doGemv {
public:
doGemv(const std::string csvDir, const int iters, const int startDim,
const int upperLimit, const bool cpuEnabled = true,
const bool gpuEnabled = true)
const bool gpuEnabled = true, const bool doDense = true, const bool
doSparse = true)
: CSV_DIR(csvDir),
iterations_(iters),
startDimention_(startDim),
upperLimit_(upperLimit),
doCPU_(cpuEnabled),
doGPU_(gpuEnabled)
doGPU_(gpuEnabled),
doDense_(doDense),
doSparse_(doSparse)
#if CPU_ENABLED
,
gemvCpu_(iterations_)
Expand All @@ -56,28 +59,29 @@ class doGemv {

/** Run all problem types and write data to CSV files. */
void collectData() {
// Square Problem Sizes...
// Re-initialise offload threshold structures & previous results
cpuGpu_always_ = cpuGpu_offloadThreshold();
cpuGpu_once_ = cpuGpu_offloadThreshold();
cpuGpu_unified_ = cpuGpu_offloadThreshold();
prev_gpuResult_always = time_checksum_gflop();
prev_gpuResult_once = time_checksum_gflop();
prev_gpuResult_unified = time_checksum_gflop();
std::ofstream csvFile =
initCSVFile(CSV_DIR + "/" + getKernelName() + "_square_vector_M=N.csv");
for (int dim = startDimention_; dim <= upperLimit_; dim++) {
// M = dim, N = dim;
callKernels(csvFile, dim, dim);
}
// Close file
csvFile.close();
#if CPU_ENABLED && GPU_ENABLED
if (doCPU_ && doGPU_) {
// Print offload results to stdout
printOffloadThreshold("Square x Vector (M=N)");
}
#endif
if (doDense_) {
// Square Problem Sizes...
// Re-initialise offload threshold structures & previous results
cpuGpu_always_ = cpuGpu_offloadThreshold();
cpuGpu_once_ = cpuGpu_offloadThreshold();
cpuGpu_unified_ = cpuGpu_offloadThreshold();
prev_gpuResult_always = time_checksum_gflop();
prev_gpuResult_once = time_checksum_gflop();
prev_gpuResult_unified = time_checksum_gflop();
std::ofstream csvFile =
initCSVFile(CSV_DIR + "/" + getKernelName() + "_square_vector_M=N.csv");
for (int dim = startDimention_; dim <= upperLimit_; dim++) {
// M = dim, N = dim;
callKernels(csvFile, dim, dim);
}
// Close file
csvFile.close();
#if CPU_ENABLED && GPU_ENABLED
if (doCPU_ && doGPU_) {
// Print offload results to stdout
printOffloadThreshold("Square x Vector (M=N)");
}
#endif

// Rectangular Problem Sizes:
// Tall and thin x Vector
Expand Down Expand Up @@ -182,6 +186,7 @@ class doGemv {
}
#endif
}
}

private:
/** Call the appropriate CPU and GPU GEMV kernels. */
Expand Down Expand Up @@ -494,6 +499,10 @@ class doGemv {
/** Whether the GPU kernels should be run. */
const bool doGPU_ = true;

/** Whether sparse and or dense kernels should be run. */
const bool doSparse_;
const bool doDense_;

#if CPU_ENABLED
/** The GEMV CPU kernel. */
cpu::gemv_cpu<T> gemvCpu_;
Expand Down
7 changes: 4 additions & 3 deletions include/kernels/CPU/sp_gemm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ namespace cpu {
// Note that the below should be the same as the edges calculation
// used in the initInputMatricesSparse function. If changed here,
// change there
nnz_ = 1 + (int) ((double)n_ * (double)n_ * (1.0 - sparsity_));
nnz_ = 1 + (uint64_t)((double)n_ * (double)n_ * (1.0 - sparsity_));

// std::cout << "\t____About to malloc()____" << std::endl;
A_ = (T*)malloc(sizeof(T) * n_ * n_);
B_ = (T*)malloc(sizeof(T) * n_ * n_);
C_ = (T*)malloc(sizeof(T) * n_ * n_);

initInputMatricesSparse(sparsity_);
initInputMatricesSparse(sparsity);

toCSR_int();
}

int nnz_;
uint64_t nnz_;

protected:

Expand Down
7 changes: 3 additions & 4 deletions include/kernels/gemm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ class gemm {
.time_since_epoch().count());
std::uniform_real_distribution<double> dist(0.0, 1.0);

int edges = 1 + (int) (n_ * n_ * (1 - sparsity));
int edges = 1 + (uint64_t)((double)n_ * (double)n_ * (1.0 - sparsity));

// Using a=0.45 and b=c=0.22 as default probabilities
for (int i = 0; i < edges; i++) {
while (!rMat(A_, n_, 0, n_ - 1, 0, n_ - 1, 0.45, 0.22, 0.22, &gen, dist,
false)) {}
false)) {}
while (!rMat(B_, n_, 0, n_ - 1, 0, n_ - 1, 0.45, 0.22, 0.22, &gen, dist,
false)) {}
false)) {}
}
}

Expand Down Expand Up @@ -165,7 +165,6 @@ class gemm {
gen, dist, bin);
}
}
return true;
}

void toCSR_int(T* dense, int n_col, int n_row, T* vals, int* col_index,
Expand Down
5 changes: 3 additions & 2 deletions include/kernels/gemv.hh
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ class gemv {
.time_since_epoch().count());
std::uniform_real_distribution<double> dist(0.0, 1.0);

int edges = 1 + (int) (n_ * n_ * (1 - sparsity_));
uint64_t edges = 1 + (uint64_t)((double)n_ * (double)n_ * (1.0 -
sparsity_));

// Using a=0.45 and b=c=0.22 as default probabilities
for (int i = 0; i < edges; i++) {
for (uint64_t i = 0; i < edges; i++) {
while (!rMat(A_, n_, 0, n_ - 1, 0, n_ - 1, 0.45, 0.22, 0.22, &gen, dist,
false)) {}
}
Expand Down
Loading

0 comments on commit 7f82b7d

Please sign in to comment.