Skip to content

Commit

Permalink
Implement mechanism ABI
Browse files Browse the repository at this point in the history
Implements #1376.

* Provide a common C linkage ABI for externally compiled mechanisms, for both CPU and GPU.
* Remove mechanism type hierarchy (`concrete_mechanism` etc.), and move corresponding functionality to the back-end shared state objects. Mechanism catalogue is no longer indexed by type id.
* Distinguish between SIMD optimal alignment and SIMD width with new `min_align` attribute. Mechanisms provide both pieces of information via ABI.
  • Loading branch information
thorstenhater authored Jul 29, 2021
1 parent 4543840 commit ff12bb8
Show file tree
Hide file tree
Showing 101 changed files with 2,689 additions and 2,036 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "python/pybind11"]
path = python/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "ext/fmt"]
path = ext/fmt
url = https://github.com/fmtlib/fmt.git
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ string(REGEX MATCH "^[0-9]+(\\.[0-9]+)?(\\.[0-9]+)?(\\.[0-9]+)?" numeric_version
project(arbor VERSION ${numeric_version})
enable_language(CXX)

include(GNUInstallDirs)

# Turn on this option to force the compilers to produce color output when output is
# redirected from the terminal (e.g. when using ninja or a pager).

Expand Down Expand Up @@ -171,6 +173,9 @@ set(CMAKE_CXX_EXTENSIONS OFF)
# to the 'export set', even the private ones, and this must be done
# in the same CMakeLists.txt in which the target is defined.

# Data and internal scripts go here
set(ARB_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATAROOTDIR}/arbor)

# Interface library `arbor-config-defs` collects configure-time defines
# for arbor, arborenv, arborio, of the form ARB_HAVE_XXX. These
# defines should _not_ be used in any installed public headers.
Expand Down Expand Up @@ -212,6 +217,12 @@ install(TARGETS arbor-public-deps EXPORT arbor-targets)
add_library(arborio-public-deps INTERFACE)
install(TARGETS arborio-public-deps EXPORT arborio-targets)

# Add scripts and supporting CMake for setting up external catalogues

configure_file(scripts/build-catalogue.in ${CMAKE_CURRENT_BINARY_DIR}/build-catalogue @ONLY)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/build-catalogue DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
install(FILES mechanisms/BuildModules.cmake DESTINATION ${ARB_INSTALL_DATADIR})
install(FILES mechanisms/generate_catalogue DESTINATION ${ARB_INSTALL_DATADIR} PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
# External libraries in `ext` sub-directory: json, tinyopt and randon123.
# Creates interface libraries `ext-json`, `ext-tinyopt` and `ext-random123`

Expand All @@ -224,6 +235,8 @@ else()
endif()
add_subdirectory(ext)

cmake_dependent_option(ARB_USE_BUNDLED_FMT "Use bundled FMT lib." ON "ARB_USE_BUNDLED_LIBS" OFF)

# Keep track of packages we need to add to the generated CMake config
# file for arbor.

Expand Down
6 changes: 1 addition & 5 deletions arbor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
set(arbor_sources
arbexcept.cpp
assert.cpp
backends/multicore/fvm.cpp
backends/multicore/mechanism.cpp
backends/multicore/shared_state.cpp
communication/communicator.cpp
communication/dry_run_context.cpp
Expand All @@ -27,6 +25,7 @@ set(arbor_sources
lif_cell_group.cpp
mc_cell_group.cpp
mechcat.cpp
mechinfo.cpp
memory/gpu_wrappers.cpp
memory/util.cpp
morph/embed_pwlin.cpp
Expand Down Expand Up @@ -63,9 +62,6 @@ set(arbor_sources

if(ARB_WITH_GPU)
list(APPEND arbor_sources
backends/gpu/fvm.cpp
backends/gpu/mechanism.cpp
backends/gpu/mechanism.cu
backends/gpu/shared_state.cpp
backends/gpu/stimulus.cu
backends/gpu/threshold_watcher.cu
Expand Down
8 changes: 8 additions & 0 deletions arbor/arbexcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,13 @@ bad_catalogue_error::bad_catalogue_error(const std::string &fn, const std::strin
failed_call{call}
{}

unsupported_abi_error::unsupported_abi_error(size_t v):
arbor_exception(pprintf("ABI version is not supported by this version of arbor '{}'", v)),
version{v} {}

bad_alignment::bad_alignment(size_t a):
arbor_exception(pprintf("Mechanism reported unsupported alignment '{}'", a)),
alignment{a} {}

} // namespace arb

5 changes: 2 additions & 3 deletions arbor/backends/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ struct target_handle {

struct deliverable_event {
time_type time;
target_handle handle;
float weight;
target_handle handle;

deliverable_event() {}
deliverable_event(time_type time, target_handle handle, float weight):
time(time), handle(handle), weight(weight)
{}
time(time), weight(weight), handle(handle) {}
};

// Stream index accessor function for multi_event_stream:
Expand Down
18 changes: 0 additions & 18 deletions arbor/backends/gpu/fvm.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions arbor/backends/gpu/fvm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct backend {
using array = arb::gpu::array;
using iarray = arb::gpu::iarray;

static constexpr arb_backend_kind kind = arb_backend_kind_gpu;

static memory::host_vector<value_type> host_view(const array& v) {
return memory::on_host(v);
}
Expand Down Expand Up @@ -65,8 +67,6 @@ struct backend {
thresholds,
context);
}

static value_type* mechanism_field_data(arb::mechanism* mptr, const std::string& field);
};

} // namespace gpu
Expand Down
2 changes: 1 addition & 1 deletion arbor/backends/gpu/matrix_assemble.cu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <arbor/fvm_types.hpp>

#include "gpu_common.hpp"
#include <arbor/gpu/gpu_common.hpp>
#include "matrix_common.hpp"

namespace arb {
Expand Down
2 changes: 1 addition & 1 deletion arbor/backends/gpu/matrix_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cfloat>
#include <climits>

#include "gpu_api.hpp"
#include <arbor/gpu/gpu_api.hpp>

#if defined(__CUDACC__) || defined(__HIPCC__)
# define HOST_DEVICE_IF_GPU __host__ __device__
Expand Down
4 changes: 2 additions & 2 deletions arbor/backends/gpu/matrix_fine.cu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <arbor/fvm_types.hpp>
#include <arbor/gpu/gpu_api.hpp>
#include <arbor/gpu/gpu_common.hpp>

#include "gpu_api.hpp"
#include "gpu_common.hpp"
#include "matrix_common.hpp"
#include "matrix_fine.hpp"

Expand Down
2 changes: 1 addition & 1 deletion arbor/backends/gpu/matrix_solve.cu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <arbor/fvm_types.hpp>
#include <arbor/gpu/gpu_common.hpp>

#include "gpu_common.hpp"
#include "matrix_common.hpp"

namespace arb {
Expand Down
Loading

0 comments on commit ff12bb8

Please sign in to comment.