-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GPU] Add support for CUDA-based GPU build (#3160)
* Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * Initial CUDA work * redirect log to python console (#3090) * redir log to python console * fix pylint * Apply suggestions from code review * Update basic.py * Apply suggestions from code review Co-authored-by: Nikita Titov <nekit94-08@mail.ru> * Update c_api.h * Apply suggestions from code review * Apply suggestions from code review * super-minor: better wording Co-authored-by: Nikita Titov <nekit94-08@mail.ru> Co-authored-by: StrikerRUS <nekit94-12@hotmail.com> * re-order includes (fixes #3132) (#3133) * Revert "re-order includes (fixes #3132) (#3133)" (#3153) This reverts commit 656d267. * Missing change from previous rebase * Minor cleanup and removal of development scripts. * Only set gpu_use_dp on by default for CUDA. Other minor change. * Fix python lint indentation problem. * More python lint issues. * Big lint cleanup - more to come. * Another large lint cleanup - more to come. * Even more lint cleanup. * Minor cleanup so less differences in code. * Revert is_use_subset changes * Another rebase from master to fix recent conflicts. * More lint. * Simple code cleanup - add & remove blank lines, revert unneccessary format changes, remove added dead code. * Removed parameters added for CUDA and various bug fix. * Yet more lint and unneccessary changes. * Revert another change. * Removal of unneccessary code. * temporary appveyor.yml for building and testing * Remove return value in ReSize * Removal of unused variables. * Code cleanup from reviewers suggestions. * Removal of FIXME comments and unused defines. * More reviewers comments cleanup. * More reviewers comments cleanup. * More reviewers comments cleanup. * Fix config variables. * Attempt to fix check-docs failure * Update Paramster.rst for num_gpu * Removing test appveyor.yml * Add �CUDA_RESOLVE_DEVICE_SYMBOLS to libraries to fix linking issue. * Fixed handling of data elements less than 2K. * More reviewers comments cleanup. * Removal of TODO and fix printing of int64_t * Add cuda change for CI testing and remove cuda from device_type in python. * Missed one change form previous check-in * Removal AdditionConfig and fix settings. * Limit number of GPUs to one for now in CUDA. * Update Parameters.rst for previous check-in * Whitespace removal. * Cleanup unused code. * Changed uint/ushort/ulong to unsigned int/short/long to help Windows based CUDA compiler work. * Lint change from previous check-in. * Changes based on reviewers comments. * More reviewer comment changes. * Adding warning for is_sparse. Revert tmp_subset code. Only return FeatureGroupData if not is_multi_val_ * Fix so that CUDA code will compile even if you enable the SCORE_T_USE_DOUBLE define. * Reviewer comment cleanup. * Replace warning with Log message. Removal of some of the USE_CUDA. Fix typo and removal of pragma once. * Remove PRINT debug for CUDA code. * Allow to use of multiple GPUs for CUDA. * More multi-GPUs enablement for CUDA. * More code cleanup based on reviews comments. * Update docs with latest config changes. Co-authored-by: Gordon Fossum <fossum@us.ibm.com> Co-authored-by: ChipKerchner <ckerchne@linux.vnet.ibm.com> Co-authored-by: Guolin Ke <guolin.ke@outlook.com> Co-authored-by: Nikita Titov <nekit94-08@mail.ru> Co-authored-by: StrikerRUS <nekit94-12@hotmail.com> Co-authored-by: James Lamb <jaylamb20@gmail.com>
- Loading branch information
1 parent
1fddabb
commit f7ad945
Showing
33 changed files
with
2,944 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*! | ||
* Copyright (c) 2020 IBM Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*/ | ||
#ifndef LIGHTGBM_CUDA_CUDA_UTILS_H_ | ||
#define LIGHTGBM_CUDA_CUDA_UTILS_H_ | ||
|
||
#ifdef USE_CUDA | ||
|
||
#include <cuda.h> | ||
#include <cuda_runtime.h> | ||
#include <stdio.h> | ||
|
||
#define CUDASUCCESS_OR_FATAL(ans) { gpuAssert((ans), __FILE__, __LINE__); } | ||
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort = true) { | ||
if (code != cudaSuccess) { | ||
LightGBM::Log::Fatal("[CUDA] %s %s %d\n", cudaGetErrorString(code), file, line); | ||
if (abort) exit(code); | ||
} | ||
} | ||
|
||
#endif // USE_CUDA | ||
|
||
#endif // LIGHTGBM_CUDA_CUDA_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*! | ||
* Copyright (c) 2020 IBM Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*/ | ||
#ifndef LIGHTGBM_CUDA_VECTOR_CUDAHOST_H_ | ||
#define LIGHTGBM_CUDA_VECTOR_CUDAHOST_H_ | ||
|
||
#include <LightGBM/utils/common.h> | ||
|
||
#ifdef USE_CUDA | ||
#include <cuda.h> | ||
#include <cuda_runtime.h> | ||
#endif | ||
#include <stdio.h> | ||
|
||
enum LGBM_Device { | ||
lgbm_device_cpu, | ||
lgbm_device_gpu, | ||
lgbm_device_cuda | ||
}; | ||
|
||
enum Use_Learner { | ||
use_cpu_learner, | ||
use_gpu_learner, | ||
use_cuda_learner | ||
}; | ||
|
||
namespace LightGBM { | ||
|
||
class LGBM_config_ { | ||
public: | ||
static int current_device; // Default: lgbm_device_cpu | ||
static int current_learner; // Default: use_cpu_learner | ||
}; | ||
|
||
|
||
template <class T> | ||
struct CHAllocator { | ||
typedef T value_type; | ||
CHAllocator() {} | ||
template <class U> CHAllocator(const CHAllocator<U>& other); | ||
T* allocate(std::size_t n) { | ||
T* ptr; | ||
if (n == 0) return NULL; | ||
#ifdef USE_CUDA | ||
if (LGBM_config_::current_device == lgbm_device_cuda) { | ||
cudaError_t ret = cudaHostAlloc(&ptr, n*sizeof(T), cudaHostAllocPortable); | ||
if (ret != cudaSuccess) { | ||
Log::Warning("Defaulting to malloc in CHAllocator!!!"); | ||
ptr = reinterpret_cast<T*>(_mm_malloc(n*sizeof(T), 16)); | ||
} | ||
} else { | ||
ptr = reinterpret_cast<T*>(_mm_malloc(n*sizeof(T), 16)); | ||
} | ||
#else | ||
ptr = reinterpret_cast<T*>(_mm_malloc(n*sizeof(T), 16)); | ||
#endif | ||
return ptr; | ||
} | ||
|
||
void deallocate(T* p, std::size_t n) { | ||
(void)n; // UNUSED | ||
if (p == NULL) return; | ||
#ifdef USE_CUDA | ||
if (LGBM_config_::current_device == lgbm_device_cuda) { | ||
cudaPointerAttributes attributes; | ||
cudaPointerGetAttributes(&attributes, p); | ||
if ((attributes.type == cudaMemoryTypeHost) && (attributes.devicePointer != NULL)) { | ||
cudaFreeHost(p); | ||
} | ||
} else { | ||
_mm_free(p); | ||
} | ||
#else | ||
_mm_free(p); | ||
#endif | ||
} | ||
}; | ||
template <class T, class U> | ||
bool operator==(const CHAllocator<T>&, const CHAllocator<U>&); | ||
template <class T, class U> | ||
bool operator!=(const CHAllocator<T>&, const CHAllocator<U>&); | ||
|
||
} // namespace LightGBM | ||
|
||
#endif // LIGHTGBM_CUDA_VECTOR_CUDAHOST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.