Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
31 changes: 20 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
# CMakeLists.txt
cmake_minimum_required(VERSION 3.25)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

include(DisableIntree)

project(Spatter VERSION 2.0.0 LANGUAGES CXX)
option(USE_CUDA "Enable CUDA support" OFF)
option(USE_HIP "Enable HIP support" ON)

if(USE_CUDA AND USE_HIP)
message(FATAL_ERROR "Cannot enable both CUDA and HIP simultaneously. Choose one.")
endif()

if(USE_HIP)
if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER "hipcc" CACHE STRING "HIP C++ Compiler" FORCE)
endif()
project(Spatter VERSION 2.0.0 LANGUAGES CXX HIP)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be 2.2.0

include(pkgs/HIPSupport)
else()
project(Spatter VERSION 2.0.0 LANGUAGES CXX)
if(USE_CUDA)
include(pkgs/CUDASupport)
endif()
endif()

include(GNUInstallDirs)

include(BuildType)
include(CompilerType)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)

set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(pkgs/JSONSupport)
include(pkgs/MPISupport)
include(pkgs/OpenMPSupport)
include(pkgs/CUDASupport)

# Create gz_read executable
add_executable(gz_read standard-suite/binary-traces/gz_read.cc)
target_link_libraries(gz_read z)

add_subdirectory(src)

enable_testing()
add_subdirectory(tests)
34 changes: 34 additions & 0 deletions cmake/FindHIP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# cmake/FindHIP.cmake
if(NOT DEFINED HIP_PATH)
message(STATUS "HIP_PATH not defined; trying to locate hipcc in PATH.")
find_program(HIPCC_EXECUTABLE NAMES hipcc)
else()
set(HIPCC_EXECUTABLE "${HIP_PATH}/bin/hipcc")
endif()

if(NOT HIPCC_EXECUTABLE)
message(FATAL_ERROR "hipcc not found. Please ensure HIP is installed and/or set HIP_PATH to the HIP installation root.")
endif()

get_filename_component(HIP_BIN_DIR "${HIPCC_EXECUTABLE}" DIRECTORY)
get_filename_component(HIP_ROOT "${HIP_BIN_DIR}" DIRECTORY)

set(HIP_INCLUDE_DIRS "${HIP_ROOT}/include")
set(HIP_LIBRARIES "hip")

if(NOT EXISTS "${HIP_INCLUDE_DIRS}/hip/hip_runtime.h")
message(WARNING "Expected HIP header not found at ${HIP_INCLUDE_DIRS}/hip/hip_runtime.h. "
"If hipcc is in /usr/bin, then HIP_ROOT is set to ${HIP_ROOT}. "
"This may not be the actual HIP installation directory. "
"Consider setting -DHIP_PATH to the correct HIP installation root.")
endif()

set(HIP_FOUND TRUE)
set(HIP_CONFIG_VERSION "0.0.1")

message(STATUS "Found HIP installation at: ${HIP_ROOT}")
message(STATUS "HIP include directories: ${HIP_INCLUDE_DIRS}")
message(STATUS "HIP libraries: ${HIP_LIBRARIES}")

mark_as_advanced(HIP_INCLUDE_DIRS HIP_LIBRARIES HIP_ROOT)

31 changes: 31 additions & 0 deletions cmake/pkgs/HIPSupport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
option(USE_HIP "Enable support for HIP" ON)

if (USE_HIP)
if(NOT DEFINED HIP_PATH)
set(HIP_PATH "/opt/rocm-6.3.1")
endif()

list(APPEND CMAKE_PREFIX_PATH "${HIP_PATH}/lib/cmake")

find_package(hip REQUIRED CONFIG)

if (hip_FOUND)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_definitions(-DUSE_HIP)

set(COMMON_LINK_LIBRARIES ${COMMON_LINK_LIBRARIES}
hip::device
amdhip64
)

message(STATUS "HIP support enabled.")
message(STATUS "HIP path: ${HIP_PATH}")
message(STATUS "HIP version: ${hip_VERSION}")
else()
message(FATAL_ERROR "HIP not found")
endif()
else()
message(STATUS "HIP support disabled")
endif()
Empty file modified notebooks/bwbw_plot.py
100755 → 100644
Empty file.
Empty file modified results/babelStream/cuda/babelstream_oded-nv100_cuda.txt
100755 → 100644
Empty file.
Empty file.
Empty file.
Empty file.
14 changes: 10 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Spatter/src/CMakeLists.txt

add_subdirectory(Spatter)

add_executable(spatter main.cc)
#target_compile_options(spatter PUBLIC "-fnew-alignment 32")

if(USE_HIP)
target_compile_definitions(spatter PRIVATE USE_HIP)
endif()
if(USE_CUDA)
target_compile_definitions(spatter PRIVATE USE_CUDA)
endif()

target_link_libraries(spatter ${COMMON_LINK_LIBRARIES} Spatter)

set_target_properties(spatter PROPERTIES
COMPILE_DEFINITIONS "${COMMON_COMPILE_DEFINITIONS}"
COMPILE_OPTIONS "${WARNING_FLAGS}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
)
123 changes: 123 additions & 0 deletions src/Spatter/AlignedAllocator.hip.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include <cstdint>
#include <iostream>
#include <vector>

/**
* Allocator for aligned data.
* Adapted from Stephan T. Lavavej.
* <http://blogs.msdn.com/b/vcblog/archive/2008/08/28/the-mallocator.aspx>
*/

template <typename T, std::size_t Alignment> class aligned_allocator {
public:
// The following will be the same for virtually all allocators.
typedef T *pointer;
typedef const T *const_pointer;
typedef T &reference;
typedef const T &const_reference;
typedef T value_type;
typedef std::size_t size_type;
typedef ptrdiff_t difference_type;

T *address(T &r) const { return &r; }

const T *address(const T &s) const { return &s; }

std::size_t max_size() const {
// The following has been carefully written to be independent of
// the definition of size_t and to avoid signed/unsigned warnings.
return (static_cast<std::size_t>(0) - static_cast<std::size_t>(1)) /
sizeof(T);
}

// The following must be the same for all allocators.
template <typename U> struct rebind {
typedef aligned_allocator<U, Alignment> other;
};

bool operator!=(const aligned_allocator &other) const {
return !(*this == other);
}

void construct(T *const p, const T &t) const {
void *const pv = static_cast<void *>(p);

new (pv) T(t);
}

void destroy(T *const p) const { p->~T(); }

// Returns true if and only if storage allocated from *this
// can be deallocated from other, and vice versa.
// Always returns true for stateless allocators.
bool operator==(const aligned_allocator &) const { return true; }

// Default constructor, copy constructor, rebinding constructor, and
// destructor. Empty for stateless allocators.
aligned_allocator() {}

aligned_allocator(const aligned_allocator &) {}

template <typename U>
aligned_allocator(const aligned_allocator<U, Alignment> &) {}

~aligned_allocator() {}

// The following will be different for each allocator.
T *allocate(const std::size_t n) const {
// The return value of allocate(0) is unspecified.
// Mallocator returns NULL in order to avoid depending
// on malloc(0)'s implementation-defined behavior
// (the implementation can define malloc(0) to return NULL,
// in which case the bad_alloc check below would fire).
// All allocators can return NULL in this case.
if (n == 0) {
return NULL;
}

// All allocators should contain an integer overflow check.
// The Standardization Committee recommends that std::length_error
// be thrown in the case of integer overflow.
if (n > max_size()) {
throw std::length_error(
"aligned_allocator<T>::allocate() - Integer overflow.");
}

// std::aligned_alloc will return NULL if you try to allocate less bytes
// than the alignment So long as the above test against max_size() passes,
// this multiplication is safe.
std::size_t alloc = n * sizeof(T);
if (alloc < Alignment) {
alloc = Alignment;
}

// Allocate memory
void *const pv = std::aligned_alloc(Alignment, alloc);

// Allocators should throw std::bad_alloc in the case of memory allocation
// failure.
if (pv == NULL) {
throw std::bad_alloc();
}

return static_cast<T *>(pv);
}

void deallocate(T *const p, const std::size_t) const { std::free(p); }

// The following will be the same for all allocators that ignore hints.
template <typename U>
T *allocate(const std::size_t n, const U * /* const hint */) const {
return allocate(n);
}

// Allocators are not required to be assignable, so
// all allocators should have a private unimplemented
// assignment operator. Note that this will trigger the
// off-by-default (enabled under /Wall) warning C4626
// "assignment operator could not be generated because a
// base class assignment operator is inaccessible" within
// the STL headers, but that warning is useless.
private:
aligned_allocator &operator=(const aligned_allocator &);
};
Loading