Skip to content

Using the Manager API

The manager offers a quite simple Java API that enables a user to create tasks to be executed on an FPGA device. The API calls can be grouped into two major categories: Memory and Request.

Memory Calls#

Memory calls are responsible for allocating and freeing memory for buffers. They can be used to allocate and free memory on the host system or the FPGA device and they can be also used to transfer data from/to the FPGA device. Below we document a full list of the API related to memory calls:

To make things easier we have incorporated a new SharedMatrix class that is basically backed up by a Java ByteBuffer. All buffers are supposed to have two dimensions but 1-dimensional buffers can be allocated as well (see examples section). To support all types of data we have created the following subClasses:

Subclass Used to store elements of type
SharedByteMatrix byte
SharedDoubleMatrix double
SharedFloatMatrix float
SharedIntMatrx int


All of the above subclasses support the following methods:

    SharedMatrixType alloc()

Is used to allocate the specified shared memory

Returns: the SharedMatrix


    SharedMatrixType free()

Is used to free the allocated memory of the SharedMatrix

Returns: the SharedMatrix


    SharedMatrixType persist(int seed)

Is used to create a buffer on the FPGA device and transfer the data allocated in the SharedMatrix to the FPGA.

Parameters:

  • seed - a random number that is representative of the specific buffer.

Warning

You are advised to use different seed numbers for each persisted buffer for better utilization of the FPGA resources, but keep in mind to use the same seed for persisted kernels of the same task. (e.g: if you want to run a Logistic Regression application and you want to persist the buffers of data, weights and gradients, all three buffers should be persisted using the same seed)

Returns: the SharedMatrix


    SharedMatrixType unpersist(int seed)

Is used to free a buffer previously allocated on the FPGA memory.

Parameters:

  • seed - a random number that is representative of the specific buffer.

Warning

You must enter the seed number you used at the persist() method

Returns: the SharedMatrix


    Type get(int row, int col)

Is used to get the [row, col] element of a SharedMatrix.

Parameters:

  • row - Specifies the 1st dimension offset of the matrix.
  • col - Specifies the 2nd dimension offset of the matrix.

Returns: the element from the given offsets. The type depends on the type of the Matrix (e.g calling get() method from a SharedIntMatrx would return an integer)


    SharedTypeMatrix put(int i, int j, Type value)

Is used to put a new element on the Matrix on the specified offset.

Parameters:

  • row - 1st dimension offset of the matrix.
  • col - 2nd dimension offset of the matrix.
  • value - The value to be stored on the specified offset. (value type should be the same as the Matrix type. eg. int for SharedIntMatrix)

Returns: the SharedMatrix


Request Calls#

Request calls are responsible for sending new tasks to the FPGA manager. All the requests are static methods of InAccel class. Right now the supported requests are the following:

Request Used to accelerate:
Gradients32 Logistic Regression
Centroids32 KMeans
Black-Scholes Black-Scholes

Below we take a closer look on the Requests' API:


    static void BlackScholes(SharedFloatMatrix spot, SharedFloatMatrix strike, SharedFloatMatrix time, SharedFloatMatrix sigma, SharedFloatMatrix volatility, SharedFloatMatrix result, int size, int seed)

Used to send a Black-Scholes request to the manager

Parameters:

  • spot - The spot shared memory matrix..
  • strike - The strike shared memory matrix.
  • time - The time shared memory matrix.
  • sigma - The sigma shared memory matrix.
  • volatility - The volatility shared memory matrix.
  • result - The result shared memory matrix.
  • size - The size.
  • seed - The seed.

Returns: nothing


    static void Gradients32(SharedIntMatrix label, SharedFloatMatrix features, SharedFloatMatrix weights, SharedFloatMatrix gradients, int numClasses, int numFeatures, int numExamples, int seed)

Used to send a Gradients32 request to the manager

Parameters:

  • label - The label shared memory matrix..
  • features - The features shared memory matrix..
  • weights - The weights shared memory matrix.
  • gradients - The gradients shared memory matrix.
  • numClasses - The number of classes.
  • numFeatures - The number of features.
  • numExamples - The number of examples.
  • seed - The seed.

Returns: nothing


    static void Centroids32(SharedFloatMatrix features, SharedFloatMatrix centroids, SharedFloatMatrix sums_counts, int numClusters, int numFeatures, int numExamples, int seed)

Used to send a Gradients32 request to the manager

Parameters:

  • features - The features shared memory matrix..
  • centroids - The centroids shared memory matrix.
  • sums_counts - The sums_counts shared memory matrix.
  • numClusters - The number of clusters.
  • numFeatures - The number of features.
  • numExamples - The number of examples.
  • seed - The seed.

Returns: nothing

Warning

The seed must be the same used to allocate the buffers of each request