Re: About CPU and GPUs

Eibe Frank <[email protected]>
Newsgroups gmane.comp.ai.weka
Message-ID <CADehzLUFkPJQ4+_uFfhcSYHqRoVkHjsiFmRhs7qPE1qC9YrZJg@mail.gmail.com>
This is not quite right. WEKA implementations of algorithms that are based
on standard linear algebra generally apply the MTJ library, which,
optionally, can use a much faster native backend than the default pure-Java
backend. Install the appropriate netlibNative* package for your platform
using the WEKA package manager to get this acceleration.

To get further speed-ups, compile OpenBLAS or similar for your particular
computer and link it with MTJ/NetlibJava, i.e., to make use of
multi-threaded linear algebra (see info at
https://github.com/fommil/netlib-java). There is good news for Mac OS X
users: OS X comes with a system-optimised library (vecLib) and all you need
to do is install the WEKA package netlibNativeOSX* to get high-speed matrix
algebra.

Here is a list of WEKA schemes (not sure whether it’s complete) that can
benefit from this (but only on sufficiently large data):

GaussianProcesses
PrincipalComponents
LinearRegression
M5P
M5Rules
MultivariateGaussianEstimator

There are also some schemes in various packages:

 LDA
 QDA
 FLDA
 LatentSemanticAnalysis
 Nystroem
 RotationForest
 LeastMedSq
 RBFNetwork

Now, regarding GPUs, it's actually possible to set up a GPU-based backend
for MTJ/NetlibJava. However, WEKA uses double-precision arithmetic and
consumer-grade GPUs are optimised for single-precision arithmetic and very
slow when using double-precision arithmetic. (Neural networks in deep
learning libraries are generally trained using single-precision
arithmetic.) Anyway, I attach instructions for using NVBLAS (Nvidia's BLAS
wrapper) on Ubuntu 20.04 below at the end of this message.

I tried PrincipalComponents (see instructions below for how I did this) and
LDA with NVBLAS. However,  in my experiments, only a small fraction of the
BLAS operations were off-loaded to the GPU by NVBLAS, even though the names
of the BLAS routines in nvblas.log are all in the list of GPU-based
routines at

https://docs.nvidia.com/cuda/nvblas/index.html#routines

Perhaps it also depends on the parameter settings of those routines as to
whether they are off-loaded to the GPU. It seems NVBLAS uses some
heuristics to guess whether it's worthwhile to use the GPU instead of the
CPU for certain input parameters.

So, apart from using wekaDeeplearning4j, there is this second way of using
GPUs: by applying the NVBLAS backend with MTJ/netlib-java.

The third way to use a GPU from WEKA is to install XGBoost with GPU support
in Python or R (note that the GPU support for XGBoost was actually
developed here at Waikato by Rory Mitchell!). That can then be used in WEKA
via the RPlugin and wekaPython. In 2020, when I tried this on a Windows
machine, it only worked out of the box using wekaPython though, and not
using R. Here is an email to a colleague that I wrote at the time:

> I finally got around to trying to run XGBoost on the GPU from WEKA, and
it works fine using the wekaPython package, out-of-the-box! I tried the
following configuration on an artificial dataset with 1,000,000 instances
and 10 predictors, running a 10-fold cross-validation:
>
> weka.classifiers.sklearn.ScikitLearnClassifier -learner XGBClassifier
-parameters "tree_method=\"gpu_hist\""
>
> The GPU is definitely being used, I checked this in the Windows task
manager, and overall runtime is a bit lower than using the CPU version
("hist"?). The majority of the time is spent transferring data, probably
from WEKA to Python. The time actually spent doing computation on the GPU
seems fairly insignificant based on the plot of GPU utilisation in the
Windows TaskManager. :-)
>
> This was on my Windows 10 laptop with a 1050 GPU (4 GB only). It looks
like I could fit 40,000,000+ instances with 10 predictors onto it, but the
16GB of main memory on my laptop are not sufficient to hold the data on the
WEKA side.
>
> Via R, with the default XGBoost package available for R, I could get the
CPU version to run using
>
> weka.classifiers.mlr.MLRClassifier -learner classif.xgboost -params
"nrounds=100,tree_method=\"hist\""
>
> but it looks like the GPU variant is not available with the default
binary of the XGBoost library for R. The XGBoost package for R that I have
seems quite recent (2020-06-12), with XGBoost version number 1.1.1.1(?),
but it looks like GPU support needs to be compiled up separately (for my
own reference: see
https://medium.com/@karthikdulam/installing-xgboost-gpu-for-r-on-windows-10-7927a65c0ca8
for instructions). It's a pity that the default R binary distribution of
the XGBBoost package does not seem to have GPU support, particularly given
that the RPlugin for WEKA can be installed without issuing any commands in
a terminal (in contrast to wekaPython)!

The fourth way to use a GPU from WEKA is to use the kerasZoo package, which
has


https://github.com/Waikato/weka-3.8/blob/master/packages/internal/kerasZoo/src/main/java/weka/classifiers/keras/KerasZooClassifier.java

However, it may need to be updated to work with the very latest version of
WEKA.

Finally, I suppose any installed GPU-support in R/Python for any of other
the learning schemes in MLR (version 1) or scikit-learn should be
"transparently" available in WEKA via RPlugin and wekaPython respectively.

Unfortunately, in contrast to the MTJ and wekaDeeplearning4j options,
wekaPython or RPlugin always incurs an overheard (both, in terms of time
and memory) by transferring the data from WEKA to R or Python respectively
(and then from RAM to GPU device memory!).

Cheers,
Eibe

Running MTJ with NVBLAS on Ubuntu:

1. Installed

   https://prdownloads.sourceforge.net/weka/weka-3-8-6-azul-zulu-linux.zip

   in

   /home/eibe/Desktop

2. Ran

   ~/Desktop/weka-3-8-6/weka.sh -main weka.core.WekaPackageManager
-install-package netlibNativeLinux

3. To install CPU-based system BLAS/LAPACK, ran

   sudo apt-get install libblas-dev liblapack-dev
   sudo ln -s /usr/lib/x86_64-linux-gnu/libblas.so.3 /usr/lib/libblas.so.3
   sudo ln -s /usr/lib/x86_64-linux-gnu/liblapack.so.3
/usr/lib/liblapack.so.3

4. Downloaded and installed CUDA 11.6 from
https://developer.nvidia.com/cuda-downloads

5. Copied example nvblas.conf from https://docs.nvidia.com/cuda/nvblas/
into local directory using

   cat > nvblas.conf

6. Edited nvblas.conf to have

   NVBLAS_CPU_BLAS_LIB  /usr/lib/x86_64-linux-gnu/blas/libblas.so.3

7. Now, by adapting what's given at
https://github.com/fommil/netlib-java/wiki/NVBLAS, issued

   export
LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64:/usr/lib/x86_64-linux-gnu/blas/libblas.so.3

8. Then,

   ~/Desktop/weka-3-8-6/weka.sh -main weka.Run .RandomRBF -a 5000 >
RandomRBF.a5000.arff
   LD_PRELOAD=libnvblas.so ~/Desktop/weka-3-8-6/weka.sh -main weka.Run
.attributeSelection.PrincipalComponents -i RandomRBF.a5000.arff

9. Observation: Memory is being allocated on the GPU. Looking at nvblas.log,
the GPU is used, but only for some dgemm operations. However, according to
https://docs.nvidia.com/cuda/nvblas/, the tremm operation (which is
executed on the CPU) should also be supported by the GPU.

On Sun, 3 Apr 2022 at 11:18, Peter Reutemann <[email protected]> wrote:

> Short answer is: no, Weka doesn't run on GPUs. It runs in the JVM on the
> CPU.
>
> Why? If one wants to take advantage of GPU compute resources, then one has
> to use libraries that give you that capability while designing your
> software. In case of GPUs that could be NVIDIA's CUDA library.
>
> Weka predates this GPU capability and was aimed at being cross-platform
> (write once, run anywhere). Having Weka take advantage of the GPU would
> require a complete rewrite of its code base, unfortunately.
>
> The wekadeeplearning4j package takes advantage of your GPU for its deep
> learning methods.
>
> Cheers, Peter
> --
> Peter Reutemann
> Dept. of Computer Science
> University of Waikato, NZ
> +64 (7) 858-5174 (office)
> +64 (7) 577-5304 (home office)
> http://www.cs.waikato.ac.nz/~fracpete/
> http://www.data-mining.co.nz/
>
> Apr 2, 2022 10:41:59 Celestino Laranjeira <[email protected]>:
>
> > Hi,
> > I have an issue that certainly many people also have when there is a cpu
> (with integrated gpu) + graphics card gpu.
> >
> > I have a laptop that has cpu with integrated gpu (amd ryzen 7 4800H) +
> graphics card (nVidia GeForce 1050Ti). I've been told it's a good computer.
> >
> > My question is: when using weka algorithms, I use auto-weka a lot, can I
> benefit from the nvidia graphics card gpu? Weka is using CPU only.
> >
> > How can I configure computer or weka to use nvidia gpu instead of cpu?
> Or at least can you compare the performance of the cpu and gpu of the
> nvidia graphics card?
> > _______________________________________________
> > Wekalist mailing list -- [email protected]
> > Send posts to [email protected]
> > To unsubscribe send an email to [email protected]
> > To subscribe, unsubscribe, etc., visit
> https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
> > List etiquette:
> http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
> _______________________________________________
> Wekalist mailing list -- [email protected]
> Send posts to [email protected]
> To unsubscribe send an email to [email protected]
> To subscribe, unsubscribe, etc., visit
> https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
> List etiquette:
> http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
>

_______________________________________________
Wekalist mailing list -- [email protected]
Send posts to [email protected]
To unsubscribe send an email to [email protected]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.