Skip to content

Commit

Permalink
split CUDA and HIP (fb)csr_kernels compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Jul 31, 2023
1 parent 87ad9bd commit ee21178
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 162 deletions.
5 changes: 0 additions & 5 deletions common/cuda_hip/matrix/csr_kernels.hpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,6 @@ void convert_to_fbcsr(std::shared_ptr<const DefaultExecutor> exec,
});
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CONVERT_TO_FBCSR_KERNEL);


namespace kernel {

Expand Down Expand Up @@ -1122,8 +1119,6 @@ void build_lookup(std::shared_ptr<const DefaultExecutor> exec,
storage);
}

GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_CSR_BUILD_LOOKUP_KERNEL);


template <typename ValueType, typename IndexType>
void fallback_transpose(std::shared_ptr<const DefaultExecutor> exec,
Expand Down
18 changes: 0 additions & 18 deletions common/cuda_hip/matrix/fbcsr_kernels.hpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,6 @@ void fill_in_matrix_data(std::shared_ptr<const DefaultExecutor> exec,
});
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_FBCSR_FILL_IN_MATRIX_DATA_KERNEL);


namespace kernel {

Expand Down Expand Up @@ -323,9 +320,6 @@ void fill_in_dense(std::shared_ptr<const DefaultExecutor> exec,
}
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_FBCSR_FILL_IN_DENSE_KERNEL);


template <typename ValueType, typename IndexType>
void convert_to_csr(const std::shared_ptr<const DefaultExecutor> exec,
Expand All @@ -345,9 +339,6 @@ void convert_to_csr(const std::shared_ptr<const DefaultExecutor> exec,
}
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_FBCSR_CONVERT_TO_CSR_KERNEL);


template <typename ValueType, typename IndexType>
void is_sorted_by_column_index(
Expand All @@ -372,23 +363,14 @@ void is_sorted_by_column_index(
*is_sorted = exec->copy_val_to_host(gpu_array.get_data());
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_FBCSR_IS_SORTED_BY_COLUMN_INDEX);


template <typename ValueType, typename IndexType>
void sort_by_column_index(const std::shared_ptr<const DefaultExecutor> exec,
matrix::Fbcsr<ValueType, IndexType>* const to_sort)
GKO_NOT_IMPLEMENTED;

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_FBCSR_SORT_BY_COLUMN_INDEX);


template <typename ValueType, typename IndexType>
void extract_diagonal(std::shared_ptr<const DefaultExecutor> exec,
const matrix::Fbcsr<ValueType, IndexType>* orig,
matrix::Diagonal<ValueType>* diag) GKO_NOT_IMPLEMENTED;

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_FBCSR_EXTRACT_DIAGONAL);
9 changes: 7 additions & 2 deletions cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
add_library(ginkgo_cuda $<TARGET_OBJECTS:ginkgo_cuda_device> "")
include(${PROJECT_SOURCE_DIR}/cmake/template_instantiation.cmake)
add_instantiation_files(. matrix/csr_kernels.instantiate.cu CSR_INSTANTIATE)
add_instantiation_files(. matrix/fbcsr_kernels.instantiate.cu FBCSR_INSTANTIATE)
# we don't split up the dense kernels into distinct compliations

Check warning on line 5 in cuda/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"compliations" should be "compilation" or "compilations".
list(APPEND GKO_UNIFIED_COMMON_SOURCES ${PROJECT_SOURCE_DIR}/common/unified/matrix/dense_kernels.instantiate.cpp)
target_sources(ginkgo_cuda
PRIVATE
base/device.cpp
Expand Down Expand Up @@ -31,11 +36,11 @@ target_sources(ginkgo_cuda
factorization/par_ilut_spgeam_kernel.cu
factorization/par_ilut_sweep_kernel.cu
matrix/coo_kernels.cu
matrix/csr_kernels.cu
${CSR_INSTANTIATE}
matrix/dense_kernels.cu
matrix/diagonal_kernels.cu
matrix/ell_kernels.cu
matrix/fbcsr_kernels.cu
${FBCSR_INSTANTIATE}
matrix/fft_kernels.cu
matrix/sellp_kernels.cu
matrix/sparsity_csr_kernels.cu
Expand Down
99 changes: 99 additions & 0 deletions cuda/matrix/csr_kernels.instantiate.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*******************************<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 "cuda/matrix/csr_kernels.template.cu"


namespace gko {
namespace kernels {
namespace cuda {
/**
* @brief The Compressed sparse row matrix format namespace.
*
* @ingroup csr
*/
namespace csr {


// begin
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CONVERT_TO_FBCSR_KERNEL);
// split
GKO_INSTANTIATE_FOR_EACH_MIXED_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_SPMV_KERNEL);
// split
GKO_INSTANTIATE_FOR_EACH_MIXED_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_ADVANCED_SPMV_KERNEL);
// split
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_CSR_TRANSPOSE_KERNEL);
// split
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CONJ_TRANSPOSE_KERNEL);
// split
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_SORT_BY_COLUMN_INDEX);
// split
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_CSR_SPGEMM_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_ADVANCED_SPGEMM_KERNEL);
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_CSR_BUILD_LOOKUP_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_CSR_SPGEAM_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_FILL_IN_DENSE_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_INV_SYMM_PERMUTE_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_ROW_PERMUTE_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_INVERSE_ROW_PERMUTE_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CALC_NNZ_PER_ROW_IN_SPAN_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_COMPUTE_SUB_MATRIX_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CALC_NNZ_PER_ROW_IN_INDEX_SET_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_COMPUTE_SUB_MATRIX_FROM_INDEX_SET_KERNEL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_IS_SORTED_BY_COLUMN_INDEX);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_CSR_EXTRACT_DIAGONAL);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CHECK_DIAGONAL_ENTRIES_EXIST);
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_ADD_SCALED_IDENTITY_KERNEL);
// end


} // namespace csr
} // namespace cuda
} // namespace kernels
} // namespace gko
56 changes: 0 additions & 56 deletions cuda/matrix/csr_kernels.cu → cuda/matrix/csr_kernels.template.cu
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,6 @@ void spmv(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_MIXED_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_SPMV_KERNEL);
template <typename MatrixValueType, typename InputValueType,
typename OutputValueType, typename IndexType>
Expand Down Expand Up @@ -598,9 +595,6 @@ void advanced_spmv(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_MIXED_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_ADVANCED_SPMV_KERNEL);
template <typename ValueType, typename IndexType>
void spgemm(std::shared_ptr<const CudaExecutor> exec,
Expand Down Expand Up @@ -724,8 +718,6 @@ void spgemm(std::shared_ptr<const CudaExecutor> exec,
#endif // CUDA_VERSION >= 11000
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_CSR_SPGEMM_KERNEL);
namespace {
Expand Down Expand Up @@ -920,9 +912,6 @@ void advanced_spgemm(std::shared_ptr<const CudaExecutor> exec,
#endif // CUDA_VERSION >= 11000
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_ADVANCED_SPGEMM_KERNEL);
template <typename ValueType, typename IndexType>
void spgeam(std::shared_ptr<const DefaultExecutor> exec,
Expand All @@ -948,8 +937,6 @@ void spgeam(std::shared_ptr<const DefaultExecutor> exec,
b->get_const_col_idxs(), b->get_const_values(), c);
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_CSR_SPGEAM_KERNEL);
template <typename ValueType, typename IndexType>
void fill_in_dense(std::shared_ptr<const CudaExecutor> exec,
Expand All @@ -972,9 +959,6 @@ void fill_in_dense(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_FILL_IN_DENSE_KERNEL);
template <typename ValueType, typename IndexType>
void transpose(std::shared_ptr<const CudaExecutor> exec,
Expand Down Expand Up @@ -1024,8 +1008,6 @@ void transpose(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_CSR_TRANSPOSE_KERNEL);
template <typename ValueType, typename IndexType>
void conj_transpose(std::shared_ptr<const CudaExecutor> exec,
Expand Down Expand Up @@ -1083,9 +1065,6 @@ void conj_transpose(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CONJ_TRANSPOSE_KERNEL);
template <typename ValueType, typename IndexType>
void inv_symm_permute(std::shared_ptr<const CudaExecutor> exec,
Expand Down Expand Up @@ -1116,9 +1095,6 @@ void inv_symm_permute(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_INV_SYMM_PERMUTE_KERNEL);
template <typename ValueType, typename IndexType>
void row_permute(std::shared_ptr<const CudaExecutor> exec,
Expand Down Expand Up @@ -1149,9 +1125,6 @@ void row_permute(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_ROW_PERMUTE_KERNEL);
template <typename ValueType, typename IndexType>
void inverse_row_permute(std::shared_ptr<const CudaExecutor> exec,
Expand Down Expand Up @@ -1182,9 +1155,6 @@ void inverse_row_permute(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_INVERSE_ROW_PERMUTE_KERNEL);
template <typename ValueType, typename IndexType>
void calculate_nonzeros_per_row_in_span(
Expand All @@ -1204,9 +1174,6 @@ void calculate_nonzeros_per_row_in_span(
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CALC_NNZ_PER_ROW_IN_SPAN_KERNEL);
template <typename ValueType, typename IndexType>
void compute_submatrix(std::shared_ptr<const DefaultExecutor> exec,
Expand All @@ -1233,9 +1200,6 @@ void compute_submatrix(std::shared_ptr<const DefaultExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_COMPUTE_SUB_MATRIX_KERNEL);
template <typename ValueType, typename IndexType>
void calculate_nonzeros_per_row_in_index_set(
Expand All @@ -1245,9 +1209,6 @@ void calculate_nonzeros_per_row_in_index_set(
const gko::index_set<IndexType>& col_index_set,
IndexType* row_nnz) GKO_NOT_IMPLEMENTED;
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CALC_NNZ_PER_ROW_IN_INDEX_SET_KERNEL);
template <typename ValueType, typename IndexType>
void compute_submatrix_from_index_set(
Expand All @@ -1257,9 +1218,6 @@ void compute_submatrix_from_index_set(
const gko::index_set<IndexType>& col_index_set,
matrix::Csr<ValueType, IndexType>* result) GKO_NOT_IMPLEMENTED;
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_COMPUTE_SUB_MATRIX_FROM_INDEX_SET_KERNEL);
template <typename ValueType, typename IndexType>
void sort_by_column_index(std::shared_ptr<const CudaExecutor> exec,
Expand Down Expand Up @@ -1312,9 +1270,6 @@ void sort_by_column_index(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_SORT_BY_COLUMN_INDEX);
template <typename ValueType, typename IndexType>
void is_sorted_by_column_index(
Expand All @@ -1336,9 +1291,6 @@ void is_sorted_by_column_index(
cpu_array = gpu_array;
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_IS_SORTED_BY_COLUMN_INDEX);
template <typename ValueType, typename IndexType>
void extract_diagonal(std::shared_ptr<const CudaExecutor> exec,
Expand All @@ -1364,8 +1316,6 @@ void extract_diagonal(std::shared_ptr<const CudaExecutor> exec,
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_CSR_EXTRACT_DIAGONAL);
template <typename ValueType, typename IndexType>
void check_diagonal_entries_exist(
Expand All @@ -1389,9 +1339,6 @@ void check_diagonal_entries_exist(
}
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_CHECK_DIAGONAL_ENTRIES_EXIST);
template <typename ValueType, typename IndexType>
void add_scaled_identity(std::shared_ptr<const CudaExecutor> exec,
Expand All @@ -1413,9 +1360,6 @@ void add_scaled_identity(std::shared_ptr<const CudaExecutor> exec,
as_device_type(mtx->get_values()));
}
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_CSR_ADD_SCALED_IDENTITY_KERNEL);
} // namespace csr
} // namespace cuda
Expand Down
Loading

0 comments on commit ee21178

Please sign in to comment.