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

Add an option to use the mimalloc memory allocator #170

Merged
merged 1 commit into from
Apr 5, 2023
Merged
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
CMakeSettings.json
compile_commands.json
build
build_*
install
.cache/
.vs/
.vscode/
.idea/
/tags

5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
url = https://github.com/catchorg/Catch2.git
[submodule "vendor/libenvpp"]
path = vendor/libenvpp
url = https://github.com/ph3at/libenvpp.git
url = https://github.com/ph3at/libenvpp.git
[submodule "vendor/mimalloc"]
path = vendor/mimalloc
url = https://github.com/microsoft/mimalloc.git
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ message(VERBOSE "Celerity version is ${CELERITY_VERSION_MAJOR}.${CELERITY_VERSIO

project(celerity_runtime VERSION ${Celerity_VERSION} LANGUAGES CXX)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(CELERITY_USE_MIMALLOC "Use the mimalloc memory allocator" ON)

set(CELERITY_CMAKE_DIR "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CELERITY_CMAKE_DIR}")
Expand Down Expand Up @@ -62,7 +65,7 @@ else()
"Please choose one implementation using -DCELERITY_SYCL_IMPL=hipSYCL|ComputeCpp|DPC++.")
else()
set(CELERITY_SYCL_IMPL "${AVAILABLE_SYCL_IMPLS}")
message(STATUS "Automatically chooosing ${CELERITY_SYCL_IMPL} because it is the only SYCL implementation available")
message(STATUS "Automatically choosing ${CELERITY_SYCL_IMPL} because it is the only SYCL implementation available")
endif()
endif()

Expand Down Expand Up @@ -184,6 +187,15 @@ list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
set(LIBENVPP_INSTALL ON CACHE BOOL "" FORCE)
fetch_content_from_submodule(libenvpp vendor/libenvpp)

if(CELERITY_USE_MIMALLOC)
set(MI_OVERRIDE ON CACHE BOOL "" FORCE)
set(MI_BUILD_SHARED ON CACHE BOOL "" FORCE)
set(MI_BUILD_STATIC OFF CACHE BOOL "" FORCE)
set(MI_BUILD_OBJECT OFF CACHE BOOL "" FORCE)
set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE)
fetch_content_from_submodule(mimalloc vendor/mimalloc)
endif()

configure_file(include/version.h.in include/version.h @ONLY)

# Add includes to library so they show up in IDEs
Expand Down Expand Up @@ -258,6 +270,10 @@ if(WIN32 AND CELERITY_SYCL_IMPL STREQUAL "DPC++")
)
endif()

if(CELERITY_USE_MIMALLOC)
target_link_libraries(celerity_runtime PUBLIC mimalloc)
endif()

target_link_libraries(celerity_runtime PUBLIC
Threads::Threads
MPI::MPI_CXX
Expand Down Expand Up @@ -287,6 +303,7 @@ target_compile_definitions(celerity_runtime PUBLIC
$<BUILD_INTERFACE:
$<$<CONFIG:Debug>:CELERITY_DETAIL_ENABLE_DEBUG>
>
CELERITY_USE_MIMALLOC=$<BOOL:${CELERITY_USE_MIMALLOC}>
CELERITY_FEATURE_SCALAR_REDUCTIONS=$<BOOL:${CELERITY_FEATURE_SCALAR_REDUCTIONS}>
CELERITY_FEATURE_SIMPLE_SCALAR_REDUCTIONS=$<BOOL:${CELERITY_FEATURE_SIMPLE_SCALAR_REDUCTIONS}>
CELERITY_FEATURE_LOCAL_ACCESSOR=$<BOOL:${CELERITY_FEATURE_LOCAL_ACCESSOR}>
Expand Down
172 changes: 86 additions & 86 deletions ci/perf/gpuc2_bench.csv

Large diffs are not rendered by default.

174 changes: 87 additions & 87 deletions ci/perf/gpuc2_bench.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cmake/celerity-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ find_dependency(fmt REQUIRED)
find_dependency(spdlog REQUIRED)
find_dependency(small_vector REQUIRED)
find_dependency(libenvpp REQUIRED)
find_dependency(mimalloc REQUIRED)
if(@CELERITY_ENABLE_CUDA_BACKEND@)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17")
find_dependency(CUDAToolkit REQUIRED)
Expand Down
17 changes: 15 additions & 2 deletions src/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

#include <mpi.h>

#if CELERITY_USE_MIMALLOC
// override default new/delete operators to use the mimalloc memory allocator
#include <mimalloc-new-delete.h>
#endif

#include "affinity.h"
#include "buffer.h"
#include "buffer_manager.h"
Expand Down Expand Up @@ -79,6 +84,14 @@ namespace detail {
#endif
}

static const char* get_mimalloc_string() {
#if CELERITY_USE_MIMALLOC
return "using mimalloc";
#else
return "using the default allocator";
#endif
}

static std::string get_sycl_version() {
#if defined(__COMPUTECPP__)
return fmt::format("ComputeCpp {}.{}.{}", COMPUTECPP_VERSION_MAJOR, COMPUTECPP_VERSION_MINOR, COMPUTECPP_VERSION_PATCH);
Expand Down Expand Up @@ -145,8 +158,8 @@ namespace detail {
m_task_mngr->register_task_callback([this](const task* tsk) { m_schdlr->notify_task_created(tsk); });
}

CELERITY_INFO(
"Celerity runtime version {} running on {}. PID = {}, build type = {}", get_version_string(), get_sycl_version(), get_pid(), get_build_type());
CELERITY_INFO("Celerity runtime version {} running on {}. PID = {}, build type = {}, {}", get_version_string(), get_sycl_version(), get_pid(),
get_build_type(), get_mimalloc_string());
m_d_queue->init(*m_cfg, user_device_or_selector);
}

Expand Down
1 change: 1 addition & 0 deletions vendor/mimalloc
Submodule mimalloc added at acdd35