1 package com.android.nn.benchmark.core.sl;
2 
3 import android.content.Context;
4 import android.system.ErrnoException;
5 import android.system.Os;
6 import android.util.Log;
7 import java.io.IOException;
8 
9 public class ArmSupportLibraryDriverHandler extends SupportLibraryDriverHandler {
10   // This environment variable is required by Arm SL driver, and is used to control
11   // different options. It is fully documented in ArmNN repository.
12   private static final String ARM_OPTIONS_VAR = "ARMNN_SL_OPTIONS";
13   // Arm SL Options:
14   // -v : Verbose logging
15   // -c GpuAcc : Use GPU backend (rather than CPU)
16   private static final String ARM_OPTIONS_VAR_VALUE = "-v -c GpuAcc";
17 
18   @Override
prepareDriver(Context context, String nnSupportLibFilePath)19   public void prepareDriver(Context context, String nnSupportLibFilePath) throws IOException {
20     Log.i(TAG, "Preparing Arm NNAPI SL");
21     try {
22       Os.setenv(ARM_OPTIONS_VAR, ARM_OPTIONS_VAR_VALUE, /*overwrite=*/true);
23       Log.i(TAG, String.format("Overwritten system env variable %s with %s",
24         ARM_OPTIONS_VAR, ARM_OPTIONS_VAR_VALUE));
25     } catch (ErrnoException errnoException) {
26       throw new IOException(String.format("Unable to overwrite system env variable %s with %s",
27         ARM_OPTIONS_VAR, ARM_OPTIONS_VAR_VALUE), errnoException);
28     }
29   }
30 }
31