This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from gunrock/bench
Benchmarking support, cmake version++, and sample csr()
- Loading branch information
Showing
10 changed files
with
225 additions
and
17 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
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,20 @@ | ||
set(BENCHMARK_SOURCES | ||
for.cu | ||
) | ||
|
||
foreach(SOURCE IN LISTS BENCHMARK_SOURCES) | ||
get_filename_component(BENCHMARK_NAME ${SOURCE} NAME_WLE) | ||
add_executable(${BENCHMARK_NAME} ${SOURCE}) | ||
target_link_libraries(${BENCHMARK_NAME} | ||
PRIVATE essentials | ||
PRIVATE nvbench::main | ||
) | ||
get_target_property(ESSENTIALS_ARCHITECTURES | ||
essentials CUDA_ARCHITECTURES | ||
) | ||
set_target_properties(${BENCHMARK_NAME} | ||
PROPERTIES | ||
CUDA_ARCHITECTURES ${ESSENTIALS_ARCHITECTURES} | ||
) | ||
message(STATUS "Benchmark Added: ${BENCHMARK_NAME}") | ||
endforeach() |
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 @@ | ||
#include <gunrock/error.hxx> | ||
#include <gunrock/graph/graph.hxx> | ||
#include <gunrock/formats/formats.hxx> | ||
#include <gunrock/cuda/cuda.hxx> | ||
#include <gunrock/framework/operators/for/for.hxx> | ||
#include <gunrock/util/sample.hxx> | ||
|
||
#include <nvbench/nvbench.cuh> | ||
|
||
namespace gunrock { | ||
namespace benchmark { | ||
void parallel_for(nvbench::state& state) { | ||
auto csr = sample::csr(); | ||
|
||
// -- | ||
// Build graph | ||
|
||
auto G = graph::build::from_csr<memory_space_t::device, graph::view_t::csr>( | ||
csr.number_of_rows, // rows | ||
csr.number_of_columns, // columns | ||
csr.number_of_nonzeros, // nonzeros | ||
csr.row_offsets.data().get(), // row_offsets | ||
csr.column_indices.data().get(), // column_indices | ||
csr.nonzero_values.data().get() // values | ||
); | ||
|
||
// Initialize the context. | ||
cuda::device_id_t device = 0; | ||
cuda::multi_context_t context(device); | ||
|
||
vector_t<int> vertices(G.get_number_of_vertices()); | ||
auto d_vertices = vertices.data().get(); | ||
|
||
auto f = [=] __device__(int const& v) -> void { d_vertices[v] = v; }; | ||
|
||
state.exec(nvbench::exec_tag::sync, [&](nvbench::launch& launch) { | ||
operators::parallel_for::execute<operators::parallel_for_each_t::vertex>( | ||
G, // graph | ||
f, // lambda function | ||
context // context | ||
); | ||
}); | ||
} | ||
|
||
NVBENCH_BENCH(parallel_for).set_name("parallel_for"); | ||
|
||
} // namespace benchmark | ||
} // namespace gunrock |
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
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,27 @@ | ||
include(FetchContent) | ||
set(FETCHCONTENT_QUIET ON) | ||
|
||
message(STATUS "Cloning External Project: NVBench") | ||
get_filename_component(FC_BASE "../externals" | ||
REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") | ||
set(FETCHCONTENT_BASE_DIR ${FC_BASE}) | ||
|
||
FetchContent_Declare( | ||
nvbench | ||
GIT_REPOSITORY https://github.com/NVIDIA/nvbench.git | ||
GIT_TAG main | ||
) | ||
|
||
FetchContent_GetProperties(nvbench) | ||
if(NOT nvbench_POPULATED) | ||
FetchContent_Populate( | ||
nvbench | ||
) | ||
endif() | ||
|
||
# Exposing nvbench's source and include directory | ||
set(NVBENCH_INCLUDE_DIR "${nvbench_SOURCE_DIR}") | ||
set(NVBENCH_BUILD_DIR "${nvbench_BINARY_DIR}") | ||
|
||
# Add subdirectory ::nvbench | ||
add_subdirectory(${NVBENCH_INCLUDE_DIR} ${NVBENCH_BUILD_DIR}) |
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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @file sample.hxx | ||
* @author Muhammad Osama (mosama@ucdavis.edu) | ||
* @brief | ||
* @version 0.1 | ||
* @date 2021-12-23 | ||
* | ||
* @copyright Copyright (c) 2021 | ||
* | ||
*/ | ||
#pragma once | ||
|
||
#include <gunrock/formats/formats.hxx> | ||
|
||
namespace gunrock { | ||
namespace sample { | ||
|
||
using namespace memory; | ||
|
||
template <memory_space_t space = memory_space_t::device, | ||
typename vertex_t = int, | ||
typename edge_t = int, | ||
typename weight_t = float> | ||
format::csr_t<space, vertex_t, edge_t, weight_t> csr() { | ||
// Logical Matrix Representation | ||
// r/c 0 1 2 3 | ||
// 0 [ 0 0 0 0 ] | ||
// 1 [ 5 8 0 0 ] | ||
// 2 [ 0 0 3 0 ] | ||
// 3 [ 0 6 0 0 ] | ||
|
||
// Logical Graph Representation | ||
// (i, j) [w] | ||
// (1, 0) [5] | ||
// (1, 1) [8] | ||
// (2, 2) [3] | ||
// (3, 1) [6] | ||
|
||
// CSR Matrix Representation | ||
// V = [ 5 8 3 6 ] | ||
// COL_INDEX = [ 0 1 2 1 ] | ||
// ROW_OFFSETS = [ 0 0 2 3 4 ] | ||
using csr_t = format::csr_t<memory_space_t::host, vertex_t, edge_t, weight_t>; | ||
csr_t matrix(4, 4, 4); | ||
|
||
// Row Offsets | ||
matrix.row_offsets[0] = 0; | ||
matrix.row_offsets[1] = 0; | ||
matrix.row_offsets[2] = 2; | ||
matrix.row_offsets[3] = 3; | ||
matrix.row_offsets[4] = 4; | ||
|
||
// Column Indices | ||
matrix.column_indices[0] = 0; | ||
matrix.column_indices[1] = 1; | ||
matrix.column_indices[2] = 2; | ||
matrix.column_indices[3] = 3; | ||
|
||
// Non-zero values | ||
matrix.nonzero_values[0] = 5; | ||
matrix.nonzero_values[1] = 8; | ||
matrix.nonzero_values[2] = 3; | ||
matrix.nonzero_values[3] = 6; | ||
|
||
if (space == memory_space_t::host) { | ||
return matrix; | ||
} else { | ||
using d_csr_t = | ||
format::csr_t<memory_space_t::device, vertex_t, edge_t, weight_t>; | ||
d_csr_t d_matrix(matrix); | ||
return d_matrix; | ||
} | ||
} | ||
|
||
} // namespace sample | ||
} // namespace gunrock |