Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparse #1

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open

Sparse #1

wants to merge 32 commits into from

Conversation

ABenC377
Copy link

@ABenC377 ABenC377 commented Feb 2, 2024

Adding in Sparse CPU Kernel. Currently just runs a square matrix with a sparsity of 0.99 for each problem size.

Copy link
Collaborator

@FinnWilkinson FinnWilkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, just a few queries about comments and project structure

iterations_, gpuTime_every,
calcGflops(calcFlops(M, N, K), iterations_, gpuTime_every));
}

void callSparseKernels(std::ofstream& csvFile, const int N, const double sparsity) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than have the sparce kernels also in doGemm, I think having a seperate do<KERNEL> for each kernel type would make it a bit easier to do kernel specific updates.

Creating a doSpMM.hh or doSpGemm.hh I think would be beneficial, copying a similar structure to this file and then adding the appropriate calls in main.cc

@@ -28,15 +28,16 @@ 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 int K, const double sparsity, const double totalProbSize, const int iters,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be worth us having a writeLineToCSV type function for each kernel? There will probably be more instances where there will be kernel specific parameters we want to print out.

using spGemm<T>::spGemm;
using spGemm<T>::n_;

/** Initialise the required data structures. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the above todo, may be worth adding to this comment what type of sparce matrix is being initialised currently

}

private:
bool rMat(std::vector<T>& M, int n, int x1, int x2, int y1, int y2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a brief comment above this function explaining what it does

int xMidPoint = x1 + (int)((x2 - x1) / 2);
int yMidPoint = y1 + (int)((y2 - y1) / 2);

// ToDo - consider if need to check for non-square matrices
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a static_assert to the top of this function to ensure the matrix is always square?

Comment on lines 85 to 87
// float newA = a;
// float newB = b;
// float newC = c;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove un-used variables

Comment on lines 112 to 113
* A return value is required to ensure that the compiler does not optimise
* away this function. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is from my implementation, but this last sentence isn't true anymore. Please remove

Comment on lines 132 to 140
void printGraph(std::vector<T> M, int n) {
std::cout << "____Printing Matrix____" << std::endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
std::cout << M[(i * n) + j] << " ";
}
std::cout << std::endl;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still used?

Comment on lines 42 to 50
while (!rMat(A_, n, 0, n-1, 0, n-1,
0.45, 0.22, 0.22,
gen, dist)) {
gen.seed(std::chrono::system_clock::now()
.time_since_epoch().count());
}
while (!rMat(B_, n, 0, n-1, 0, n-1,
0.45, 0.22, 0.22,
gen, dist)) {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment to each while explaining what is being done?

Comment on lines 17 to 18
/** Matrix size -- matrix will be nxn */
int n_ = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all matricies are always nxn then may be worth updating the comment to " -- all matrices will be nxn" to be very explicit?

Copy link
Collaborator

@FinnWilkinson FinnWilkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was meant to request changes last time...

.idea/.gitignore Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.idea/ needs adding to .gitignore

#include <vector>
#include <chrono>

#include "../include/CPU/spGemm.hh"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should follow general BLAS naming convensions and rename spGemm to spmm universally

}

private:
bool rMat(std::vector<T>* M, int n, int x1, int x2, int y1, int y2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add short comment above function detailing what it is doing

src/main.cc Outdated
Comment on lines 107 to 116
std::cout << " --dense Run only the dense matrix kernels "
"(cannot be run in combination with --sparse)" << std::endl;
std::cout << " -s --sparse Run only the sparse matrix kernels "
"(cannot be run in combination with --dense)" << std::endl;
std::cout << std::endl;
exit(0);
} else if (!strcmp(argv[i], "--sparse") || !strcmp(argv[i], "-s")) {
dense = false;
} else if (!strcmp(argv[i], "--dense")) {
sparse = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, I think having a sinlge --kernels= argument followed by a comma seperated list would be a cleaner option and avoid scenarios above where --dense cannot have -d also assigned to it.

In use, the argument would look like --kernel=gemm,spmm,gemv for example

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if --kernel is not given, we should default to running all kernels

src/main.cc Outdated
Comment on lines 58 to 59
std::cout << "\tRunning dense kernels: " << denseStr << std::endl;
std::cout << "\tRunning sparse kernels: " << sparseStr << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea of printing which kernels have been enabled. With the suggested change to the input argument, perhaps printing Running dense kernels: gemm gemv etc would mean that the print out list doesn't keep growing with each new kernel type added? Plus it gives the user 100% clarity on what exact dense / sparce kernels are being run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants