Package: sklearn-numba-dpex
sklearn-numba-dpexExperimental plugin for scikit-learn to be able to run (some estimators) on
Intel GPUs vianumba-dpex.DISCLAIMER: this is work in progres, do not expect this repo to be in a
workable state at the moment.This requires working with the following branch of scikit-learn which is itself
not yet in a working state at the moment:wip-enginesbranch onhttps://github.com/ogrisel/scikit-learnGetting started:Step 1: Installing anumba_dpexenvironmentGetting started requires a working environment for usingnumba_dpex. Currently aconda installor adocker imageare available. The most stable and recommended environment at the moment is using the docker image.Using a conda installationTODO: update the instructions to install everything from non-dev conda packages
once available.A conda env with Intel Python libraries (1/2)Let's create a dedicated conda env with the development versions
of the Intel Python libraries (from thedppy/label/devchannel).conda create -n dppy-dev dpnp numba cython spirv-tools -c dppy/label/dev -c intel --override-channelsLet's activate it and introspect the available hardware:conda activate dppy-dev
python -c "import dpctl; print(dpctl.get_devices())"If you do not not see any CPU device, try again with the following after
setting theSYCL_ENABLE_HOST_DEVICE=1environment variable, for instance:SYCL_ENABLE_HOST_DEVICE=1 python -c "import dpctl; print(dpctl.get_devices())"If you have an Intel GPU and it is not detected, check the
following steps:Make sure you have installed thelatest GPU driversOn Linux, check that the i915 driver is properly loaded:$ lspci -nnk | grep i915
      Kernel driver in use: i915
      Kernel modules: i915On Linux, check that the current user is in therendergroup, for instance:$ groups
myuser adm cdrom sudo dip plugdev render lpadmin lxd sambashare dockerIf not, add it withsudo adduser $USER render, logout and log back in, and check
again.Install recent versions of theruntime libraries(not yet available
as conda packages)For more in-depth information, you can refer to theguides for system configuration for Intel hardware and softwareand to the discussions in this github issuehttps://github.com/IntelPython/dpnp/issues/1149Thedpctl.lsplatform()can also list version informations on your SYCL
runtime environment:python -c "import dpctl; dpctl.lsplatform()"Install numba-dpex from source (2/2)Install and activate the Intel oneAPI DPC++ compiler shipped with theIntel oneAPI base toolkit.For instance, in Ubuntu, once the apt repo has been configured:sudo apt update
sudo apt install intel-basekit
source /opt/intel/oneapi/compiler/latest/env/vars.shEnsure that theicxcommand can be found in the PATH with the command:which icxInstall numba-dpex in the same conda env as previously:git clone https://github.com/IntelPython/numba-dpex/
cd numba-dpex
pip install -e . --no-build-isolationImportant: in order to usenumba-dpex, thellvm-spirvcompiler is required
to be in the PATH. This can be achieved with:$ export PATH=/opt/intel/oneapi/compiler/latest/linux/bin-llvm:$PATHUsing the docker imageA docker image is available and provides an up-to-date, one-command install environment. You can either build it from theDockerfile:$ cd docker
$ docker build . -t my_tagor pull the docker image fromthis publicly available repository:$ docker pull jjerphan/numba_dpex_dev:latestRun the container in interactive mode with your favorite docker flags, for example:$ docker run --name my_container_name -it -v /my/host/volume/:/mounted/volume --device=/dev/dri my_tagwheremy_tagwould bejjerphan/numba_dpex_dev:latestif you pulled from the repository.⚠ The flag--device=/dev/driismandatoryto enable the gpu within the container, also the user starting thedocker runcommand must have access to the gpu, e.g. by being a member of therendergroup.Unless using the flag--rmwhen starting a container, you can restart it after it was exited, with the command:sudo docker start -a -i my_container_nameOnce inside the container, you can check that the environment works: the commandpython -c "import dpctl; print(dpctl.get_devices())"will introspect the available hardware, and should display workingopenclcpu and gpu devices, andlevel_zerogpu devices.Step 2: install thewip-enginesbranch of scikit-learnOnce you have loaded into anumba_dpexdevelopment environment, following one of the two previous guides, follow those instructions:git clone https://github.com/ogrisel/scikit-learn
cd scikit-learn
git checkout wip-engines
pip install -e . --no-build-isolation
cd ..Step 3: install this plugingit clone https://github.com/soda-inria/sklearn-numba-dpex
cd sklearn-numba-dpex
pip install -e . --no-build-isolationIntended usageSee thesklearn_numba_dpex/testsfolder for example usage.TODO: write some doc here instead.Running the benchmarksRepeat the pip installation step exposed instep 3with the following edit:pip install -e .[benchmark] --no-build-isolation(i.e adding thebenchmarkextra-require), followed by:cd benckmark
python ./kmeans.pyto run a benchmark for different k-means implementations and print a short summary of the performance.Some parameters in the__main__section of the file./benchmark/kmeans.pyare exposed for quick edition (n_clusters,max_iter,skip_slow, ...).Notes about the preferred floating point precisionIn many machine learning applications, operations using single-precision (float32) floating point data require twice as less memory that double-precision (float64), are regarded as faster, accurate enough and more suitable for GPU compute. Besides, most GPUs used in machine learning projects are significantly faster with float32 than with double-precision (float64) floating point data.To leverage the full potential of GPU execution, it's strongly advised to use a data loader that loads float32 data. By default, unless specified otherwise numpy array are created with type float64, so be especially careful to the type whenever the loader does not explicitly document the type nor expose a type option.Although it's less recommended to prevent avoidable data copies, it's also possible to transform float64 numpy arrays into float32 arrays using thenumpy.ndarray.astypetype converter following this example:X = my_data_loader()
X_float32 = X.astype(float32)
my_gpu_compute(X_float32)