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 7f82b7d commit 0130b81
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 32 deletions.
23 changes: 15 additions & 8 deletions .idea/workspace.xml

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

84 changes: 84 additions & 0 deletions ArmPL/sp_gemm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,90 @@ class sp_gemm_cpu : public sp_gemm<T> {
void preLoopRequirements() override {
// Need to put A_ and B_ into A_armpl_ and B_armpl_
toCSR_armpl();

/** providing hints to ARMPL and optimizing the matrix datastructures */
// TODO -- is noallocs best here?
status_ = armpl_spmat_hint(A_armpl_, ARMPL_SPARSE_HINT_MEMORY,
ARMPL_SPARSE_MEMORY_NOALLOCS);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}
status_ = armpl_spmat_hint(B_armpl_, ARMPL_SPARSE_HINT_MEMORY,
ARMPL_SPARSE_MEMORY_NOALLOCS);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}

status_ = armpl_spmat_hint(A_armpl_, ARMPL_SPARSE_HINT_STRUCTURE,
ARMPL_SPARSE_STRUCTURE_UNSTRUCTURED);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}
status_ = armpl_spmat_hint(B_armpl_, ARMPL_SPARSE_HINT_STRUCTURE,
ARMPL_SPARSE_STRUCTURE_UNSTRUCTURED);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}

// TODO -- will this be FEW?
status_ = armpl_spmat_hint(A_armpl_, ARMPL_SPARSE_HINT_SPMM_INVOCATIONS,
ARMPL_SPARSE_INVOCATIONS_MANY);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}
status_ = armpl_spmat_hint(B_armpl_, ARMPL_SPARSE_HINT_SPMM_INVOCATIONS,
ARMPL_SPARSE_INVOCATIONS_MANY);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}

status_ = armpl_spmat_hint(A_armpl_, ARMPL_SPARSE_HINT_SPMM_OPERATION,
ARMPL_SPARSE_OPERATION_NOTRANS);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}
status_ = armpl_spmat_hint(B_armpl_, ARMPL_SPARSE_HINT_SPMM_OPERATION,
ARMPL_SPARSE_OPERATION_NOTRANS);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}

// TODO -- investigate whch is better here
status_ = armpl_spmat_hint(A_armpl_, ARMPL_SPARSE_HINT_SPMM_STRATEGY,
ARMPL_SPARSE_SPMM_STRAT_OPT_PART_STRUCT);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}
status_ = armpl_spmat_hint(B_armpl_, ARMPL_SPARSE_HINT_SPMM_STRATEGY,
ARMPL_SPARSE_SPMM_STRAT_OPT_PART_STRUCT);
if (status_ != ARMPL_STATUS_SUCCESS) {
std::cout << "ERROR " << status_ << std::endl;
exit(1);
}

// TODO -- this is thorwing an error -- couldn't immediately fix so come
// back to

// /** provide hints for the optimisation of the spmm execution */
// status_ = armpl_spmm_optimize(ARMPL_SPARSE_OPERATION_NOTRANS,
// ARMPL_SPARSE_OPERATION_NOTRANS,
// ARMPL_SPARSE_SCALAR_ONE,
// A_armpl_, B_armpl_,
// ARMPL_SPARSE_SCALAR_ZERO,
// C_armpl_);
// if (status_ != ARMPL_STATUS_SUCCESS) {
// std::cout << "ERROR " << status_ << std::endl;
// exit(1);
// }
}

/** Perform any required steps after calling the GEMM kernel that should
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CXX = $(CXX_$(COMPILER))

CXXFLAGS_ARM = -std=c++17 -Wall -Ofast -$(ARCHFLAG)=native
CXXFLAGS_CLANG = -std=c++17 -Wall -Ofast -$(ARCHFLAG)=native
CXXFLAGS_GNU = -std=c++17 -Wall -Ofast -$(ARCHFLAG)=native
CXXFLAGS_GNU = -std=c++17 -Wall -Wno-deprecated-declarations -Ofast -$(ARCHFLAG)=native
CXXFLAGS_INTEL = -std=c++17 -Wall -Ofast -$(ARCHFLAG)=native -Wno-tautological-constant-compare
CXXFLAGS_NVIDIA = -std=c++17 -Wall -O3 -fast -$(ARCHFLAG)=native
CXXFLAGS_HIP = -std=c++17 -Wall -Ofast -$(ARCHFLAG)=native
Expand Down
26 changes: 14 additions & 12 deletions include/doGemm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ class doGemm {
cpuResult = gemmCpu_.compute();
cpuResult.gflops = calcGflops(flops, iterations_, cpuResult.runtime);
// Write result to CSV file
writeLineToCsv(csvFile, "cpu", kernelName, M, N, K, probSize, iterations_,
cpuResult.runtime, cpuResult.gflops);
writeLineToCsv(csvFile, "cpu", kernelName, M, N, K, probSize,
0.0, iterations_, cpuResult.runtime, cpuResult.gflops);
}
#endif

Expand Down Expand Up @@ -422,13 +422,13 @@ class doGemm {

// Write results to CSV file
writeLineToCsv(csvFile, "gpu_offloadOnce", kernelName, M, N, K, probSize,
iterations_, gpuResult_once.runtime,
0.0, iterations_, gpuResult_once.runtime,
gpuResult_once.gflops);
writeLineToCsv(csvFile, "gpu_offloadAlways", kernelName, M, N, K,
probSize, iterations_, gpuResult_always.runtime,
probSize, 0.0, iterations_, gpuResult_always.runtime,
gpuResult_always.gflops);
writeLineToCsv(csvFile, "gpu_unified", kernelName, M, N, K, probSize,
iterations_, gpuResult_unified.runtime,
0.0, iterations_, gpuResult_unified.runtime,
gpuResult_unified.gflops);
}
#endif
Expand Down Expand Up @@ -578,8 +578,9 @@ 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_,
cpuResult.runtime, cpuResult.gflops);
writeLineToCsv(csvFile, "cpu", kernelName, N, N, N, probSize,
sparsity, iterations_, cpuResult.runtime,
cpuResult.gflops);
}
#endif
#if GPU_ENABLED
Expand Down Expand Up @@ -607,13 +608,14 @@ class doGemm {

// Write lines to CSV file
writeLineToCsv(csvFile, "gpu_offloadOnce", kernelName, N, N, N, probSize,
iterations_, gpuResult_once.runtime, gpuResult_once.gflops);
sparsity, iterations_, gpuResult_once.runtime,
gpuResult_once.gflops);
writeLineToCsv(csvFile, "gpu_offloadAlways", kernelName, N, N, N, probSize,
iterations_, gpuResult_always.runtime,
gpuResult_always.gflops);
sparsity, iterations_, gpuResult_always.runtime,
gpuResult_always.gflops);
writeLineToCsv(csvFile, "gpu_unified", kernelName, N, N, N, probSize,
iterations_, gpuResult_unified.runtime,
gpuResult_unified.gflops);
sparsity, iterations_, gpuResult_unified.runtime,
gpuResult_unified.gflops);

}
#endif
Expand Down
12 changes: 6 additions & 6 deletions include/doGemv.hh
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ class doGemv {
cpuResult = gemvCpu_.compute();
cpuResult.gflops = calcGflops(flops, iterations_, cpuResult.runtime);
// Write result to CSV file
writeLineToCsv(csvFile, "cpu", kernelName, M, N, 0, probSize, iterations_,
cpuResult.runtime, cpuResult.gflops);
writeLineToCsv(csvFile, "cpu", kernelName, M, N, 0, probSize, 0.0,
iterations_, cpuResult.runtime, cpuResult.gflops);
}
#endif

Expand Down Expand Up @@ -237,13 +237,13 @@ class doGemv {

// Write results to CSV file
writeLineToCsv(csvFile, "gpu_offloadOnce", kernelName, M, N, 0, probSize,
iterations_, gpuResult_once.runtime,
0.0, iterations_, gpuResult_once.runtime,
gpuResult_once.gflops);
writeLineToCsv(csvFile, "gpu_offloadAlways", kernelName, M, N, 0,
probSize, iterations_, gpuResult_always.runtime,
probSize, 0.0, iterations_, gpuResult_always.runtime,
gpuResult_always.gflops);
writeLineToCsv(csvFile, "gpu_unified", kernelName, M, N, 0, probSize,
iterations_, gpuResult_unified.runtime,
0.0, iterations_, gpuResult_unified.runtime,
gpuResult_unified.gflops);
}
#endif
Expand Down Expand Up @@ -500,8 +500,8 @@ class doGemv {
const bool doGPU_ = true;

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

#if CPU_ENABLED
/** The GEMV CPU kernel. */
Expand Down
12 changes: 7 additions & 5 deletions include/helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ std::ofstream initCSVFile(const std::string filename) {

std::ofstream newFile(filename);

newFile << "Device,Kernel,M,N,K,Total Problem Size (KiB),Iterations,Total "
"Seconds,GFLOP/s"
newFile << "Device,Kernel,M,N,K,Total Problem Size (KiB),sparsity,Iterations,"
"Total Seconds,GFLOP/s"
<< std::endl;

return newFile;
Expand All @@ -28,15 +28,17 @@ std::ofstream initCSVFile(const std::string filename) {
* Function does not close the file. */
void writeLineToCsv(std::ofstream& file, const std::string device,
const std::string kernel, const int M, const int N,
const int K, const double totalProbSize, const int iters,
const double totalTime, const double gflops) {
const int K, const double totalProbSize, const float
sparsity, const int iters, const double totalTime,
const double gflops) {
if (!file.is_open()) {
std::cout << "ERROR - Attempted to write line to a closed CSV file."
<< std::endl;
exit(1);
}
file << device << "," << kernel << "," << M << "," << N << "," << K << ","
<< std::fixed << std::setprecision(3) << totalProbSize << "," << iters
<< std::fixed << std::setprecision(3) << totalProbSize << ","
<< std::fixed << std::setprecision(8) << sparsity << "," << iters
<< "," << std::fixed << std::setprecision(5) << totalTime << ","
<< std::fixed << std::setprecision(3) << gflops << std::endl;
}
Expand Down

0 comments on commit 0130b81

Please sign in to comment.