Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ build
# Visual studio code
.vscode

### Generated header file
### Generated header files
include/config.hpp
dpcpp/base/config.hpp

### C++
# Prerequisites
Expand Down
20 changes: 15 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,20 @@ else()
option(GINKGO_BUILD_HWLOC "Build Ginkgo with HWLOC. Default is ON. If a system HWLOC is not found, then we try to build it ourselves. Switch this OFF to disable HWLOC." ON)
endif()
option(GINKGO_DPCPP_SINGLE_MODE "Do not compile double kernels for the DPC++ backend." OFF)
set(GINKGO_DPCPP_AOT_TARGETS "" CACHE STRING
"Uses DPC++ AOT with set targets (e.g., spir64_gen;spir64_x86_64). The default is '' (use JIT).")
set(GINKGO_DPCPP_SUBGROUPS "8;16;32" CACHE STRING
"The subgroup sizes to generate DPC++ kernels for. The default is '8;16;32'.")
set(GINKGO_DPCPP_WORKGROUPS "256;512" CACHE STRING
"The max workgroup sizes to generate DPC++ kernels for. The default is '256;512'.")
option(GINKGO_INSTALL_RPATH "Set the RPATH when installing its libraries." ON)
option(GINKGO_INSTALL_RPATH_ORIGIN "Add $ORIGIN (Linux) or @loader_path (MacOS) to the installation RPATH." ON)
option(GINKGO_INSTALL_RPATH_DEPENDENCIES "Add dependencies to the installation RPATH." OFF)
# Third party libraries
option(GINKGO_DOWNLOAD_GFLAGS "Force Ginkgo to download gflags." OFF)
option(GINKGO_DOWNLOAD_GTEST "Force Ginkgo to download GTest." OFF)
option(GINKGO_DOWNLOAD_HWLOC "Force Ginkgo to download HWLOC." OFF)
option(GINKGO_DOWNLOAD_RAPIDJSON "Force Ginkgo to download RapidJSON." OFF)

set(GINKGO_CIRCULAR_DEPS_FLAGS "-Wl,--no-undefined")

Expand Down Expand Up @@ -186,7 +197,6 @@ if(GINKGO_BUILD_HWLOC)
set(GINKGO_HAVE_HWLOC 1)
else()
set(GINKGO_HAVE_HWLOC 0)
message(STATUS "HWLOC is being forcibly switched off")
endif()

if(GINKGO_BUILD_MPI)
Expand Down Expand Up @@ -223,14 +233,14 @@ endif()
# Try to find the third party packages before using our subdirectories
include(cmake/package_helpers.cmake)
if(GINKGO_BUILD_TESTS)
find_package(GTest 1.10.0) # No need for QUIET as CMake ships FindGTest
ginkgo_find_package(GTest 1.10.0) # No need for QUIET as CMake ships FindGTest
endif()
if(GINKGO_BUILD_BENCHMARKS)
find_package(gflags 2.2.2 QUIET)
find_package(RapidJSON 1.1.0 QUIET)
ginkgo_find_package(gflags 2.2.2 QUIET)
ginkgo_find_package(RapidJSON 1.1.0 QUIET)
endif()
if(GINKGO_BUILD_HWLOC)
find_package(HWLOC 2.1) # No need for QUIET as we ship FindHWLOC
ginkgo_find_package(HWLOC 2.1) # No need for QUIET as we ship FindHWLOC
endif()
add_subdirectory(third_party) # Third-party tools and libraries

Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/FindHWLOC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ include(hwloc_helpers)

find_path(HWLOC_INCLUDE_DIRS
NAMES "hwloc.h"
HINTS ${HWLOC_DIR} $ENV{HWLOC_DIR}
HINTS ${HWLOC_DIR} $ENV{HWLOC_DIR} ${HWLOC_ROOT} $ENV{HWLOC_ROOT}
PATH_SUFFIXES include
DOC "Find the hwloc.h main header"
)

find_library(HWLOC_LIBRARIES "hwloc"
HINTS ${HWLOC_DIR} $ENV{HWLOC_DIR}
HINTS ${HWLOC_DIR} $ENV{HWLOC_DIR} ${HWLOC_ROOT} $ENV{HWLOC_ROOT}
PATH_SUFFIXES lib lib64
DOC "Find the hwloc library"
)
Expand Down
6 changes: 5 additions & 1 deletion cmake/create_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ function(ginkgo_create_dpcpp_test test_name)
target_compile_features(${test_target_name} PUBLIC cxx_std_17)
target_compile_options(${test_target_name} PRIVATE "${GINKGO_DPCPP_FLAGS}")
target_compile_options(${test_target_name} PRIVATE "${GINKGO_COMPILER_FLAGS}")
target_link_options(${test_target_name} PRIVATE -fsycl-device-code-split=per_kernel)
if (NOT GINKGO_DPCPP_AOT_TARGETS STREQUAL "")
target_compile_options(${test_target_name} PRIVATE -fsycl-targets=${GINKGO_DPCPP_AOT_TARGETS_FORMATTED})
else()
target_link_options(${test_target_name} PRIVATE -fsycl-device-code-split=per_kernel)
endif()
ginkgo_set_test_target_properties(${test_name} ${test_target_name})
# Note: MKL_ENV is empty on linux. Maybe need to apply MKL_ENV to all test.
if (MKL_ENV)
Expand Down
4 changes: 4 additions & 0 deletions cmake/get_info.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ ginkgo_print_variable(${detailed_log} "GINKGO_BUILD_HWLOC")
ginkgo_print_variable(${detailed_log} "HWLOC_VERSION")
ginkgo_print_variable(${detailed_log} "HWLOC_LIBRARIES")
ginkgo_print_variable(${detailed_log} "HWLOC_INCLUDE_DIRS")
ginkgo_print_variable(${minimal_log} "GINKGO_DOWNLOAD_GFLAGS")
ginkgo_print_variable(${minimal_log} "GINKGO_DOWNLOAD_GTEST")
ginkgo_print_variable(${minimal_log} "GINKGO_DOWNLOAD_HWLOC")
ginkgo_print_variable(${minimal_log} "GINKGO_DOWNLOAD_RAPIDJSON")

_minimal(
"
Expand Down
12 changes: 12 additions & 0 deletions cmake/package_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ function(ginkgo_download_file url filename hash_type hash)
message(FATAL_ERROR "Download of ${filename} failed.")
endif()
endfunction(ginkgo_download_file)

# Find package with a protection. To not find library foo, set the CMake
# variable GINKGO_DOWNLOAD_FOO=ON
#
# \param hash The name of the package
# \param ARGN Extra arguments to give to find_package
macro(ginkgo_find_package name)
string(TOUPPER "${name}" GKO_TPL_PKG_NAME)
if(NOT GINKGO_DOWNLOAD_${GKO_TPL_PKG_NAME})
find_package(${name} ${ARGN})
endif()
endmacro()
9 changes: 9 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ set(UNIFIED_SOURCES
matrix/coo_kernels.cpp
matrix/csr_kernels.cpp
matrix/dense_kernels.cpp
matrix/dense_kernels_2.cpp
matrix/dense_kernels_3.cpp
matrix/dense_kernels_4.cpp
matrix/dense_kernels_5.cpp
matrix/dense_kernels_6.cpp
matrix/dense_compute_norm2.cpp
matrix/dense_compute_norm1.cpp
matrix/dense_cmnpr.cpp
matrix/dense_css.cpp
matrix/ell_kernels.cpp
matrix/hybrid_kernels.cpp
matrix/sellp_kernels.cpp
Expand Down
80 changes: 80 additions & 0 deletions common/unified/matrix/dense_cmnpr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************<GINKGO LICENSE>******************************
Copyright (c) 2017-2022, 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 "core/matrix/dense_kernels.hpp"


#include <ginkgo/core/base/device_matrix_data.hpp>
#include <ginkgo/core/base/math.hpp>


#include "common/unified/base/kernel_launch.hpp"
#include "common/unified/base/kernel_launch_reduction.hpp"
#include "core/base/mixed_precision_types.hpp"
#include "core/components/prefix_sum_kernels.hpp"


namespace gko {
namespace kernels {
namespace GKO_DEVICE_NAMESPACE {
/**
* @brief The Dense matrix format namespace.
*
* @ingroup dense
*/
namespace dense {


template <typename ValueType>
void compute_max_nnz_per_row(std::shared_ptr<const DefaultExecutor> exec,
const matrix::Dense<ValueType>* source,
size_type& result)
{
Array<size_type> partial{exec, source->get_size()[0] + 1};
count_nonzeros_per_row(exec, source, partial.get_data());
run_kernel_reduction(
exec, [] GKO_KERNEL(auto i, auto partial) { return partial[i]; },
GKO_KERNEL_REDUCE_MAX(size_type),
partial.get_data() + source->get_size()[0], source->get_size()[0],
partial);
result = exec->copy_val_to_host(partial.get_const_data() +
source->get_size()[0]);
}

GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(
GKO_DECLARE_DENSE_COMPUTE_MAX_NNZ_PER_ROW_KERNEL);


} // namespace dense
} // namespace GKO_DEVICE_NAMESPACE
} // namespace kernels
} // namespace gko
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,45 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************<GINKGO LICENSE>*******************************/

#ifndef GKO_DPCPP_BASE_CONFIG_HPP_
#define GKO_DPCPP_BASE_CONFIG_HPP_
#include "core/matrix/dense_kernels.hpp"


#include <ginkgo/core/base/device_matrix_data.hpp>
#include <ginkgo/core/base/math.hpp>
#include <ginkgo/core/base/types.hpp>


namespace gko {
namespace kernels {
namespace dpcpp {


struct config {
/**
* The type containing a bitmask over all lanes of a warp.
*/
using lane_mask_type = uint64;

/**
* The number of threads within a Dpcpp subgroup.
*/
static constexpr uint32 warp_size = 16;

/**
* The bitmask of the entire warp.
*/
static constexpr auto full_lane_mask = ~zero<lane_mask_type>();
#include "common/unified/base/kernel_launch.hpp"
#include "common/unified/base/kernel_launch_reduction.hpp"
#include "core/base/mixed_precision_types.hpp"
#include "core/components/prefix_sum_kernels.hpp"

/**
* The minimal amount of warps that need to be scheduled for each block
* to maximize GPU occupancy.
*/
static constexpr uint32 min_warps_per_block = 4;

/**
* The default maximal number of threads allowed in DPCPP group
*/
static constexpr uint32 max_block_size = 256;
};


} // namespace dpcpp
namespace gko {
namespace kernels {
namespace GKO_DEVICE_NAMESPACE {
/**
* @brief The Dense matrix format namespace.
*
* @ingroup dense
*/
namespace dense {


template <typename ValueType>
void compute_norm1(std::shared_ptr<const DefaultExecutor> exec,
const matrix::Dense<ValueType>* x,
matrix::Dense<remove_complex<ValueType>>* result)
{
run_kernel_col_reduction(
exec, [] GKO_KERNEL(auto i, auto j, auto x) { return abs(x(i, j)); },
GKO_KERNEL_REDUCE_SUM(remove_complex<ValueType>), result->get_values(),
x->get_size(), x);
}

GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_DENSE_COMPUTE_NORM1_KERNEL);


} // namespace dense
} // namespace GKO_DEVICE_NAMESPACE
} // namespace kernels
} // namespace gko


#endif // GKO_DPCPP_BASE_CONFIG_HPP_
76 changes: 76 additions & 0 deletions common/unified/matrix/dense_compute_norm2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************<GINKGO LICENSE>******************************
Copyright (c) 2017-2022, 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 "core/matrix/dense_kernels.hpp"


#include <ginkgo/core/base/device_matrix_data.hpp>
#include <ginkgo/core/base/math.hpp>


#include "common/unified/base/kernel_launch.hpp"
#include "common/unified/base/kernel_launch_reduction.hpp"
#include "core/base/mixed_precision_types.hpp"
#include "core/components/prefix_sum_kernels.hpp"


namespace gko {
namespace kernels {
namespace GKO_DEVICE_NAMESPACE {
/**
* @brief The Dense matrix format namespace.
*
* @ingroup dense
*/
namespace dense {


template <typename ValueType>
void compute_norm2(std::shared_ptr<const DefaultExecutor> exec,
const matrix::Dense<ValueType>* x,
matrix::Dense<remove_complex<ValueType>>* result)
{
run_kernel_col_reduction(
exec,
[] GKO_KERNEL(auto i, auto j, auto x) { return squared_norm(x(i, j)); },
[] GKO_KERNEL(auto a, auto b) { return a + b; },
[] GKO_KERNEL(auto a) { return sqrt(a); }, remove_complex<ValueType>{},
result->get_values(), x->get_size(), x);
}

GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_DENSE_COMPUTE_NORM2_KERNEL);


} // namespace dense
} // namespace GKO_DEVICE_NAMESPACE
} // namespace kernels
} // namespace gko
Loading