Since: API level 34
public class

KnoxAiSession

extends Object
java.lang.Object
   ↳ com.samsung.android.knox.ex.knoxAI.KnoxAiSession

Class Overview

Class of managing Knox AI Session.

Since
API level 34
KNOX 3.7.1

Summary

Nested Classes
enum KnoxAiSession.CompUnit The Computation units, used for KfaOptions. 
enum KnoxAiSession.DataFormat The data format constants, used for DataBuffer. 
enum KnoxAiSession.DataType The data types, used for DataBuffer. 
enum KnoxAiSession.ExecType The execution types, used for KfaOptions. 
enum KnoxAiSession.Mode The supported modes, used for KfaOptions. 
enum KnoxAiSession.ModelInputType The Model input type constants, used for KfaOptions. 
enum KnoxAiSession.ModelType The Model types, used for KfaOptions. 
Public Constructors
KnoxAiSession()
Default Constructor
Public Methods
KnoxAiManager.ErrorCodes close()
Closes the current Knox AI session.
KnoxAiManager.ErrorCodes execute(DataBuffer[] inputs, DataBuffer[] outputs)
Executes the AI model using the given inputs and outputs the result of execution.
KnoxAiManager.ErrorCodes getModelInputShape(int inputIndex, int[] shape)
Gets the dimensions of input data based on the AI model.
KnoxAiManager.ErrorCodes open(KfaOptions options)
Opens the Knox AI session and loads the AI model using the given KfaOptions.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public KnoxAiSession ()

Since: API level 34

Default Constructor

Since
API level 34
KNOX 3.7.1

Public Methods

public KnoxAiManager.ErrorCodes close ()

Since: API level 34

Closes the current Knox AI session.

Returns
  • Returns status of close() API. Returns 0 on success.
Throws
SecurityException
Usage
Called at the end of AI model execution to release the instance of session.
     int status = -1;
     status = session.close();
 
Permission
com.samsung.android.knox.permission.KNOX_NDA_AI
Since
API level 34
KNOX 3.7.1
Multiuser Environment
User Scope
See Also

public KnoxAiManager.ErrorCodes execute (DataBuffer[] inputs, DataBuffer[] outputs)

Since: API level 34

Executes the AI model using the given inputs and outputs the result of execution.

Returns
  • Returns status of Execute API. Returns 0 on success.
Throws
SecurityException
Usage
Called after the session is opened to execute AI model.
     DataBuffer[] input = new DataBuffer[1];
     DataBuffer[] output = new DataBuffer[1];
     DataBuffer dB = new DataBuffer();
     dB.setDataType((byte) 0);
     dB.setDataFormat((byte) 1);
     int[] shape = new int[]{1, 224, 224, 3};
     dB.setShape(shape);
     dB.setDataSource((byte)2);
     try {
         SharedMemory sharedMemory = SharedMemory.create("data", indata.length * 4);  
         ByteBuffer bBuffer = sharedMemory.mapReadWrite();
         byte[] bytes = DataBuffer.readFloatToBytes(indata);
         bBuffer.put(bytes);
         dB.setDataShared(sharedMemory);
     } catch (ErrnoException e) {
         e.printStackTrace();
     }
     input[0] = dB;
     status = session.execute(input, output);
     if (output != null && output.length > 0 ) {
         if (output[0].getDataSource() == 0) {
             float[] outputData = output[0].getDataOriginal();
         }
     }
 
Permission
com.samsung.android.knox.permission.KNOX_NDA_AI
Since
API level 34
KNOX 3.7.1
Multiuser Environment
User Scope

public KnoxAiManager.ErrorCodes getModelInputShape (int inputIndex, int[] shape)

Since: API level 34

Gets the dimensions of input data based on the AI model.

Returns
  • Returns status of getModelInputShape() API. Returns 0 on success.
Throws
SecurityException
Usage
Called before execute API to get the expected input dimensions.
    int status = -1;
    int[] inputShape = new int[4];
    status = session.getModelInputShape(0, inputShape);
  
Permission
com.samsung.android.knox.permission.KNOX_NDA_AI
Since
API level 34
KNOX 3.7.1
Multiuser Environment
User Scope
See Also

public KnoxAiManager.ErrorCodes open (KfaOptions options)

Since: API level 34

Opens the Knox AI session and loads the AI model using the given KfaOptions.

Returns
  • Returns status of Execute API. Returns 0 on success.
Throws
SecurityException
Usage
Called at beginning before AI model execution to load the model.
     KfaOptions options = new KfaOptions();
     options.setExecType(0);
     options.setCompUnit(0);
     options.setmType(4);
     ArrayList ipNames = new ArrayList();
     ipNames.add("keras_layer_input");
     options.setInputNames(ipNames);
     ArrayList opNames = new ArrayList();
     opNames.add("Identity");
     options.setOutputNames(opNames);
     options.setModelInputType(0);
     options.setWeights_file("/data/KFA/converted_model_224.tflite.pkg");
     options.setModel_file("/data/KFA/converted_model_224.tflite.pkg");
     status = session.open(options);
     return status;
 
Permission
com.samsung.android.knox.permission.KNOX_NDA_AI
Since
API level 34
KNOX 3.7.1
Multiuser Environment
User Scope