iNc · In-memory computing

SSPU.dll Specification

SSPU.dll provides connection to SSPU devices, approximate Sloppy activation functions, and saturated integer arithmetic.

1. Overview

This DLL provides SSPU communication plus Sloppy operations. Each operation sends the input data to the SSPU device, performs the calculation with the specified parameters, and receives output data.

Approximate activation functions

SloppySigmoid, SloppyTanh, SloppySiLU, SloppyGeLU, SloppySoftmax

Saturated integer operations

IntAddSat, IntSubSat, IntMulSat

Device connection

Connect

2. Runtime environment

ItemContent
Supported operating systemWindows 64-bit
Supported architecturex64
Target framework.NET 8.0
Required privilegeAdministrator
Dependency librarySystem.Management.dll
Runtime dependency filesNone
DistributionSSPU.dll (single file)

3. Import method

3.1 Prerequisites

  • Install .NET 8.0 SDK or later.
  • Run the application with administrator privileges.
  • Place SSPU.dll in an accessible path.

3.2 Add a reference

// Add a reference to SSPU.dll
// Option A: Visual Studio: right-click project -> Add Reference -> Browse
// Option B: add this to .csproj:
<Reference Include="SSPU">
  <HintPath>path\to\SSPU.dll</HintPath>
</Reference>

3.3 Integration steps

using SSPU;

// 1. Create an instance
var sspu = new SSPUDevice();

// 2. Connect the device
int result = sspu.Connect();
if (result != 0) {
    Console.WriteLine($"Connection failed: {result}");
    return;
}

// 3. Run an operation (SloppySigmoid example)
byte[] inBuffer = PrepareInputData(...);
byte[] outBuffer = new byte[expectedOutputSize];
result = sspu.SloppySigmoid(inBuffer, outBuffer, param_n, param_b);

// 4. Prefer asynchronous execution
await Task.Run(() => sspu.SloppySigmoid(inBuffer, outBuffer, param_n, param_b));

4. API specification

4.1 Method list

MethodFunction
ConnectConnect to an SSPU device
SloppySigmoidApproximate Sigmoid activation
SloppyTanhApproximate Tanh activation
SloppySiLUApproximate SiLU activation
SloppyGeLUApproximate GeLU activation
SloppySoftmaxApproximate Softmax activation
IntAddSatSigned saturating addition
IntSubSatSigned saturating subtraction
IntMulSatSigned saturating multiplication

4.1.1 Connect

Establishes a connection to an SSPU device. This method must be called before any other calculation method.

int Connect()

Return value

0 = completed normally (connection succeeded); negative value = error

  • Call this before every calculation method is used.
  • If the connection fails, subsequent calculation calls return -1.

4.1.2 SloppySigmoid

Executes an approximate Sigmoid activation operation. Input data is sent to the SSPU device and the calculation result is returned.

int SloppySigmoid(byte[] inBuffer, byte[] outBuffer, byte param_n, byte param_b)
ParameterTypeDescription
inBufferbyte[]Input data array (see 5.3 Input data generation)
outBufferbyte[]Output data array (see 5.4 buffer allocation)
param_nbyteN parameter - total bit width (3-32)
param_bbyteB parameter - fractional bit width

Return value

0 = completed normally; negative value = error (see 4.2 Error information)

  • For input/output data requirements, see Chapter 5.
  • Use asynchronous execution such as await Task.Run(() => sspu.SloppySigmoid(...)).

4.1.3 SloppyTanh

Executes an approximate Tanh activation operation. Input data is sent to the SSPU device and the calculation result is returned.

int SloppyTanh(byte[] inBuffer, byte[] outBuffer, byte param_n, byte param_b)
ParameterTypeDescription
inBufferbyte[]Input data array
outBufferbyte[]Output data array
param_nbyteN parameter - total bit width (3-32)
param_bbyteB parameter - fractional bit width

Return value

0 = completed normally; negative value = error (see 4.2 Error information)

  • Use asynchronous execution such as await Task.Run(...).

4.1.4 SloppySiLU

Executes an approximate SiLU activation operation. Input data is sent to the SSPU device and the calculation result is returned.

int SloppySiLU(byte[] inBuffer, byte[] outBuffer, byte param_n, byte param_b)
ParameterTypeDescription
inBufferbyte[]Input data array
outBufferbyte[]Output data array
param_nbyteN parameter - total bit width (3-32)
param_bbyteB parameter - fractional bit width

Return value

0 = completed normally; negative value = error (see 4.2 Error information)

  • Use asynchronous execution such as await Task.Run(...).

4.1.5 SloppyGeLU

Executes an approximate GeLU activation operation. Input data is sent to the SSPU device and the calculation result is returned.

int SloppyGeLU(byte[] inBuffer, byte[] outBuffer, byte param_n, byte param_b)
ParameterTypeDescription
inBufferbyte[]Input data array
outBufferbyte[]Output data array
param_nbyteN parameter - total bit width (3-32)
param_bbyteB parameter - fractional bit width

Return value

0 = completed normally; negative value = error (see 4.2 Error information)

  • Use asynchronous execution such as await Task.Run(...).

4.1.6 SloppySoftmax

Executes an approximate Softmax activation operation. One group consists of 2^d elements.

int SloppySoftmax(byte[] inBuffer, byte[] outBuffer, byte param_n, byte param_b, byte param_d, byte param_mode = 0)
ParameterTypeDescription
inBufferbyte[]Input data array
outBufferbyte[]Output data array
param_nbyteN parameter - total bit width
param_bbyteB parameter - fractional bit width
param_dbyteD parameter - exponent of element count per group (one group = 2^d elements)
param_modebyteMode selection (default 0; see the table below)

Return value

0 = completed normally; negative value = error (see 4.2 Error information)

  • One operation processes 2^d elements as one group.
  • Per-call limit: group count <= 15872 / 2^d.
  • The number of input elements must be a multiple of 2^d (complete groups).
  • This is an approximate operation; output can deviate by approximately +/-1 least-significant bit.
  • Use asynchronous execution such as await Task.Run(...).
ModeTypeValid parameter range
0 (default)Simple3 <= n <= 32, b >= 0, 2 <= d <= 13, 2 <= n-b <= d+1
1Standard7 <= n <= 32, b >= 4, d >= 1, 3 <= n-b <= d+2
2+ReservedReserved; not used

4.1.7 IntAddSat

Executes signed saturating addition. If the result exceeds the data type range, the maximum or minimum value of that type is returned.

int IntAddSat(byte[] aBuffer, byte[] bBuffer, byte[] outBuffer, byte param_n)
ParameterTypeDescription
aBufferbyte[]Input array A (operand A)
bBufferbyte[]Input array B (operand B)
outBufferbyte[]Output array (A + B)
param_nbyteN parameter - total bit width (2-32)

Return value

0 = completed normally; negative value = error (see 4.2 Error information)

  • Input and output are signed integers; param_n specifies their bit width.
  • Use asynchronous execution such as await Task.Run(...).

4.1.8 IntSubSat

Executes signed saturating subtraction. If the result exceeds the data type range, the maximum or minimum value of that type is returned.

int IntSubSat(byte[] aBuffer, byte[] bBuffer, byte[] outBuffer, byte param_n)
ParameterTypeDescription
aBufferbyte[]Input array A (minuend)
bBufferbyte[]Input array B (subtrahend)
outBufferbyte[]Output array (A - B)
param_nbyteN parameter - total bit width (2-32)

Return value

0 = completed normally; negative value = error (see 4.2 Error information)

  • Use asynchronous execution such as await Task.Run(...).

4.1.9 IntMulSat

Executes signed saturating multiplication. It supports output width k; when k = 2n, the full product is preserved without saturation.

int IntMulSat(byte[] aBuffer, byte[] bBuffer, byte[] outBuffer, byte param_n, byte param_k)
ParameterTypeDescription
aBufferbyte[]Input array A (operand A)
bBufferbyte[]Input array B (operand B)
outBufferbyte[]Output array (A x B)
param_nbyteN parameter - total bit width of each operand (2-16)
param_kbyteK parameter - output bit width (n-2n; no saturation when k = 2n)

Return value

0 = completed normally; negative value = error (see 4.2 Error information)

  • A and B are n-bit signed integers.
  • When k = 2n, the full product is retained without saturation clipping.
  • Use asynchronous execution such as await Task.Run(...).

4.2 Error information

Error codeDescription
0Completed normally
-1Not connected (device handle was not obtained; Connect was not called or failed)
-2Failed to obtain an idle BankID (processing failed or no idle bank was found)
-3Failed to send SetDataDMA command
-4Failed to send StartCalculation command
-5Failed to send GetBankStatus command (send failed or status polling timed out)
-6Failed to send GetDataDMA command
-10Command-list transfer failed
-11Command-list generation failed
-12Input exceeds the capacity limit per call, or the SloppySoftmax element count is not a multiple of 2^d

5. Input/output data specification

5.1 Terminology

TermDescription
nBit width of one input value (for example, 22 bits)
bFractional-part bit width
dUsed only by SloppySoftmax; exponent of the element count in one group (one group = 2^d elements)
kUsed only by IntMulSat; output bit width (n-2n)
I(s, m, b)Fixed-point type: s = number of sign bits, m = integer bit width, b = fractional bit width, total width = s + m + b
bytesPerDataBytes per item: input = (n+7)/8; output is calculated from output width
elementCountNumber of items = inBuffer.length / ((n+7)/8)
LSB firstStore bits sequentially starting with bit0 (the least-significant bit)

5.2 Input/output types

MethodInput typeOutput typeOutput bit widthResult type
SloppySigmoidI(1, n-1-b, b)I(0, 0, b+2)b + 2Unsigned (0-1)
SloppyTanhI(1, n-1-b, b)I(1, 0, b)b + 1Signed (-1 to +1)
SloppySiLUI(1, n-1-b, b)I(1, n-1-b, b)nSigned
SloppyGeLUI(1, n-1-b, b)I(1, n-1-b, b)nSigned
SloppySoftmaxI(1, n-1-b, b)I(0, 0, n)nUnsigned (0-1)
IntAddSatI(1, n-1, 0)I(1, n-1, 0)nSigned
IntSubSatI(1, n-1, 0)I(1, n-1, 0)nSigned
IntMulSatI(1, n-1, 0)I(1, k-1, 0)kSigned

5.3 Input data

Input-data generation flow

  1. Mask the value to n bits (for example, use only the lower 22 bits).
  2. Sign-extend it: when the highest bit is 1, treat it as negative and fill higher bits with 1.
  3. Pack the bits LSB first.
  4. Store each item in (n + 7) / 8 bytes; unused bits in the final byte are not used.

Bit layout example (n = 22 -> 3 bytes/item)

ByteBit contents
Byte0bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
Byte1bit15 bit14 bit13 bit12 bit11 bit10 bit9 bit8
Byte2[unused] [unused] bit21 bit20 bit19 bit18 bit17 bit16

Input example: {45, -73} (n = 22)

// Byte sequence for {45, -73} (n = 22, 3 bytes/data):
// 45  -> 0x00002D -> Byte0: 0x2D, Byte1: 0x00, Byte2: 0x00
// -73 -> 0x3FFFB7 -> Byte0: 0xB7, Byte1: 0xFF, Byte2: 0x3F
//
// Final inBuffer: 2D 00 00 B7 FF 3F

SloppySoftmax input/output notes

  • Input data consists of consecutive Softmax groups; every group contains 2^d consecutive elements.
  • Output is returned in the same group order.
  • The number of input elements must be a multiple of 2^d (complete groups).
  • This is an approximate operation; output can deviate by approximately +/-1 least-significant bit.

5.4 Output data

Output-data reconstruction flow

  1. Restore the output-width bits LSB first.
  2. Interpret the sign according to the output type.
  3. Signed (Tanh / SiLU / GeLU): use the highest bit as the sign bit and sign-extend it.
  4. Unsigned (Sigmoid / Softmax): do not sign-extend (fixed-point fraction at or above 0).

Buffer allocation

MethodOutput bit widthBytes per item
SloppySigmoidb + 2(b + 2 + 7) / 8
SloppyTanhb + 1(b + 1 + 7) / 8
SloppySiLU / GeLU / Softmaxn(n + 7) / 8
IntAddSat / IntSubSatn(n + 7) / 8
IntMulSatk(k + 7) / 8

5.5 Capacity limit

One calculation call can process at most one device page: an effective area of 15872 elements. Calls exceeding the limit must be split by the caller.

Function categoryPer-call limitRemarks
Sigmoid / Tanh / SiLU / GeLU / IntAddSat / IntSubSat / IntMulSatelementCount <= 15872Element unit
SloppySoftmaxGroup count <= 15872 / 2^dInput element count must be a multiple of 2^d

SloppySoftmax maximum group count examples

dPer-call limit
23968 groups
931 groups
131 group
14+Not supported

Important: When the limit is exceeded, error code -12 is returned. SloppySoftmax also returns -12 when its input element count is not a multiple of 2^d.