How to enable GPU in ai.djl with MXNet engine?

15 views Asked by At

Environment:

  • OS: Ubunntu 20.04 LTS enable NVIDIA CUDA
  • Java: GraalVM JDK 11.0.18
  • DJL: ai.djl 0.25.0

I am a newbie for using ai.djl. Below is my code and build.gradle. I want to know how to enable GPU while usine MXNet engine.

nvidia-smi:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.147.05   Driver Version: 525.147.05   CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0  On |                  N/A |
| N/A   35C    P8    12W / 180W |    879MiB /  8192MiB |      5%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      3045      G   /usr/lib/xorg/Xorg                344MiB |
|    0   N/A  N/A      3181      G   /usr/bin/gnome-shell              209MiB |
|    0   N/A  N/A     44400      G   /usr/lib/firefox/firefox          128MiB |

nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

build.gradle:

plugins {
    id 'java'
}

group = 'org.example'
version = '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation platform('org.junit:junit-bom:5.9.1')
    testImplementation 'org.junit.jupiter:junit-jupiter'

    implementation platform("ai.djl:bom:0.25.0")
    implementation ("ai.djl:api")
    runtimeOnly("ai.djl.mxnet:mxnet-engine")
}

TestDjlGpu.java:

public class TestDjlGpu {
    public static void main(String[] args) {
        System.out.printf("There are %d engines\n", Engine.getAllEngines().size());
        Engine.getAllEngines().forEach(engineName ->{
               System.out.printf("  Engine name: %s\n", engineName);
        });
        Device device = Device.gpu();
        try(NDManager manager = NDManager.newBaseManager(device)){
            NDArray x = manager.arange(12).reshape(3, 4);
            System.out.println (manager);
            System.out.println(x);
            System.out.println( x.size());
        }

    }
}

Output:

There are 1 engines
  Engine name: MXNet
[16:46:10] ../src/imperative/./imperative_utils.h:93: GPU support is disabled. Compile MXNet with USE_CUDA=1 to enable GPU support.
Exception in thread "main" ai.djl.engine.EngineException: MXNet engine call failed: MXNetError: Operator _npi_arange is not implemented for GPU.
Stack trace:
  File "../src/imperative/imperative.cc", line 81

    at ai.djl.mxnet.jna.JnaUtils.checkCall(JnaUtils.java:1942)
    at ai.djl.mxnet.jna.JnaUtils.imperativeInvoke(JnaUtils.java:521)
    at ai.djl.mxnet.jna.FunctionInfo.invoke(FunctionInfo.java:75)
    at ai.djl.mxnet.engine.MxNDManager.invoke(MxNDManager.java:382)
    at ai.djl.mxnet.engine.MxNDManager.invoke(MxNDManager.java:417)
    at ai.djl.mxnet.engine.MxNDManager.arange(MxNDManager.java:195)
    at ai.djl.ndarray.NDManager.arange(NDManager.java:1024)
    at ai.djl.ndarray.NDManager.arange(NDManager.java:925)
    at TestDjlGpu.main(TestDjlGpu.java:15)

How to enable GPU while uusing MXNet?

0

There are 0 answers