Installation-Guide.rst 29.6 KB
Newer Older
1
2
3
Installation Guide
==================

4
5
6
All instructions below are aimed at compiling the 64-bit version of LightGBM.
It is worth compiling the 32-bit version only in very rare special cases involving environmental limitations.
The 32-bit version is slow and untested, so use it at your own risk and don't forget to adjust some of the commands below when installing.
7

8
9
10
11
12
13
14
By default, instructions below will use **VS Build Tools** or **make** tool to compile the code.
It it possible to use `Ninja`_ tool instead of make on all platforms, but VS Build Tools cannot be replaced with Ninja.
You can add ``-G Ninja`` to CMake flags to use Ninja.

By default, instructions below will produce a shared library file and an executable file with command-line interface.
You can add ``-DBUILD_CLI=OFF`` to CMake flags to disable the executable compilation.

15
16
If you need to build a static library instead of a shared one, you can add ``-DBUILD_STATIC_LIB=ON`` to CMake flags.

17
18
19
20
21
22
By default, instructions below will place header files into system-wide folder.
You can add ``-DINSTALL_HEADERS=OFF`` to CMake flags to disable headers installation.

By default, on macOS, CMake is looking into Homebrew standard folders for finding dependencies (e.g. OpenMP).
You can add ``-DUSE_HOMEBREW_FALLBACK=OFF`` to CMake flags to disable this behaviour.

23
Users who want to perform benchmarking can make LightGBM output time costs for different internal routines by adding ``-DUSE_TIMETAG=ON`` to CMake flags.
Guolin Ke's avatar
Guolin Ke committed
24

25
26
27
It is possible to build LightGBM in debug mode.
In this mode all compiler optimizations are disabled and LightGBM performs more checks internally.
To enable debug mode you can add ``-DUSE_DEBUG=ON`` to CMake flags or choose ``Debug_*`` configuration (e.g. ``Debug_DLL``, ``Debug_mpi``) in Visual Studio depending on how you are building LightGBM.
Guolin Ke's avatar
Guolin Ke committed
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
.. _sanitizers:

In addition to the debug mode, LightGBM can be built with compiler sanitizers.
To enable them add ``-DUSE_SANITIZER=ON -DENABLED_SANITIZERS="address;leak;undefined"`` to CMake flags.
These values refer to the following supported sanitizers:

- ``address`` - AddressSanitizer (ASan);
- ``leak`` - LeakSanitizer (LSan);
- ``undefined`` - UndefinedBehaviorSanitizer (UBSan);
- ``thread`` - ThreadSanitizer (TSan).

Please note, that ThreadSanitizer cannot be used together with other sanitizers.
For more info and additional sanitizers' parameters please refer to the `following docs`_.
It is very useful to build `C++ unit tests <#build-c-unit-tests>`__ with sanitizers.

44
45
.. _nightly-builds:

46
You can download the artifacts of the latest successful build on master branch (nightly builds) here: |download artifacts|.
47

48
49
50
51
.. contents:: **Contents**
    :depth: 1
    :local:
    :backlinks: none
52

53
54
55
Windows
~~~~~~~

56
On Windows, LightGBM can be built using
57
58

- **Visual Studio**;
59
- **CMake** and **VS Build Tools**;
60
- **CMake** and **MinGW**.
61

62
63
Visual Studio (or VS Build Tools)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
64
65
66
67

With GUI
********

68
1. Install `Visual Studio`_.
69

70
2. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
71

72
3. Go to ``LightGBM-complete_source_code_zip/windows`` folder.
73

74
4. Open ``LightGBM.sln`` file with **Visual Studio**, choose ``Release`` configuration if you need executable file or ``DLL`` configuration if you need shared library and click ``Build`` -> ``Build Solution (Ctrl+Shift+B)``.
75

76
   If you have errors about **Platform Toolset**, go to ``Project`` -> ``Properties`` -> ``Configuration Properties`` -> ``General`` and select the toolset installed on your machine.
77

78
79
The ``.exe`` file will be in ``LightGBM-complete_source_code_zip/windows/x64/Release`` folder.
The ``.dll`` file will be in ``LightGBM-complete_source_code_zip/windows/x64/DLL`` folder.
80
81
82
83

From Command Line
*****************

84
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** is already installed).
85
86
87

2. Run the following commands:

88
   .. code:: console
89

90
     git clone --recursive https://github.com/microsoft/LightGBM
91
     cd LightGBM
92
93
     cmake -B build -S . -A x64
     cmake --build build --target ALL_BUILD --config Release
94

95
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
96

97
98
MinGW-w64
^^^^^^^^^
99
100
101
102
103

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

2. Run the following commands:

104
   .. code:: console
105

106
     git clone --recursive https://github.com/microsoft/LightGBM
107
     cd LightGBM
108
109
     cmake -B build -S . -G "MinGW Makefiles"
     cmake --build build -j4
110

111
The ``.exe`` and ``.dll`` files will be in ``LightGBM/`` folder.
112

113
**Note**: You may need to run the ``cmake -B build -S . -G "MinGW Makefiles"`` one more time or add ``-DCMAKE_SH=CMAKE_SH-NOTFOUND`` to CMake flags if you encounter the ``sh.exe was found in your PATH`` error.
114

115
It is recommended that you use **Visual Studio** since it has better multithreading efficiency in **Windows** for many-core systems
116
(see `Question 4 <./FAQ.rst#i-am-using-windows-should-i-use-visual-studio-or-mingw-for-compiling-lightgbm>`__ and `Question 8 <./FAQ.rst#cpu-usage-is-low-like-10-in-windows-when-using-lightgbm-on-very-large-datasets-with-many-core-systems>`__).
117

118
119
120
Linux
~~~~~

121
122
123
124
125
126
On Linux, LightGBM can be built using

- **CMake** and **gcc**;
- **CMake** and **Clang**.

After compilation the executable and ``.so`` files will be in ``LightGBM/`` folder.
127

128
129
130
131
gcc
^^^

1. Install `CMake`_ and **gcc**.
132

133
134
2. Run the following commands:

135
   .. code:: sh
136

137
138
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
139
140
     cmake -B build -S .
     cmake --build build -j4
141

142
143
Clang
^^^^^
144

145
1. Install `CMake`_, **Clang** and **OpenMP**.
146

147
2. Run the following commands:
148

149
   .. code:: sh
150
151
152

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
153
154
155
     export CXX=clang++-14 CC=clang-14  # replace "14" with version of Clang installed on your machine
     cmake -B build -S .
     cmake --build build -j4
156

157
158
macOS
~~~~~
159

160
On macOS, LightGBM can be installed using
161

162
163
164
165
- **Homebrew**;
- **MacPorts**;

or can be built using
fanliwen's avatar
fanliwen committed
166

167
168
- **CMake** and **Apple Clang**;
- **CMake** and **gcc**.
fanliwen's avatar
fanliwen committed
169

170
Install Using ``Homebrew``
171
^^^^^^^^^^^^^^^^^^^^^^^^^^
172

173
.. code:: sh
174
175
176

  brew install lightgbm

177
Refer to https://formulae.brew.sh/formula/lightgbm for more details.
178

179
180
Install Using ``MacPorts``
^^^^^^^^^^^^^^^^^^^^^^^^^^
Nikita Titov's avatar
Nikita Titov committed
181

182
.. code:: sh
Nikita Titov's avatar
Nikita Titov committed
183

184
185
186
187
188
  sudo port install LightGBM

Refer to https://ports.macports.org/port/LightGBM for more details.

**Note**: Port for LightGBM is not maintained by LightGBM's maintainers.
fanliwen's avatar
fanliwen committed
189

190
191
192
193
194
195
196
197
198
Build from GitHub
^^^^^^^^^^^^^^^^^

After compilation the executable and ``.dylib`` files will be in ``LightGBM/`` folder.

Apple Clang
***********

1. Install `CMake`_ and **OpenMP**:
fanliwen's avatar
fanliwen committed
199

200
   .. code:: sh
fanliwen's avatar
fanliwen committed
201

202
     brew install cmake libomp
203

204
2. Run the following commands:
205

206
   .. code:: sh
207

208
209
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
210
211
     cmake -B build -S .
     cmake --build build -j4
fanliwen's avatar
fanliwen committed
212

213
gcc
214
***
215

216
1. Install `CMake`_ and **gcc**:
217

218
   .. code:: sh
219

220
     brew install cmake gcc
221

222
2. Run the following commands:
223

224
   .. code:: sh
225

226
227
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
228
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
229
230
     cmake -B build -S .
     cmake --build build -j4
231
232
233
234

Docker
~~~~~~

235
Refer to `Docker folder <https://github.com/microsoft/LightGBM/tree/master/docker>`__.
236

237
238
239
240
Build Threadless Version (not Recommended)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The default build version of LightGBM is based on OpenMP.
241
You can build LightGBM without OpenMP support but it is **strongly not recommended**.
242
243
244
245

Windows
^^^^^^^

246
On Windows, a version of LightGBM without OpenMP support can be built using
247
248
249
250
251
252
253
254
255
256
257

- **Visual Studio**;
- **CMake** and **VS Build Tools**;
- **CMake** and **MinGW**.

Visual Studio (or VS Build Tools)
*********************************

With GUI
--------

258
1. Install `Visual Studio`_.
259

260
2. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
261

262
3. Go to ``LightGBM-complete_source_code_zip/windows`` folder.
263

264
4. Open ``LightGBM.sln`` file with **Visual Studio**, choose ``Release`` configuration if you need executable file or ``DLL`` configuration if you need shared library.
265

266
5. Go to ``Project`` -> ``Properties`` -> ``Configuration Properties`` -> ``C/C++`` -> ``Language`` and change the ``OpenMP Support`` property to ``No (/openmp-)``.
267

268
6. Get back to the project's main screen and click ``Build`` -> ``Build Solution (Ctrl+Shift+B)``.
269

270
   If you have errors about **Platform Toolset**, go to ``Project`` -> ``Properties`` -> ``Configuration Properties`` -> ``General`` and select the toolset installed on your machine.
271

272
273
The ``.exe`` file will be in ``LightGBM-complete_source_code_zip/windows/x64/Release`` folder.
The ``.dll`` file will be in ``LightGBM-complete_source_code_zip/windows/x64/DLL`` folder.
274
275
276
277

From Command Line
-----------------

278
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** is already installed).
279
280
281

2. Run the following commands:

282
   .. code:: console
283

284
     git clone --recursive https://github.com/microsoft/LightGBM
285
     cd LightGBM
286
287
     cmake -B build -S . -A x64 -DUSE_OPENMP=OFF
     cmake --build build --target ALL_BUILD --config Release
288

289
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
290
291
292
293
294
295
296
297

MinGW-w64
*********

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

2. Run the following commands:

298
   .. code:: console
299

300
     git clone --recursive https://github.com/microsoft/LightGBM
301
     cd LightGBM
302
303
     cmake -B build -S . -G "MinGW Makefiles" -DUSE_OPENMP=OFF
     cmake --build build -j4
304

305
The ``.exe`` and ``.dll`` files will be in ``LightGBM/`` folder.
306

307
**Note**: You may need to run the ``cmake -B build -S . -G "MinGW Makefiles" -DUSE_OPENMP=OFF`` one more time or add ``-DCMAKE_SH=CMAKE_SH-NOTFOUND`` to CMake flags if you encounter the ``sh.exe was found in your PATH`` error.
308
309
310
311

Linux
^^^^^

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
On Linux, a version of LightGBM without OpenMP support can be built using

- **CMake** and **gcc**;
- **CMake** and **Clang**.

After compilation the executable and ``.so`` files will be in ``LightGBM/`` folder.

gcc
***

1. Install `CMake`_ and **gcc**.

2. Run the following commands:

   .. code:: sh
327

328
329
330
331
332
333
334
335
336
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     cmake -B build -S . -DUSE_OPENMP=OFF
     cmake --build build -j4

Clang
*****

1. Install `CMake`_ and **Clang**.
337
338
339

2. Run the following commands:

340
   .. code:: sh
341

342
343
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
344
     export CXX=clang++-14 CC=clang-14  # replace "14" with version of Clang installed on your machine
345
346
     cmake -B build -S . -DUSE_OPENMP=OFF
     cmake --build build -j4
347
348
349
350

macOS
^^^^^

351
352
353
354
355
356
On macOS, a version of LightGBM without OpenMP support can be built using

- **CMake** and **Apple Clang**;
- **CMake** and **gcc**.

After compilation the executable and ``.dylib`` files will be in ``LightGBM/`` folder.
357
358
359
360

Apple Clang
***********

361
1. Install `CMake`_:
362

363
   .. code:: sh
364
365
366
367
368

     brew install cmake

2. Run the following commands:

369
   .. code:: sh
370

371
372
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
373
374
     cmake -B build -S . -DUSE_OPENMP=OFF
     cmake --build build -j4
375
376
377
378

gcc
***

379
1. Install `CMake`_ and **gcc**:
380

381
   .. code:: sh
382

383
     brew install cmake gcc
384

385
2. Run the following commands:
386

387
   .. code:: sh
388

389
390
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
391
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
392
393
     cmake -B build -S . -DUSE_OPENMP=OFF
     cmake --build build -j4
394

395
396
397
Build MPI Version
~~~~~~~~~~~~~~~~~

398
399
The default build version of LightGBM is based on socket. LightGBM also supports MPI.
`MPI`_ is a high performance communication approach with `RDMA`_ support.
400

401
If you need to run a distributed learning application with high performance communication, you can build the LightGBM with MPI support.
402
403
404
405

Windows
^^^^^^^

406
On Windows, an MPI version of LightGBM can be built using
407
408

- **MS MPI** and **Visual Studio**;
409
- **MS MPI**, **CMake** and **VS Build Tools**.
410

411
412
**Note**: Building MPI version by **MinGW** is not supported due to the miss of MPI library in it.

413
414
415
With GUI
********

416
1. You need to install `MS MPI`_ first. Both ``msmpisdk.msi`` and ``msmpisetup.exe`` are needed.
417

418
2. Install `Visual Studio`_.
419

420
3. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
421

422
4. Go to ``LightGBM-complete_source_code_zip/windows`` folder.
423

424
5. Open ``LightGBM.sln`` file with **Visual Studio**, choose ``Release_mpi`` configuration and click ``Build`` -> ``Build Solution (Ctrl+Shift+B)``.
425

426
   If you have errors about **Platform Toolset**, go to ``Project`` -> ``Properties`` -> ``Configuration Properties`` -> ``General`` and select the toolset installed on your machine.
427

428
The ``.exe`` file will be in ``LightGBM-complete_source_code_zip/windows/x64/Release_mpi`` folder.
429
430
431
432

From Command Line
*****************

433
1. You need to install `MS MPI`_ first. Both ``msmpisdk.msi`` and ``msmpisetup.exe`` are needed.
434

435
2. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** is already installed).
436
437
438

3. Run the following commands:

439
   .. code:: console
440

441
     git clone --recursive https://github.com/microsoft/LightGBM
442
     cd LightGBM
443
444
     cmake -B build -S . -A x64 -DUSE_MPI=ON
     cmake --build build --target ALL_BUILD --config Release
445

446
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
447
448
449
450

Linux
^^^^^

451
On Linux, an MPI version of LightGBM can be built using
452

453
454
- **CMake**, **gcc** and **Open MPI**;
- **CMake**, **Clang** and **Open MPI**.
455

456
After compilation the executable and ``.so`` files will be in ``LightGBM/`` folder.
457

458
459
460
461
462
463
gcc
***

1. Install `CMake`_, **gcc** and `Open MPI`_.

2. Run the following commands:
464

465
   .. code:: sh
466

467
468
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
469
470
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
471

472
473
Clang
*****
474

475
1. Install `CMake`_, **Clang**, **OpenMP** and `Open MPI`_.
476

477
2. Run the following commands:
478

479
   .. code:: sh
480

481
482
483
484
485
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     export CXX=clang++-14 CC=clang-14  # replace "14" with version of Clang installed on your machine
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
486

487
488
macOS
^^^^^
489

490
On macOS, an MPI version of LightGBM can be built using
491

492
493
- **CMake**, **Open MPI** and **Apple Clang**;
- **CMake**, **Open MPI** and **gcc**.
494

495
After compilation the executable and ``.dylib`` files will be in ``LightGBM/`` folder.
496

497
498
Apple Clang
***********
499

500
1. Install `CMake`_, **OpenMP** and `Open MPI`_:
501

502
   .. code:: sh
503

504
     brew install cmake libomp open-mpi
505

506
2. Run the following commands:
507

508
   .. code:: sh
509

510
511
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
512
513
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
514
515
516
517

gcc
***

518
1. Install `CMake`_, `Open MPI`_ and  **gcc**:
519

520
   .. code:: sh
521

522
     brew install cmake open-mpi gcc
523

524
2. Run the following commands:
525

526
   .. code:: sh
527

528
529
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
530
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
531
532
     cmake -B build -S . -DUSE_MPI=ON
     cmake --build build -j4
533
534
535
536
537
538
539

Build GPU Version
~~~~~~~~~~~~~~~~~

Windows
^^^^^^^

540
541
542
543
On Windows, a GPU version of LightGBM (``device_type=gpu``) can be built using

- **OpenCL**, **Boost**, **CMake** and **VS Build Tools**;
- **OpenCL**, **Boost**, **CMake** and **MinGW**.
544

545
If you use **MinGW**, the build procedure is similar to the build on Linux.
546

547
548
Following procedure is for the **MSVC** (Microsoft Visual C++) build.

549
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** is installed).
550
551
552
553
554

2. Install **OpenCL** for Windows. The installation depends on the brand (NVIDIA, AMD, Intel) of your GPU card.

   - For running on Intel, get `Intel SDK for OpenCL`_.

555
   - For running on AMD, get AMD APP SDK.
556
557
558

   - For running on NVIDIA, get `CUDA Toolkit`_.

559
560
   Further reading and correspondence table: `GPU SDK Correspondence and Device Targeting Table <./GPU-Targets.rst>`__.

Nikita Titov's avatar
Nikita Titov committed
561
3. Install `Boost Binaries`_.
562

563
   **Note**: Match your Visual C++ version:
564

565
566
   Visual Studio 2015 -> ``msvc-14.0-64.exe``,

567
568
   Visual Studio 2017 -> ``msvc-14.1-64.exe``,

569
570
571
   Visual Studio 2019 -> ``msvc-14.2-64.exe``,

   Visual Studio 2022 -> ``msvc-14.3-64.exe``.
572
573
574

4. Run the following commands:

575
   .. code:: console
576

577
     git clone --recursive https://github.com/microsoft/LightGBM
578
     cd LightGBM
579
     cmake -B build -S . -A x64 -DUSE_GPU=ON -DBOOST_ROOT=C:/local/boost_1_63_0 -DBOOST_LIBRARYDIR=C:/local/boost_1_63_0/lib64-msvc-14.0
580
     # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
581
     # cmake -B build -S . -A x64 -DUSE_GPU=ON -DBOOST_ROOT=C:/local/boost_1_63_0 -DBOOST_LIBRARYDIR=C:/local/boost_1_63_0/lib64-msvc-14.0 -DOpenCL_LIBRARY="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/lib/x64/OpenCL.lib" -DOpenCL_INCLUDE_DIR="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/include"
582
     cmake --build build --target ALL_BUILD --config Release
583

584
   **Note**: ``C:/local/boost_1_63_0`` and ``C:/local/boost_1_63_0/lib64-msvc-14.0`` are locations of your **Boost** binaries (assuming you've downloaded 1.63.0 version for Visual Studio 2015).
585

586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.

Linux
^^^^^

On Linux, a GPU version of LightGBM (``device_type=gpu``) can be built using

- **CMake**, **OpenCL**, **Boost** and **gcc**;
- **CMake**, **OpenCL**, **Boost** and **Clang**.

**OpenCL** headers and libraries are usually provided by GPU manufacture.
The generic OpenCL ICD packages (for example, Debian packages ``ocl-icd-libopencl1``, ``ocl-icd-opencl-dev``, ``pocl-opencl-icd``) can also be used.

Required **Boost** libraries (Boost.Align, Boost.System, Boost.Filesystem, Boost.Chrono) should be provided by the following Debian packages: ``libboost-dev``, ``libboost-system-dev``, ``libboost-filesystem-dev``, ``libboost-chrono-dev``.

After compilation the executable and ``.so`` files will be in ``LightGBM/`` folder.

gcc
***

1. Install `CMake`_, **gcc**, **OpenCL** and **Boost**.

2. Run the following commands:

   .. code:: sh

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     cmake -B build -S . -DUSE_GPU=ON
     # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
     # cmake -B build -S . -DUSE_GPU=ON -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/
     cmake --build build -j4

Clang
*****

1. Install `CMake`_, **Clang**, **OpenMP**, **OpenCL** and **Boost**.

2. Run the following commands:

   .. code:: sh

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     export CXX=clang++-14 CC=clang-14  # replace "14" with version of Clang installed on your machine
     cmake -B build -S . -DUSE_GPU=ON
     # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
     # cmake -B build -S . -DUSE_GPU=ON -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/
     cmake --build build -j4

macOS
^^^^^

The GPU version is not supported on macOS.

641
642
643
Docker
^^^^^^

644
Refer to `GPU Docker folder <https://github.com/microsoft/LightGBM/tree/master/docker/gpu>`__.
645

646
647
Build CUDA Version
~~~~~~~~~~~~~~~~~~
648

649
The `original GPU version <#build-gpu-version>`__ of LightGBM (``device_type=gpu``) is based on OpenCL.
650

651
The CUDA-based version (``device_type=cuda``) is a separate implementation.
652
Use this version in Linux environments with an NVIDIA GPU with compute capability 6.0 or higher.
653

654
655
656
657
658
659
Windows
^^^^^^^

The CUDA version is not supported on Windows.
Use the `GPU version <#build-gpu-version>`__ (``device_type=gpu``) for GPU acceleration on Windows.

660
661
662
Linux
^^^^^

663
On Linux, a CUDA version of LightGBM can be built using
664

665
666
- **CMake**, **gcc** and **CUDA**;
- **CMake**, **Clang** and **CUDA**.
667

668
Please refer to `this detailed guide`_ for **CUDA** libraries installation.
669

670
After compilation the executable and ``.so`` files will be in ``LightGBM/`` folder.
671

672
673
gcc
***
674

675
676
677
1. Install `CMake`_, **gcc** and **CUDA**.

2. Run the following commands:
678

679
680
681
682
683
684
685
686
687
688
689
690
691
   .. code:: sh

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     cmake -B build -S . -DUSE_CUDA=ON
     cmake --build build -j4

Clang
*****

1. Install `CMake`_, **Clang**, **OpenMP** and **CUDA**.

2. Run the following commands:
692

693
694
695
696
697
698
699
   .. code:: sh

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     export CXX=clang++-14 CC=clang-14  # replace "14" with version of Clang installed on your machine
     cmake -B build -S . -DUSE_CUDA=ON
     cmake --build build -j4
700

701
702
703
704
705
macOS
^^^^^

The CUDA version is not supported on macOS.

706
707
708
Build Java Wrapper
~~~~~~~~~~~~~~~~~~

709
Using the following instructions you can generate a JAR file containing the LightGBM `C API <./Development-Guide.rst#c-api>`__ wrapped by **SWIG**.
710

711
712
After compilation the ``.jar`` file will be in ``LightGBM/build`` folder.

713
714
715
Windows
^^^^^^^

716
717
718
719
On Windows, a Java wrapper of LightGBM can be built using

- **Java**, **SWIG**, **CMake** and **VS Build Tools**;
- **Java**, **SWIG**, **CMake** and **MinGW**.
720

721
722
VS Build Tools
**************
723

724
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** is already installed).
725

726
2. Install `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` environment variable is set properly).
727
728
729

3. Run the following commands:

730
   .. code:: console
731

732
     git clone --recursive https://github.com/microsoft/LightGBM
733
     cd LightGBM
734
735
     cmake -B build -S . -A x64 -DUSE_SWIG=ON
     cmake --build build --target ALL_BUILD --config Release
736
737
738
739
740
741

MinGW-w64
*********

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

742
2. Install `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` environment variable is set properly).
743
744
745

3. Run the following commands:

746
   .. code:: console
747

748
     git clone --recursive https://github.com/microsoft/LightGBM
749
     cd LightGBM
750
751
     cmake -B build -S . -G "MinGW Makefiles" -DUSE_SWIG=ON
     cmake --build build -j4
752

753
**Note**: You may need to run the ``cmake -B build -S . -G "MinGW Makefiles" -DUSE_SWIG=ON`` one more time or add ``-DCMAKE_SH=CMAKE_SH-NOTFOUND`` to CMake flags if you encounter the ``sh.exe was found in your PATH`` error.
754

755
It is recommended to use **VS Build Tools (Visual Studio)** since it has better multithreading efficiency in **Windows** for many-core systems
756
757
(see `Question 4 <./FAQ.rst#i-am-using-windows-should-i-use-visual-studio-or-mingw-for-compiling-lightgbm>`__ and `Question 8 <./FAQ.rst#cpu-usage-is-low-like-10-in-windows-when-using-lightgbm-on-very-large-datasets-with-many-core-systems>`__).

758
759
760
Linux
^^^^^

761
762
763
764
765
766
767
On Linux, a Java wrapper of LightGBM can be built using

- **CMake**, **gcc**, **Java** and **SWIG**;
- **CMake**, **Clang**, **Java** and **SWIG**.

gcc
***
768

769
1. Install `CMake`_, **gcc**, `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` environment variable is set properly).
770

771
2. Run the following commands:
772

773
   .. code:: sh
774

775
776
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
777
778
     cmake -B build -S . -DUSE_SWIG=ON
     cmake --build build -j4
779

780
781
Clang
*****
782

783
1. Install `CMake`_, **Clang**, **OpenMP**, `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` environment variable is set properly).
784

785
2. Run the following commands:
786

787
   .. code:: sh
788

789
790
791
792
793
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     export CXX=clang++-14 CC=clang-14  # replace "14" with version of Clang installed on your machine
     cmake -B build -S . -DUSE_SWIG=ON
     cmake --build build -j4
794

795
796
macOS
^^^^^
797

798
On macOS, a Java wrapper of LightGBM can be built using
799

800
801
- **CMake**, **Java**, **SWIG** and **Apple Clang**;
- **CMake**, **Java**, **SWIG** and **gcc**.
802

803
804
Apple Clang
***********
805

806
1. Install `CMake`_, **Java** (also make sure that ``JAVA_HOME`` environment variable is set properly), `SWIG`_ and **OpenMP**:
807

808
   .. code:: sh
809

810
811
     brew install cmake openjdk swig libomp
     export JAVA_HOME="$(brew --prefix openjdk)/libexec/openjdk.jdk/Contents/Home/"
812

813
2. Run the following commands:
814

815
   .. code:: sh
816

817
818
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
819
     cmake -B build -S . -DUSE_SWIG=ON
820
     cmake --build build -j4
821
822
823
824

gcc
***

825
1. Install `CMake`_, **Java** (also make sure that ``JAVA_HOME`` environment variable is set properly), `SWIG`_ and **gcc**:
826

827
   .. code:: sh
828

829
830
     brew install cmake openjdk swig gcc
     export JAVA_HOME="$(brew --prefix openjdk)/libexec/openjdk.jdk/Contents/Home/"
831

832
2. Run the following commands:
833

834
   .. code:: sh
835

836
837
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
838
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
839
     cmake -B build -S . -DUSE_SWIG=ON
840
     cmake --build build -j4
841

842
843
844
845
846
847
848
849
850
851
Build Python-package
~~~~~~~~~~~~~~~~~~~~

Refer to `Python-package folder <https://github.com/microsoft/LightGBM/tree/master/python-package>`__.

Build R-package
~~~~~~~~~~~~~~~

Refer to `R-package folder <https://github.com/microsoft/LightGBM/tree/master/R-package>`__.

852
853
854
855
856
857
Build C++ Unit Tests
~~~~~~~~~~~~~~~~~~~~

Windows
^^^^^^^

858
859
860
861
862
863
864
On Windows, C++ unit tests of LightGBM can be built using

- **CMake** and **VS Build Tools**;
- **CMake** and **MinGW**.

VS Build Tools
**************
865

866
1. Install `Git for Windows`_, `CMake`_ and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** is already installed).
867
868
869

2. Run the following commands:

870
   .. code:: console
871
872
873

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
874
     cmake -B build -S . -A x64 -DBUILD_CPP_TEST=ON
875
     cmake --build build --target testlightgbm --config Debug
876
877
878

The ``.exe`` file will be in ``LightGBM/Debug`` folder.

879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
MinGW-w64
*********

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

2. Run the following commands:

   .. code:: console

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     cmake -B build -S . -G "MinGW Makefiles" -DBUILD_CPP_TEST=ON
     cmake --build build --target testlightgbm -j4

The ``.exe`` file will be in ``LightGBM/`` folder.

**Note**: You may need to run the ``cmake -B build -S . -G "MinGW Makefiles" -DBUILD_CPP_TEST=ON`` one more time or add ``-DCMAKE_SH=CMAKE_SH-NOTFOUND`` to CMake flags if you encounter the ``sh.exe was found in your PATH`` error.

897
898
899
Linux
^^^^^

900
901
902
903
904
905
906
907
908
On Linux, a C++ unit tests of LightGBM can be built using

- **CMake** and **gcc**;
- **CMake** and **Clang**.

After compilation the executable file will be in ``LightGBM/`` folder.

gcc
***
909

910
1. Install `CMake`_ and **gcc**.
911
912
913

2. Run the following commands:

914
   .. code:: sh
915
916
917

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
     cmake -B build -S . -DBUILD_CPP_TEST=ON
     cmake --build build --target testlightgbm -j4

Clang
*****

1. Install `CMake`_, **Clang** and **OpenMP**.

2. Run the following commands:

   .. code:: sh

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     export CXX=clang++-14 CC=clang-14  # replace "14" with version of Clang installed on your machine
     cmake -B build -S . -DBUILD_CPP_TEST=ON
934
     cmake --build build --target testlightgbm -j4
935
936
937
938

macOS
^^^^^

939
940
941
942
943
944
On macOS, a C++ unit tests of LightGBM can be built using

- **CMake** and **Apple Clang**;
- **CMake** and **gcc**.

After compilation the executable file will be in ``LightGBM/`` folder.
945
946
947
948

Apple Clang
***********

949
1. Install `CMake`_ and **OpenMP**:
950

951
   .. code:: sh
952

953
     brew install cmake libomp
954
955
956

2. Run the following commands:

957
   .. code:: sh
958
959
960

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
961
     cmake -B build -S . -DBUILD_CPP_TEST=ON
962
     cmake --build build --target testlightgbm -j4
963
964
965
966

gcc
***

967
1. Install `CMake`_ and **gcc**:
968

969
   .. code:: sh
970

971
     brew install cmake gcc
972

973
2. Run the following commands:
974

975
   .. code:: sh
976
977
978
979

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
980
     cmake -B build -S . -DBUILD_CPP_TEST=ON
981
     cmake --build build --target testlightgbm -j4
982

983

984
985
986
.. |download artifacts| image:: ./_static/images/artifacts-not-available.svg
   :target: https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html

987
.. _Visual Studio: https://visualstudio.microsoft.com/downloads/
988
989
990
991
992

.. _Git for Windows: https://git-scm.com/download/win

.. _CMake: https://cmake.org/

993
.. _VS Build Tools: https://visualstudio.microsoft.com/downloads/
994

995
.. _MinGW-w64: https://www.mingw-w64.org/downloads/
996
997
998
999
1000

.. _MPI: https://en.wikipedia.org/wiki/Message_Passing_Interface

.. _RDMA: https://en.wikipedia.org/wiki/Remote_direct_memory_access

1001
.. _MS MPI: https://learn.microsoft.com/en-us/message-passing-interface/microsoft-mpi-release-notes
1002
1003
1004
1005
1006
1007
1008

.. _Open MPI: https://www.open-mpi.org/

.. _Intel SDK for OpenCL: https://software.intel.com/en-us/articles/opencl-drivers

.. _CUDA Toolkit: https://developer.nvidia.com/cuda-downloads

1009
.. _Boost Binaries: https://sourceforge.net/projects/boost/files/boost-binaries/
1010

James Lamb's avatar
James Lamb committed
1011
.. _SWIG: https://www.swig.org/download.html
1012
1013

.. _this detailed guide: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
1014
1015

.. _following docs: https://github.com/google/sanitizers/wiki
1016
1017

.. _Ninja: https://ninja-build.org