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

File config on small set #1346

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")
# Ginkgo configuration options
option(GINKGO_DEVEL_TOOLS "Add development tools to the build system" OFF)
option(GINKGO_BUILD_TESTS "Generate build files for unit tests" ON)
option(GINKGO_BUILD_EXTENSIONS "Build Ginkgo's extension" ON)
option(GINKGO_BUILD_EXAMPLES "Build Ginkgo's examples" ON)
option(GINKGO_BUILD_BENCHMARKS "Build Ginkgo's benchmarks" ON)
option(GINKGO_BUILD_REFERENCE "Compile reference CPU kernels" ON)
Expand Down Expand Up @@ -278,6 +279,9 @@ if(GINKGO_BUILD_BENCHMARKS)
find_package(gflags 2.2.2 QUIET)
find_package(RapidJSON 1.1.0 QUIET)
endif()
if(GINKGO_BUILD_EXTENSIONS)
find_package(nlohmann_json 3.11.2 QUIET)
endif()
if(GINKGO_BUILD_HWLOC)
find_package(HWLOC 2.1) # No need for QUIET as we ship FindHWLOC
endif()
Expand Down Expand Up @@ -335,6 +339,10 @@ if(GINKGO_BUILD_BENCHMARKS)
add_subdirectory(benchmark)
endif()

if(GINKGO_BUILD_EXTENSIONS)
add_subdirectory(extensions)
endif()

if(GINKGO_DEVEL_TOOLS)
add_custom_target(add_license
COMMAND ${Ginkgo_SOURCE_DIR}/dev_tools/scripts/add_license.sh
Expand Down
6 changes: 4 additions & 2 deletions dev_tools/scripts/format_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ convert_header () {
else
echo "#include \"${header_file}\""
fi
elif [ -f "extensions/file_config/include/${header_file}" ]; then
echo "#include \"${header_file}\""
elif [ "${header_file}" = "matrices/config.hpp" ]; then
echo "#include \"${header_file}\""
elif [[ "${header_file}" =~ ${jacobi_regex} ]]; then
Expand All @@ -28,8 +30,8 @@ convert_header () {
get_header_def () {
local regex="\.(hpp|cuh)"
if [[ $@ =~ $regex ]]; then
local def=$(echo "$@" | sed -E "s~include/ginkgo/~PUBLIC_~g;s~/|\.~_~g")
# Used to get rid of \r in Windows
local def=$(echo "$@" | sed -E "s~include/ginkgo/~PUBLIC_~g;s~extensions/[^/]*/include/~PUBLIC_EXT_~g;s~/|\.~_~g")
# Used to get rid of \r in Windows
def=$(echo "GKO_${def^^}_")
echo "$def"
else
Expand Down
2 changes: 1 addition & 1 deletion dev_tools/scripts/regroup
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<(rapidjson|gflags|gtest|papi).*'
- Regex: '^<(rapidjson|gflags|gtest|papi|nlohmann).*'
Priority: 3
- Regex: '^<(omp|cu|hip|thrust|CL/|cooperative|oneapi|mpi|nvToolsExt).*'
Priority: 2
Expand Down
1 change: 1 addition & 0 deletions extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(file_config)
84 changes: 84 additions & 0 deletions extensions/file_config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
add_library(file_config "")
add_library(file_config_custom "")

target_sources(file_config_custom
PRIVATE
"base/executor.cpp"
"matrix/csr.cpp"
"preconditioner/isai.cpp"
"stop/iteration.cpp"
"log/convergence.cpp"
)


target_link_libraries(file_config_custom PUBLIC nlohmann_json::nlohmann_json Ginkgo::ginkgo)
target_include_directories(file_config_custom PUBLIC
$<BUILD_INTERFACE:${Ginkgo_SOURCE_DIR}/extensions/file_config/include>
$<INSTALL_INTERFACE:include/extensions/file_config>
)
target_sources(file_config
PRIVATE
"base/selection.cpp"
)
target_link_libraries(file_config PUBLIC file_config_custom)

ginkgo_compile_features(file_config_custom)
ginkgo_compile_features(file_config)


function(ginkgo_ext_install_library name export_target)
if (WIN32 OR CYGWIN)
# dll is considered as runtime
install(TARGETS "${name}"
EXPORT "${export_target}"
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}"
)
else ()
# install .so and .a files
install(TARGETS "${name}"
EXPORT "${export_target}"
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
)
endif ()
endfunction()

ginkgo_ext_install_library(file_config_custom GkoFileConfig)
ginkgo_ext_install_library(file_config GkoFileConfig)

install(DIRECTORY "${Ginkgo_SOURCE_DIR}/extensions/file_config/include/"
DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/extensions/file_config"
FILES_MATCHING PATTERN "*.hpp"
)
# export targets
export(EXPORT GkoFileConfig
NAMESPACE Ginkgo::
FILE "${Ginkgo_BINARY_DIR}/extensions/file_config/GkoFileConfigTargets.cmake"
)

# export configuration file for importing
write_basic_package_version_file(
"${Ginkgo_BINARY_DIR}/extensions/file_config/GkoFileConfigConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${Ginkgo_SOURCE_DIR}/extensions/file_config/GkoFileConfigConfig.cmake.in"
"${Ginkgo_BINARY_DIR}/extensions/file_config/GkoFileConfigConfig.cmake"
INSTALL_DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}"
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR CMAKE_INSTALL_FULL_LIBDIR CMAKE_INSTALL_PREFIX GINKGO_INSTALL_MODULE_DIR
)
install(FILES
"${Ginkgo_BINARY_DIR}/extensions/file_config/GkoFileConfigConfig.cmake"
"${Ginkgo_BINARY_DIR}/extensions/file_config/GkoFileConfigConfigVersion.cmake"
DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}"
)
install(EXPORT Ginkgo
NAMESPACE Ginkgo::
FILE GkoFileConfigTargets.cmake
DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}")
if(GINKGO_BUILD_TESTS)
add_subdirectory(test)
endif()
5 changes: 5 additions & 0 deletions extensions/file_config/GkoFileConfigConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

find_package(nlohmann_json 3.11.2 REQUIRED)

include(${CMAKE_CURRENT_LIST_DIR}/GkoFileConfig.cmake)
157 changes: 157 additions & 0 deletions extensions/file_config/base/executor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*******************************<GINKGO LICENSE>******************************
Copyright (c) 2017-2023, the Ginkgo authors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************<GINKGO LICENSE>*******************************/

#include <ginkgo/core/base/executor.hpp>


#include <iostream>
#include <memory>


#include <nlohmann/json.hpp>


#include "file_config/base/generic_constructor.hpp"
#include "file_config/base/helper.hpp"
#include "file_config/base/json_helper.hpp"
#include "file_config/base/macro_helper.hpp"
#include "file_config/base/types.hpp"

namespace gko {
namespace extensions {
namespace file_config {


template <>
struct Generic<gko::CudaExecutor> {
using type = std::shared_ptr<gko::CudaExecutor>;
static type build(const nlohmann::json& item,
std::shared_ptr<const Executor> exec,
std::shared_ptr<const LinOp> linop,
ResourceManager* manager)
{
std::cout << "Cuda" << std::endl;
auto device_id = get_value_with_default(item, "device_id", 0);
auto ptr = CudaExecutor::create(device_id, ReferenceExecutor::create());
add_logger(ptr, item, exec, linop, manager);
return std::move(ptr);
}
};


IMPLEMENT_BRIDGE(RM_Executor, CudaExecutor, CudaExecutor);


template <>
struct Generic<gko::HipExecutor> {
using type = std::shared_ptr<gko::HipExecutor>;
static type build(const nlohmann::json& item,
std::shared_ptr<const Executor> exec,
std::shared_ptr<const LinOp> linop,
ResourceManager* manager)
{
std::cout << "Hip" << std::endl;
auto device_id = get_value_with_default(item, "device_id", 0);
auto ptr = HipExecutor::create(device_id, ReferenceExecutor::create());
add_logger(ptr, item, exec, linop, manager);
return std::move(ptr);
}
};


IMPLEMENT_BRIDGE(RM_Executor, HipExecutor, HipExecutor);


template <>
struct Generic<gko::DpcppExecutor> {
using type = std::shared_ptr<gko::DpcppExecutor>;
static type build(const nlohmann::json& item,
std::shared_ptr<const Executor> exec,
std::shared_ptr<const LinOp> linop,
ResourceManager* manager)
{
std::cout << "Dpcpp" << std::endl;
auto device_id = get_value_with_default(item, "device_id", 0);
auto device_type =
get_value_with_default(item, "device_type", std::string("all"));
auto ptr = DpcppExecutor::create(device_id, ReferenceExecutor::create(),
device_type);
add_logger(ptr, item, exec, linop, manager);
return std::move(ptr);
}
};


IMPLEMENT_BRIDGE(RM_Executor, DpcppExecutor, DpcppExecutor);


template <>
struct Generic<gko::ReferenceExecutor> {
using type = std::shared_ptr<gko::ReferenceExecutor>;
static type build(const nlohmann::json& item,
std::shared_ptr<const Executor> exec,
std::shared_ptr<const LinOp> linop,
ResourceManager* manager)
{
std::cout << "Reference" << std::endl;
auto ptr = ReferenceExecutor::create();
add_logger(ptr, item, exec, linop, manager);
return std::move(ptr);
}
};


IMPLEMENT_BRIDGE(RM_Executor, ReferenceExecutor, ReferenceExecutor);


template <>
struct Generic<gko::OmpExecutor> {
using type = std::shared_ptr<gko::OmpExecutor>;
static type build(const nlohmann::json& item,
std::shared_ptr<const Executor> exec,
std::shared_ptr<const LinOp> linop,
ResourceManager* manager)
{
std::cout << "Omp" << std::endl;
auto ptr = OmpExecutor::create();
add_logger(ptr, item, exec, linop, manager);
return std::move(ptr);
}
};


IMPLEMENT_BRIDGE(RM_Executor, OmpExecutor, OmpExecutor);


} // namespace file_config
} // namespace extensions
} // namespace gko
34 changes: 34 additions & 0 deletions extensions/file_config/base/selection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************<GINKGO LICENSE>******************************
Copyright (c) 2017-2023, the Ginkgo authors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************<GINKGO LICENSE>*******************************/

// compile the implementation in the library
#include "file_config/file_config_custom.hpp"
Loading