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

558 develop shared memory parallel backend for dense alp #163

Open
wants to merge 6 commits into
base: 303-develop-reference_dense-backend
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ endif()
option( WITH_REFERENCE_BACKEND "With Reference backend" ON )
option( WITH_ALP_REFERENCE_BACKEND "With Reference Dense backend" ON )
option( WITH_OMP_BACKEND "With OMP backend" ON )
option( WITH_ALP_OMP_BACKEND "With OMP Dense backend" ON )
option( WITH_NUMA "With NUMA support" ON )
option( LPF_INSTALL_PATH "Path to the LPF tools for the BSP1D and Hybrid backends" OFF )
# the following options depend on LPF_INSTALL_PATH being set
Expand Down Expand Up @@ -190,6 +191,7 @@ endif()
set( WITH_REFERENCE_BACKEND_HEADERS OFF )
set( WITH_ALP_REFERENCE_BACKEND_HEADERS OFF )
set( WITH_OMP_BACKEND_HEADERS OFF )
set( WITH_ALP_OMP_BACKEND_HEADERS OFF )

# activate headers based on requested backends
if( WITH_REFERENCE_BACKEND OR WITH_BSP1D_BACKEND )
Expand All @@ -206,6 +208,10 @@ if( WITH_ALP_REFERENCE_BACKEND )
set( WITH_ALP_REFERENCE_BACKEND_HEADERS ON )
endif()

if( WITH_ALP_OMP_BACKEND )
set( WITH_ALP_OMP_BACKEND_HEADERS ON )
endif()

add_subdirectory( include )

### BACKEND IMPLEMENTATIONS
Expand Down
6 changes: 6 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ reference=yes
banshee=no
lpf=no
alp_reference=yes
alp_omp=yes
show=no
FLAGS=$''
LPF_INSTALL_PATH=
Expand Down Expand Up @@ -297,6 +298,11 @@ the current directory before invocation or confirm the deletion of its content w
else
CMAKE_OPTS+=" -DWITH_ALP_REFERENCE_BACKEND=ON"
fi
if [[ "${alp_omp}" == "no" ]]; then
CMAKE_OPTS+=" -DWITH_ALP_OMP_BACKEND=OFF"
else
CMAKE_OPTS+=" -DWITH_ALP_OMP_BACKEND=ON"
fi
if [[ "${lpf}" == "yes" ]]; then
CMAKE_OPTS+=" -DLPF_INSTALL_PATH='${ABSOLUTE_LPF_INSTALL_PATH}'"
fi
Expand Down
9 changes: 9 additions & 0 deletions cmake/AddGRBInstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ install( EXPORT GraphBLASTargets
set( ALP_UTILS_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}" )
set( SHMEM_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/sequential" )
set( ALP_REFERENCE_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/alp/reference" )
set( ALP_OMP_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/alp/omp" )
set( BSP1D_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/spmd" )
set( HYBRID_BACKEND_INSTALL_DIR "${BINARY_LIBRARIES_INSTALL_DIR}/hybrid" )

Expand Down Expand Up @@ -136,6 +137,14 @@ if( WITH_OMP_BACKEND )
)
endif()

if( WITH_ALP_OMP_BACKEND )
addBackendWrapperGenOptions( "alp_omp"
COMPILE_DEFINITIONS "${ALP_OMP_SELECTION_DEFS}"
LINK_FLAGS "'${ALP_OMP_BACKEND_INSTALL_DIR}/lib${BACKEND_LIBRARY_OUTPUT_NAME}.a'"
"'${ALP_UTILS_INSTALL_DIR}/lib${ALP_UTILS_LIBRARY_OUTPUT_NAME}.a'" "${NUMA_LFLAG}"
)
endif()

# distributed memory backends
if( WITH_BSP1D_BACKEND OR WITH_HYBRID_BACKEND )
assert_valid_variables( LPFRUN LPFCPP )
Expand Down
12 changes: 11 additions & 1 deletion cmake/AddGRBVars.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set( REFERENCE_OMP_BACKEND_DEFAULT_NAME "backend_reference_omp" )
set( BSP1D_BACKEND_DEFAULT_NAME "backend_bsp1d" )
set( HYBRID_BACKEND_DEFAULT_NAME "backend_hybrid" )
set( ALP_REFERENCE_BACKEND_DEFAULT_NAME "backend_alp_reference" )
set( ALP_OMP_BACKEND_DEFAULT_NAME "backend_alp_omp" )


### COMPILER DEFINITIONS FOR HEADERS INCLUSION AND FOR BACKEND SELECTION
Expand All @@ -41,11 +42,16 @@ set( REFERENCE_INCLUDE_DEFS "_GRB_WITH_REFERENCE" )
set( REFERENCE_OMP_INCLUDE_DEFS "_GRB_WITH_OMP" )
set( LPF_INCLUDE_DEFS "_GRB_WITH_LPF" )
set( ALP_REFERENCE_INCLUDE_DEFS "_ALP_WITH_REFERENCE" )
set( ALP_OMP_INCLUDE_DEFS "_ALP_WITH_OMP;_ALP_OMP_WITH_REFERENCE" )

# compiler definitions to select a backend
set( REFERENCE_SELECTION_DEFS "_GRB_BACKEND=reference" )
set( REFERENCE_OMP_SELECTION_DEFS "_GRB_BACKEND=reference_omp" )
set( ALP_REFERENCE_SELECTION_DEFS "_ALP_BACKEND=reference" )
set( ALP_OMP_SELECTION_DEFS
"_ALP_BACKEND=omp"
"_ALP_SECONDARY_BACKEND=reference"
)
set( BSP1D_SELECTION_DEFS
"_GRB_BACKEND=BSP1D"
"_GRB_BSP1D_BACKEND=reference"
Expand All @@ -59,7 +65,7 @@ set( HYBRID_SELECTION_DEFS
set( NO_NUMA_DEF "_GRB_NO_LIBNUMA" )

### **ALL** BACKENDS, EVEN IF NOT ENABLED BY USER
set( ALL_BACKENDS "reference" "reference_omp" "bsp1d" "hybrid" "alp_reference" )
set( ALL_BACKENDS "reference" "reference_omp" "bsp1d" "hybrid" "alp_reference" "alp_omp" )


# list of user-enabled backends, for tests and wrapper scripts (do not change!)
Expand All @@ -81,6 +87,10 @@ if( WITH_ALP_REFERENCE_BACKEND )
list( APPEND AVAILABLE_BACKENDS "alp_reference" )
endif()

if( WITH_ALP_OMP_BACKEND )
list( APPEND AVAILABLE_BACKENDS "alp_omp" )
endif()

# distributed memory backends
if( WITH_BSP1D_BACKEND )
list( APPEND AVAILABLE_BACKENDS "bsp1d" )
Expand Down
4 changes: 3 additions & 1 deletion include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ install( TARGETS alp_utils_headers EXPORT GraphBLASTargets
INCLUDES DESTINATION "${INCLUDE_INSTALL_DIR}"
)

if( WITH_ALP_REFERENCE_BACKEND_HEADERS )
if( WITH_ALP_REFERENCE_BACKEND_HEADERS OR
WITH_ALP_OMP_BACKEND_HEADERS
)
add_subdirectory( alp )
endif()

Expand Down
2 changes: 1 addition & 1 deletion include/alp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
// clang-format re-ordering
#if 1
// load active configuration
// #include <alp/config.hpp> //defines _ALP_BACKEND and _WITH_BSP
#include <alp/config.hpp> //defines _ALP_BACKEND
#endif

// #pragma message "Included ALP.hpp"
Expand Down
17 changes: 17 additions & 0 deletions include/alp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# set a default backend (if they want to do so).
#
assert_defined_variables( ALP_REFERENCE_INCLUDE_DEFS WITH_ALP_REFERENCE_BACKEND_HEADERS )
assert_defined_variables( ALP_OMP_INCLUDE_DEFS WITH_ALP_OMP_BACKEND_HEADERS )
assert_valid_variables( INCLUDE_INSTALL_DIR )

# to avoid flaky acrobatics with regex or glob expressions, copy main files directly
Expand Down Expand Up @@ -91,6 +92,22 @@ if( WITH_ALP_REFERENCE_BACKEND )
)
endif()

if( WITH_ALP_OMP_BACKEND_HEADERS )
add_library( backend_alp_omp_headers INTERFACE )
target_link_libraries( backend_alp_omp_headers INTERFACE backend_headers_nodefs )
target_link_libraries( backend_alp_omp_headers INTERFACE OpenMP::OpenMP_CXX )
target_compile_definitions( backend_alp_omp_headers INTERFACE "${ALP_OMP_INCLUDE_DEFS}" )

install( TARGETS backend_alp_omp_headers EXPORT GraphBLASTargets )
endif()

if( WITH_ALP_OMP_BACKEND )
install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/alp/omp"
DESTINATION "${ALP_INCLUDE_INSTALL_DIR}/alp_omp"
FILES_MATCHING REGEX "${HEADERS_REGEX}"
)
endif()

# this target lists the algorithms implemented on top of the generic functionalities,
# hence it depends only on backend_headers_nodefs
add_library( alp_algorithms INTERFACE )
Expand Down
1 change: 1 addition & 0 deletions include/alp/amf-based/functorbasedmatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace alp {
typedef T value_type;
/** Type returned by access function */
typedef T access_type;
typedef T const_access_type;
/** Type of the index used to access the physical storage */
typedef std::pair< size_t, size_t > storage_index_type;

Expand Down
69 changes: 49 additions & 20 deletions include/alp/amf-based/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace alp {
typename MatrixType,
std::enable_if_t< is_matrix< MatrixType >::value > * = nullptr
>
const typename MatrixType::access_type access( const MatrixType &, const typename MatrixType::storage_index_type & );
typename MatrixType::const_access_type access( const MatrixType &, const typename MatrixType::storage_index_type & );

template<
typename MatrixType,
Expand Down Expand Up @@ -146,7 +146,7 @@ namespace alp {
typename MatrixType,
std::enable_if_t< is_matrix< MatrixType >::value > *
>
friend const typename MatrixType::access_type access( const MatrixType &A, const typename MatrixType::storage_index_type &storageIndex );
friend typename MatrixType::const_access_type access( const MatrixType &A, const typename MatrixType::storage_index_type &storageIndex );

template<
typename MatrixType,
Expand All @@ -168,9 +168,9 @@ namespace alp {
static_cast< DerivedMatrix & >( *this ).setInitialized( initialized );
}

template< typename AccessType, typename StorageIndexType >
const AccessType access( const StorageIndexType storageIndex ) const {
static_assert( std::is_same< AccessType, typename DerivedMatrix::access_type >::value );
template< typename ConstAccessType, typename StorageIndexType >
ConstAccessType access( const StorageIndexType storageIndex ) const {
static_assert( std::is_same< ConstAccessType, typename DerivedMatrix::const_access_type >::value );
static_assert( std::is_same< StorageIndexType, typename DerivedMatrix::storage_index_type >::value );
return static_cast< const DerivedMatrix & >( *this ).access( storageIndex );
}
Expand Down Expand Up @@ -348,8 +348,8 @@ namespace alp {
>
Matrix( const size_t rows, const size_t cols, const size_t cap = 0 ) :
base_type(
storage::AMFFactory::FromPolynomial<
typename internal::determine_poly_factory< structure, ImfR, ImfC, backend >::factory_type
storage::AMFFactory< backend >::template FromPolynomial<
Structure, ImfR, ImfC
>::Create(
ImfR( rows ),
ImfC( cols )
Expand Down Expand Up @@ -383,8 +383,8 @@ namespace alp {
>
Matrix( const size_t dim, const size_t cap = 0 ) :
base_type(
storage::AMFFactory::FromPolynomial<
typename internal::determine_poly_factory< structure, ImfR, ImfC, backend >::factory_type
storage::AMFFactory< backend >::template FromPolynomial<
Structure, ImfR, ImfC
>::Create(
ImfR( dim ),
ImfC( dim )
Expand Down Expand Up @@ -418,7 +418,7 @@ namespace alp {
Matrix( SourceType &source_matrix, ImfR imf_r, ImfC imf_c ) :
base_type(
getContainer( source_matrix ),
storage::AMFFactory::Compose<
storage::AMFFactory< backend >::template Compose<
ImfR, ImfC, typename SourceType::base_type::amf_type
>::Create( imf_r, imf_c, internal::getAmf( source_matrix ) )
) {}
Expand All @@ -441,14 +441,43 @@ namespace alp {
Matrix( SourceType &source_matrix ) :
base_type(
getContainer( source_matrix ),
storage::AMFFactory::Reshape< View::type_id, typename SourceType::amf_type >::Create( internal::getAmf( source_matrix ) )
storage::AMFFactory< backend >::template Reshape< View::type_id, typename SourceType::amf_type >::Create( internal::getAmf( source_matrix ) )
) {}

/**
* @deprecated
* Constructor for a view over another storage-based matrix.
* Constructor for a view over an internal container of another matrix.
*
* @tparam SourceType The type of the target matrix.
* @tparam AmfType The type of the amf corresponding to the layout of
* the provided container.
* Used as a template parameter to avoid hard
* compilation error in the case of FunctorBasedMatrix,
* when base_type::amf_type does not exist.
*/
template<
typename BufferType,
typename AmfType,
std::enable_if_t<
!is_container< BufferType >::value &&
internal::is_view_over_storage< View >::value
> * = nullptr
>
Matrix( BufferType &&buffer, const size_t buffer_size, AmfType &&amf ) :
base_type(
buffer,
buffer_size,
std::forward< typename base_type::amf_type >( amf )
) {
static_assert(
std::is_same< typename base_type::amf_type, typename std::remove_reference< AmfType >::type >::value,
"The type of the provided AMF does not match the type of constructed container's AMF"
);
}

/**
* Constructor for a view over another matrix' internal container.
*
* @tparam ContainerType The type of the internal container.
* @tparam AmfType The type of the amf used to construct the matrix.
* Used as a template parameter to benefit from
* SFINAE for the case of FunctorBasedMatrix, when
Expand All @@ -457,21 +486,21 @@ namespace alp {
* result in a hard compilation error.
*/
template<
typename SourceType,
typename ContainerType,
typename AmfType,
std::enable_if_t<
std::is_same< SourceType, typename View::applied_to >::value &&
internal::is_container< ContainerType >::value &&
internal::is_view_over_storage< View >::value &&
!internal::requires_allocation< View >::value
> * = nullptr
>
Matrix( SourceType &source_matrix, AmfType &&amf ) :
Matrix( ContainerType &container, AmfType &&amf ) :
base_type(
getContainer( source_matrix ),
container,
std::forward< typename base_type::amf_type >( amf )
) {
static_assert(
std::is_same< typename base_type::amf_type, AmfType >::value,
std::is_same< typename base_type::amf_type, typename std::remove_reference< AmfType >::type >::value,
"The AMF type of the constructor parameter needs to match the AMF type of this container specialization."
);
}
Expand Down Expand Up @@ -1086,10 +1115,10 @@ namespace alp {
typename MatrixType,
std::enable_if_t< is_matrix< MatrixType >::value > * = nullptr
>
const typename MatrixType::access_type access( const MatrixType &A, const typename MatrixType::storage_index_type &storageIndex ) {
typename MatrixType::const_access_type access( const MatrixType &A, const typename MatrixType::storage_index_type &storageIndex ) {
return static_cast<
const MatrixBase< typename MatrixType::base_type > &
>( A ).template access< typename MatrixType::access_type, typename MatrixType::storage_index_type >( storageIndex );
>( A ).template access< typename MatrixType::const_access_type, typename MatrixType::storage_index_type >( storageIndex );
}

/** Non-constant variant. **/
Expand Down
Loading