-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
156 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
from .i_gemm import IGEMM | ||
from benchmarker.util.abstractprocess import Process | ||
|
||
|
||
class Benchmark(IGEMM): | ||
def __init__(self, params, remaining_args=None): | ||
super().__init__(params, remaining_args) | ||
assert self.params["problem"]["precision"] in ["FP32", "mixed"] | ||
|
||
def run(self): | ||
if "nb_gpus" in self.params: | ||
if self.params["nb_gpus"] > 0: | ||
raise Exception("cblas does not work on GPU") | ||
size = " ".join(map(str, self.params['problem']['size'])) | ||
path_binary = os.path.join(os.path.dirname(os.path.realpath(__file__)), | ||
"problems/gemm/cblas/main") | ||
if not os.path.isfile(path_binary): | ||
raise(RuntimeError(f"{path_binary} not found, run make manually")) | ||
command = [path_binary, | ||
self.params["problem"]["precision"], | ||
size] | ||
process = Process(command=command) | ||
result = process.get_output() | ||
std_out = result["out"] | ||
elapsed_time = float(std_out.strip()) | ||
self.params["time"] = elapsed_time | ||
self.params["GFLOP/sec"] = self.params["GFLOP"] / elapsed_time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// traditional BLAS API: | ||
// M - Number of rows in matrices A and C. | ||
// N - Number of columns in matrices B and C. | ||
// K - Number of columns in matrix A; number of rows in matrix B. | ||
// we remap from intuitive order to BLAS-style | ||
|
||
void parse_args(const int argc, | ||
char *argv[], | ||
std::string &precision, | ||
size_t &cnt_rows_A_rows_C, | ||
size_t &cnt_cols_A_rows_B, | ||
size_t &cnt_cols_B_cols_C | ||
) { | ||
if ((argc != 3) && (argc != 5)) | ||
{ | ||
std::cerr << "provide precision, m, n, k as command line parameters\n"; | ||
exit(-1); | ||
} | ||
precision = std::string(argv[1]); | ||
if (argc==3) { | ||
cnt_rows_A_rows_C = atoi(argv[2]); | ||
cnt_cols_A_rows_B = cnt_rows_A_rows_C; | ||
cnt_cols_B_cols_C = cnt_rows_A_rows_C; | ||
} | ||
else | ||
{ | ||
cnt_rows_A_rows_C = atoi(argv[2]); | ||
cnt_cols_A_rows_B = atoi(argv[3]); | ||
cnt_cols_B_cols_C = atoi(argv[4]); | ||
} | ||
} | ||
|
||
template<typename precision> | ||
void get_matrices(size_t &cnt_rows_A_rows_C, | ||
size_t &cnt_cols_A_rows_B, | ||
size_t &cnt_cols_B_cols_C, | ||
precision * & A, | ||
precision * & B, | ||
precision * & C) { | ||
size_t i; | ||
A = (precision*) malloc(sizeof(precision) * cnt_rows_A_rows_C * cnt_cols_A_rows_B); | ||
B = (precision*) malloc(sizeof(precision) * cnt_cols_A_rows_B * cnt_cols_B_cols_C); | ||
C = (precision*) malloc(sizeof(precision) * cnt_rows_A_rows_C * cnt_cols_B_cols_C); | ||
for(i=0; i < cnt_rows_A_rows_C * cnt_cols_A_rows_B; i++) { A[i] = rand()/RAND_MAX;} | ||
for(i=0; i < cnt_cols_A_rows_B * cnt_cols_B_cols_C; i++) { B[i] = rand()/RAND_MAX;} | ||
for(i=0; i < cnt_rows_A_rows_C * cnt_cols_B_cols_C; i++) { C[i] = rand()/RAND_MAX;} | ||
fprintf(stderr, "done random init\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.PHONY: run | ||
|
||
CXXFLAGS=-Wall -O3 -fopenmp --std=c++14 -msse3 -ftree-vectorize -ftree-vectorizer-verbose=3 -fopt-info-vec | ||
|
||
CFLAGS=-Wall -O3 -fopenmp -ftree-vectorize -ftree-vectorizer-verbose=3 -fopt-info-vec | ||
|
||
|
||
all: main | ||
|
||
main: main.cpp | ||
# TODO: make this customizable to build against different blas libraries | ||
$(CXX) -o $@ $^ $(CXXFLAGS) -lopenblas | ||
|
||
run: main | ||
./main 128 128 128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <iostream> | ||
#include <chrono> | ||
#include <cblas.h> | ||
#include "../args.hpp" | ||
|
||
using namespace std::chrono; | ||
|
||
|
||
|
||
int main(int argc, char * argv[]) { | ||
size_t m, n, k; | ||
float *A, *B, *C; | ||
double dtime; | ||
std::string precision; | ||
parse_args(argc, argv, precision, m, k, n); | ||
get_matrices<float>(m, k, n, A, B, C); | ||
const float alpha = 1; | ||
const float beta = 0; | ||
const size_t lda=m; // k for row major; | ||
const size_t ldb=k; //n; | ||
const size_t ldc=m; //n; | ||
auto start = high_resolution_clock::now(); | ||
if (precision == "FP32") | ||
cblas_sgemm(CblasColMajor, | ||
CblasNoTrans, | ||
CblasNoTrans, | ||
m, | ||
n, | ||
k, | ||
alpha, | ||
A, lda, | ||
B, ldb, | ||
beta, | ||
C, ldc); | ||
else | ||
{ | ||
fprintf(stderr, "not implemented yet"); | ||
throw "madamada"; | ||
} | ||
std::cerr << "MNK " << m << " " << n << " " << k << std::endl; | ||
auto stop = high_resolution_clock::now(); | ||
std::chrono::duration<double> seconds = (stop - start); | ||
dtime = seconds.count(); | ||
double gflop = (2.0 * m * n * k) / (1024 * 1024 * 1024); | ||
double gflops = gflop / dtime; | ||
printf("%f\n", dtime); | ||
fprintf(stderr, "gflops: \t%f\n", gflop); | ||
fprintf(stderr, "time: \t%f\n", dtime); | ||
fprintf(stderr, "ips: \t%f\n", 1 / dtime); | ||
fprintf(stderr, "gflops/s: \t%f\n", gflops); | ||
return 0; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
def get_data(params): | ||
return 2048 | ||
return "dummy data" | ||
|