Commit 61ec4f1a authored by Jeff Daily's avatar Jeff Daily
Browse files

[ROCm] re-add support for ROCm builds

Previously #6086 added ROCm support but after numerous rebases it lost
critical changes. This PR restores the ROCm build.

There are many source file changes but most were automated using the
following:

```bash
for f in `grep -rl '#ifdef USE_CUDA'`
do
    sed -i 's@#ifdef USE_CUDA@#if defined(USE_CUDA) || defined(USE_ROCM)@g' $f
done

for f in `grep -rl '#endif  // USE_CUDA'`
do
    sed -i 's@#endif  // USE_CUDA@#endif  // USE_CUDA || USE_ROCM@g' $f
done
```
parent 336a77df
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* license information. * license information.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_regression_objective.hpp" #include "cuda_regression_objective.hpp"
...@@ -106,4 +106,4 @@ void CUDARegressionQuantileloss::Init(const Metadata& metadata, data_size_t num_ ...@@ -106,4 +106,4 @@ void CUDARegressionQuantileloss::Init(const Metadata& metadata, data_size_t num_
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* license information. * license information.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_regression_objective.hpp" #include "cuda_regression_objective.hpp"
#include <LightGBM/cuda/cuda_algorithms.hpp> #include <LightGBM/cuda/cuda_algorithms.hpp>
...@@ -478,4 +478,4 @@ void CUDARegressionQuantileloss::LaunchGetGradientsKernel(const double* score, s ...@@ -478,4 +478,4 @@ void CUDARegressionQuantileloss::LaunchGetGradientsKernel(const double* score, s
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef LIGHTGBM_OBJECTIVE_CUDA_CUDA_REGRESSION_OBJECTIVE_HPP_ #ifndef LIGHTGBM_OBJECTIVE_CUDA_CUDA_REGRESSION_OBJECTIVE_HPP_
#define LIGHTGBM_OBJECTIVE_CUDA_CUDA_REGRESSION_OBJECTIVE_HPP_ #define LIGHTGBM_OBJECTIVE_CUDA_CUDA_REGRESSION_OBJECTIVE_HPP_
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#define GET_GRADIENTS_BLOCK_SIZE_REGRESSION (1024) #define GET_GRADIENTS_BLOCK_SIZE_REGRESSION (1024)
...@@ -163,5 +163,5 @@ class CUDARegressionQuantileloss : public CUDARegressionObjectiveInterface<Regre ...@@ -163,5 +163,5 @@ class CUDARegressionQuantileloss : public CUDARegressionObjectiveInterface<Regre
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
#endif // LIGHTGBM_OBJECTIVE_CUDA_CUDA_REGRESSION_OBJECTIVE_HPP_ #endif // LIGHTGBM_OBJECTIVE_CUDA_CUDA_REGRESSION_OBJECTIVE_HPP_
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
namespace LightGBM { namespace LightGBM {
ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string& type, const Config& config) { ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string& type, const Config& config) {
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
if (config.device_type == std::string("cuda") && if (config.device_type == std::string("cuda") &&
config.data_sample_strategy != std::string("goss") && config.data_sample_strategy != std::string("goss") &&
config.boosting != std::string("rf")) { config.boosting != std::string("rf")) {
...@@ -64,7 +64,7 @@ ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string& ...@@ -64,7 +64,7 @@ ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string&
return nullptr; return nullptr;
} }
} else { } else {
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
if (type == std::string("regression")) { if (type == std::string("regression")) {
return new RegressionL2loss(config); return new RegressionL2loss(config);
} else if (type == std::string("regression_l1")) { } else if (type == std::string("regression_l1")) {
...@@ -100,9 +100,9 @@ ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string& ...@@ -100,9 +100,9 @@ ObjectiveFunction* ObjectiveFunction::CreateObjectiveFunction(const std::string&
} else if (type == std::string("custom")) { } else if (type == std::string("custom")) {
return nullptr; return nullptr;
} }
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
} }
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
Log::Fatal("Unknown objective type name: %s", type.c_str()); Log::Fatal("Unknown objective type name: %s", type.c_str());
return nullptr; return nullptr;
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* license information. * license information.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include <algorithm> #include <algorithm>
...@@ -396,4 +396,4 @@ void CUDABestSplitFinder::SetUsedFeatureByNode(const std::vector<int8_t>& is_fea ...@@ -396,4 +396,4 @@ void CUDABestSplitFinder::SetUsedFeatureByNode(const std::vector<int8_t>& is_fea
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Modifications Copyright(C) 2023 Advanced Micro Devices, Inc. All rights reserved. * Modifications Copyright(C) 2023 Advanced Micro Devices, Inc. All rights reserved.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_best_split_finder.hpp" #include "cuda_best_split_finder.hpp"
...@@ -933,7 +933,11 @@ __global__ void FindBestSplitsDiscretizedForLeafKernel( ...@@ -933,7 +933,11 @@ __global__ void FindBestSplitsDiscretizedForLeafKernel(
if (is_feature_used_bytree[inner_feature_index]) { if (is_feature_used_bytree[inner_feature_index]) {
if (task->is_categorical) { if (task->is_categorical) {
__threadfence(); // ensure store issued before trap __threadfence(); // ensure store issued before trap
#if defined(USE_CUDA)
asm("trap;"); asm("trap;");
#elif defined(USE_ROCM)
__builtin_trap();
#endif
} else { } else {
if (!task->reverse) { if (!task->reverse) {
if (use_16bit_bin) { if (use_16bit_bin) {
...@@ -2239,4 +2243,4 @@ void CUDABestSplitFinder::LaunchInitCUDARandomKernel() { ...@@ -2239,4 +2243,4 @@ void CUDABestSplitFinder::LaunchInitCUDARandomKernel() {
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_BEST_SPLIT_FINDER_HPP_ #ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_BEST_SPLIT_FINDER_HPP_
#define LIGHTGBM_TREELEARNER_CUDA_CUDA_BEST_SPLIT_FINDER_HPP_ #define LIGHTGBM_TREELEARNER_CUDA_CUDA_BEST_SPLIT_FINDER_HPP_
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include <LightGBM/bin.h> #include <LightGBM/bin.h>
#include <LightGBM/dataset.h> #include <LightGBM/dataset.h>
...@@ -240,5 +240,5 @@ class CUDABestSplitFinder { ...@@ -240,5 +240,5 @@ class CUDABestSplitFinder {
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
#endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_BEST_SPLIT_FINDER_HPP_ #endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_BEST_SPLIT_FINDER_HPP_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* license information. * license information.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
...@@ -376,4 +376,4 @@ void CUDADataPartition::ReduceLeafGradStat( ...@@ -376,4 +376,4 @@ void CUDADataPartition::ReduceLeafGradStat(
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Modifications Copyright(C) 2023 Advanced Micro Devices, Inc. All rights reserved. * Modifications Copyright(C) 2023 Advanced Micro Devices, Inc. All rights reserved.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_data_partition.hpp" #include "cuda_data_partition.hpp"
...@@ -1120,4 +1120,4 @@ void CUDADataPartition::LaunchReduceLeafGradStat( ...@@ -1120,4 +1120,4 @@ void CUDADataPartition::LaunchReduceLeafGradStat(
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_DATA_PARTITION_HPP_ #ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_DATA_PARTITION_HPP_
#define LIGHTGBM_TREELEARNER_CUDA_CUDA_DATA_PARTITION_HPP_ #define LIGHTGBM_TREELEARNER_CUDA_CUDA_DATA_PARTITION_HPP_
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include <LightGBM/bin.h> #include <LightGBM/bin.h>
#include <LightGBM/meta.h> #include <LightGBM/meta.h>
...@@ -392,5 +392,5 @@ class CUDADataPartition { ...@@ -392,5 +392,5 @@ class CUDADataPartition {
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
#endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_DATA_PARTITION_HPP_ #endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_DATA_PARTITION_HPP_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* license information. * license information.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include <algorithm> #include <algorithm>
...@@ -168,4 +168,4 @@ void CUDAGradientDiscretizer::DiscretizeGradients( ...@@ -168,4 +168,4 @@ void CUDAGradientDiscretizer::DiscretizeGradients(
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_GRADIENT_DISCRETIZER_HPP_ #ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_GRADIENT_DISCRETIZER_HPP_
#define LIGHTGBM_TREELEARNER_CUDA_CUDA_GRADIENT_DISCRETIZER_HPP_ #define LIGHTGBM_TREELEARNER_CUDA_CUDA_GRADIENT_DISCRETIZER_HPP_
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include <LightGBM/bin.h> #include <LightGBM/bin.h>
#include <LightGBM/meta.h> #include <LightGBM/meta.h>
...@@ -114,5 +114,5 @@ class CUDAGradientDiscretizer: public GradientDiscretizer { ...@@ -114,5 +114,5 @@ class CUDAGradientDiscretizer: public GradientDiscretizer {
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
#endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_GRADIENT_DISCRETIZER_HPP_ #endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_GRADIENT_DISCRETIZER_HPP_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* license information. * license information.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_histogram_constructor.hpp" #include "cuda_histogram_constructor.hpp"
...@@ -185,4 +185,4 @@ void CUDAHistogramConstructor::ResetConfig(const Config* config) { ...@@ -185,4 +185,4 @@ void CUDAHistogramConstructor::ResetConfig(const Config* config) {
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Modifications Copyright(C) 2023 Advanced Micro Devices, Inc. All rights reserved. * Modifications Copyright(C) 2023 Advanced Micro Devices, Inc. All rights reserved.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_histogram_constructor.hpp" #include "cuda_histogram_constructor.hpp"
...@@ -959,4 +959,4 @@ void CUDAHistogramConstructor::LaunchSubtractHistogramKernel( ...@@ -959,4 +959,4 @@ void CUDAHistogramConstructor::LaunchSubtractHistogramKernel(
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_HISTOGRAM_CONSTRUCTOR_HPP_ #ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_HISTOGRAM_CONSTRUCTOR_HPP_
#define LIGHTGBM_TREELEARNER_CUDA_CUDA_HISTOGRAM_CONSTRUCTOR_HPP_ #define LIGHTGBM_TREELEARNER_CUDA_CUDA_HISTOGRAM_CONSTRUCTOR_HPP_
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include <LightGBM/cuda/cuda_row_data.hpp> #include <LightGBM/cuda/cuda_row_data.hpp>
#include <LightGBM/cuda/cuda_utils.hu> #include <LightGBM/cuda/cuda_utils.hu>
...@@ -192,5 +192,5 @@ class CUDAHistogramConstructor { ...@@ -192,5 +192,5 @@ class CUDAHistogramConstructor {
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
#endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_HISTOGRAM_CONSTRUCTOR_HPP_ #endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_HISTOGRAM_CONSTRUCTOR_HPP_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* license information. * license information.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_leaf_splits.hpp" #include "cuda_leaf_splits.hpp"
...@@ -75,4 +75,4 @@ void CUDALeafSplits::Resize(const data_size_t num_data) { ...@@ -75,4 +75,4 @@ void CUDALeafSplits::Resize(const data_size_t num_data) {
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_leaf_splits.hpp" #include "cuda_leaf_splits.hpp"
#include <LightGBM/cuda/cuda_algorithms.hpp> #include <LightGBM/cuda/cuda_algorithms.hpp>
...@@ -244,4 +244,4 @@ void CUDALeafSplits::LaunchInitValuesKernel( ...@@ -244,4 +244,4 @@ void CUDALeafSplits::LaunchInitValuesKernel(
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_LEAF_SPLITS_HPP_ #ifndef LIGHTGBM_TREELEARNER_CUDA_CUDA_LEAF_SPLITS_HPP_
#define LIGHTGBM_TREELEARNER_CUDA_CUDA_LEAF_SPLITS_HPP_ #define LIGHTGBM_TREELEARNER_CUDA_CUDA_LEAF_SPLITS_HPP_
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include <LightGBM/cuda/cuda_utils.hu> #include <LightGBM/cuda/cuda_utils.hu>
#include <LightGBM/bin.h> #include <LightGBM/bin.h>
...@@ -175,5 +175,5 @@ class CUDALeafSplits { ...@@ -175,5 +175,5 @@ class CUDALeafSplits {
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
#endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_LEAF_SPLITS_HPP_ #endif // LIGHTGBM_TREELEARNER_CUDA_CUDA_LEAF_SPLITS_HPP_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* license information. * license information.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_single_gpu_tree_learner.hpp" #include "cuda_single_gpu_tree_learner.hpp"
...@@ -609,4 +609,4 @@ void CUDASingleGPUTreeLearner::RenewDiscretizedTreeLeaves(CUDATree* cuda_tree) { ...@@ -609,4 +609,4 @@ void CUDASingleGPUTreeLearner::RenewDiscretizedTreeLeaves(CUDATree* cuda_tree) {
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Modifications Copyright(C) 2023 Advanced Micro Devices, Inc. All rights reserved. * Modifications Copyright(C) 2023 Advanced Micro Devices, Inc. All rights reserved.
*/ */
#ifdef USE_CUDA #if defined(USE_CUDA) || defined(USE_ROCM)
#include "cuda_single_gpu_tree_learner.hpp" #include "cuda_single_gpu_tree_learner.hpp"
...@@ -292,4 +292,4 @@ void CUDASingleGPUTreeLearner::LaunchCalcLeafValuesGivenGradStat( ...@@ -292,4 +292,4 @@ void CUDASingleGPUTreeLearner::LaunchCalcLeafValuesGivenGradStat(
} // namespace LightGBM } // namespace LightGBM
#endif // USE_CUDA #endif // USE_CUDA || USE_ROCM
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment