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

stream benchmark #749

Open
wants to merge 23 commits into
base: dwarfs
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ ucli.key
*.saifgen
*.json
dramsim3.txt
*.a
19 changes: 18 additions & 1 deletion examples/cuda/bfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@

REPLICANT_PATH:=$(shell git rev-parse --show-toplevel)

repos := hammerblade-helpers graph-tools

hammerblade-helpers.url = [email protected]:mrutt92/hammerblade-helpers
hammerblade-helpers.commit = master

graph-tools.url = [email protected]:mrutt92/graph-tools
graph-tools.commit = master

$(repos): %:
git clone $($*.url)
cd $* && git checkout $($*.commit)
cd $* && git submodule update --init

checkout_repos: $(repos)

include $(REPLICANT_PATH)/environment.mk

include $(EXAMPLES_PATH)/cuda/bfs/config.mk
Expand Down Expand Up @@ -134,6 +149,7 @@ tests_makefile: $(TESTS_MAKEFILE)
tests_parameters_mk: $(TESTS_PARAMETERS_MK)
tests_dir: tests_makefile tests_parameters_mk

$(TESTS): checkout_repos
$(TESTS): %: %/Makefile %/parameters.mk

TESTS_EXEC = $(addsuffix .exec,$(TESTS))
Expand Down Expand Up @@ -165,9 +181,10 @@ blood: $(TESTS_BLOOD)

# some support executables
graphtools-dir = $(EXAMPLES_PATH)/cuda/bfs/graph-tools
include $(graphtools-dir)/libgraphtools.mk
-include $(graphtools-dir)/libgraphtools.mk

SUPPORT_TOOLS = input-gen input-analyze input-degree-list
$(SUPPORT_TOOLS): checkout_repos
$(SUPPORT_TOOLS): $(libgraphtools-interface-headers)
$(SUPPORT_TOOLS): $(libgraphtools-interface-libraries)
$(SUPPORT_TOOLS): CXXFLAGS+=$(libgraphtools-interface-cxxflags)
Expand Down
1 change: 0 additions & 1 deletion examples/cuda/bfs/graph-tools
Submodule graph-tools deleted from 3c84a7
1 change: 0 additions & 1 deletion examples/cuda/bfs/hammerblade-helpers
Submodule hammerblade-helpers deleted from a80dad
92 changes: 92 additions & 0 deletions examples/cuda/dwarfs/dwarf.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
REPLICANT_PATH=$(shell git rev-parse --show-toplevel)
include $(REPLICANT_PATH)/environment.mk


# Set this to the path of your application.
# example: $(EXAMPLES_PATH)/cuda/dwarfs/spmv
ifndef APPLICATION_PATH
$(error "'APPLICATION_PATH' not defined; please define this variable to the absolute path to your application's directory")
endif

# Applications should define this function hook to add
# app specific parameters.
#
# 1: test-name
# 2: parameters.mk file name
#
# $(1) is the raw test name as found in the TESTS variable.
# $(2) is set to the parameters.mk of the test directory
# typically this is $(APPLICATION_PATH)/$(test-name)/parameters.mk
#
# example:
#
# define parameters-mk-add-application-params
# $(eval $(call get-test-parameters,$1)) # parse the test parameters from the test name
# @echo PARAM_0=$(PARAM_0) >> $2 # add first parameter
# @echo PARAM_1=$(PARAM_1) >> $2 # add second parameter
# endef

ifndef parameters-mk-add-application-params
$(warning "'parameters-mk-add-application-params' not defined; please define this function to populate parameters makefile.")
endif

# This is a list of parameterized 'tests' to run.
# A run directory will be generated for each element in this list.
# The parameters of the test should be extractable from the test name.
# This can be done by embedding the parameters in the test name (recommended).
# You can see bsg_replicant/examples/cuda/dwarfs/spmv for an example.
#
# Requirements:
#
# The following character set is reserved in a test name and should not be used:
# [.]
ifndef TESTS
$(warning "'TESTS' variable is empty. Populate this variable with a list of tests to run. Running with no tests...")
endif

TESTS_PARAMETERS_MK=$(addsuffix /parameters.mk,$(TESTS))
TESTS_MAKEFILE=$(addsuffix /Makefile,$(TESTS))

# template.mk should exist in your application's directory.
# It should include `parameters.mk` and interface with the general bsg_replicant flow.
# This file is used to create $(APPLICATION_PATH)/$(test-name)/Makefile
#
# See bsg_replicant/examples/cuda/dwarf/spmv/template.mk for an example.
$(TESTS_MAKEFILE): %/Makefile: template.mk
@echo "Creating $@"
@mkdir -p $*
@cp $< $@

$(TESTS_PARAMETERS_MK): %/parameters.mk:
@echo "Creating $@"
@mkdir -p $*
@echo APPLICATION_PATH=$(APPLICATION_PATH) > $@
@echo BSG_MANYCORE_KERNELS=$(APPLICATION_PATH)/$*/kernel.riscv >> $@
@$(call parameters-mk-add-application-params,$*,$@)

$(TESTS): %: %/Makefile %/parameters.mk

TESTS_EXEC = $(addsuffix .exec,$(TESTS))
TESTS_DEBUG = $(addsuffix .debug,$(TESTS))
TESTS_PROFILE = $(addsuffix .profile,$(TESTS))
TESTS_SAIFGEN = $(addsuffix .saifgen,$(TESTS))

$(TESTS_EXEC): %.exec: %
$(TESTS_DEBUG): %.debug: %
$(TESTS_PROFILE): %.profile: %
$(TESTS_SAIFGEN): %.saifgen: %

$(TESTS_EXEC) $(TESTS_DEBUG) $(TESTS_PROFILE) $(TESTS_SAIFGEN):
@$(eval TEST_NAME=$(firstword $(subst ., ,$@)))
@$(eval RUN_TYPE=$(lastword $(subst ., ,$@)))
@echo "Running '$(RUN_TYPE)' on test $(TEST_NAME)"
@$(MAKE) -C $(TEST_NAME) $(RUN_TYPE).log

exec: $(TESTS_EXEC)
debug: $(TEST_DEBUG)
saifgen: $(TESTS_SAIFGEN)
profile: $(TESTS_PROFILE)
tests: $(TESTS)

purge:
rm -rf $(TESTS)
22 changes: 22 additions & 0 deletions examples/cuda/dwarfs/imports/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos += graph-tools
repos += hammerblade-helpers
repos += eigen

graph-tools.url = [email protected]:mrutt92/graph-tools
hammerblade-helpers.url = [email protected]:mrutt92/hammerblade-helpers
eigen.url = https://gitlab.com/libeigen/eigen.git

graph-tools.commit = master
hammerblade-helpers.commit = master
eigen.commit = 3.3.9

all: $(repos)

$(repos):
$(eval url=$([email protected]))
$(eval commit=$([email protected]))
git clone $(url) --recursive
cd $@ && git checkout $(commit)

clean:
rm -rf $(repos)
20 changes: 20 additions & 0 deletions examples/cuda/dwarfs/include/common/sparse_matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif

typedef struct sparse_matrix {
int is_row_major;
int n_major;
int n_minor;
int n_non_zeros;
kernel_int_ptr_t mjr_nnz_ptr;
kernel_int_ptr_t mnr_off_ptr;
kernel_int_ptr_t mnr_idx_ptr;
kernel_float_ptr_t val_ptr;
} sparse_matrix_t;

#ifdef __cplusplus
}
#endif
18 changes: 18 additions & 0 deletions examples/cuda/dwarfs/include/common/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif

#ifdef __KERNEL__
typedef void* kernel_void_ptr_t;
typedef float* kernel_float_ptr_t;
typedef int* kernel_int_ptr_t;
#else
typedef hb_mc_eva_t kernel_void_ptr_t;
typedef hb_mc_eva_t kernel_float_ptr_t;
typedef hb_mc_eva_t kernel_int_ptr_t;
#endif

#ifdef __cplusplus
}
#endif
143 changes: 143 additions & 0 deletions examples/cuda/dwarfs/include/host/EigenSparseMatrix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include <Eigen/Sparse>
#include <sstream>
#include <fstream>
#include <vector>
#include <random>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iostream>
#include "Random.hpp"
#pragma once

namespace dwarfs {

namespace eigen_sparse_matrix {
/* dump non-zeros data to a file */
template <class SparseMatrixType>
void write_nnz(SparseMatrixType &mat, const std::string &fname) {
if (mat.isCompressed())
mat.uncompress();
std::ofstream ofs(fname);
using Index = typename SparseMatrixType::StorageIndex;
const Index *nnzs = mat.innerNonZeroPtr();
std::cout << "# nnz = " << mat.nonZeros() << std::endl;
std::cout << "# majors = " << mat.outerSize() << std::endl;
std::cout << "# minors = " << mat.innerSize() << std::endl;
ofs << "major,nnz" << std::endl;
for (Index i = 0; i < mat.outerSize(); i++) {
Index nnz = nnzs[i];
ofs << i << "," << nnz << std::endl;
}
}

/**
* Generates a sparse matrix with uniform number of non-zeros per row.
*/
template <class SparseMatrixType>
SparseMatrixType GenerateUniform(typename SparseMatrixType::StorageIndex rows
, typename SparseMatrixType::StorageIndex columns
, typename SparseMatrixType::StorageIndex nnz_per_row) {

using real_t = typename SparseMatrixType::Scalar;
using idx_t = typename SparseMatrixType::StorageIndex;
using Triplet = Eigen::Triplet<real_t>;
std::vector<Triplet> ijk;

// init random engine and dist
std::uniform_real_distribution<real_t> dist(-1.0, 1.0);
std::default_random_engine &gen = GLOBAL_RANDOM_ENGINE;

// make a list of column indices
std::vector<idx_t> cols;
for (int j = 0; j < columns; j++) {
cols.push_back(j);
}
std::random_shuffle(cols.begin(), cols.end());

// shuffle for each row
idx_t nnz = 0;
for (idx_t i = 0; i < rows; i++) {
// select the first nnz
for (idx_t nnz_i = 0; nnz_i < nnz_per_row; nnz_i++) {
// reshuffle and reset nnz
if (nnz == cols.size()) {
std::random_shuffle(cols.begin(), cols.end());
nnz = 0;
}
idx_t j = cols[nnz++];
real_t k = dist(gen);
ijk.push_back(Triplet(i,j,k));
}
}

SparseMatrixType mat(rows, columns);
mat.setFromTriplets(ijk.begin(), ijk.end());
mat.uncompress();
return mat;
}

/**
* Builds a sparse matrix using data from a MatrixMarket formatted file
*/
template <class SparseMatrixType>
SparseMatrixType FromAsciiNonZerosList(
const std::string &filename
, bool weighted
, bool directed
, bool zero_indexed = false) {
using real_t = typename SparseMatrixType::Scalar;
using idx_t = typename SparseMatrixType::StorageIndex;
using Triplet = Eigen::Triplet<real_t>;
std::vector<Triplet> ijk;
std::ifstream file(filename);
char line[256];

// skip comment lines starting with '%'
do {
file.getline(line, sizeof(line));
} while (line[0] == '%');

// first line is: ROWS COLS NNZ
std::stringstream ss(line);
int rows, cols, nnz;
ss >> rows;
ss >> cols;
ss >> nnz;

// init matrix and reserve triplets
SparseMatrixType mat(rows, cols);
ijk.reserve(nnz);

// continue until no more nnz
while (!file.eof()) {
idx_t i, j;
real_t k;
file >> i;
file >> j;
// some of the inputs are not zero indexed
if (!zero_indexed) {
--i;
--j;
}
// read weight if applicable
if (weighted) {
file >> k;
} else {
k = 1.0;
}

ijk.push_back(Triplet(i,j,k));
// symmetric matrix?
if (!directed) {
ijk.push_back(Triplet(j,i,k));
}
}
// use triplets to set nnz
mat.setFromTriplets(ijk.begin(), ijk.end());
mat.uncompress();
return mat;
}
}
}
6 changes: 6 additions & 0 deletions examples/cuda/dwarfs/include/host/Random.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include <memory>
#include <random>
namespace dwarfs {
extern std::default_random_engine GLOBAL_RANDOM_ENGINE;
}
2 changes: 2 additions & 0 deletions examples/cuda/dwarfs/spmm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*_input
inputs/
Loading