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
| Item | Content |
|---|---|
| Supported operating system | Windows 64-bit |
| Supported architecture | x64 |
| Target framework | .NET 8.0 |
| Required privilege | Administrator |
| Dependency library | System.Management.dll |
| Runtime dependency files | None |
| Distribution | SSPU.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
| Method | Function |
|---|---|
| Connect | Connect to an SSPU device |
| SloppySigmoid | Approximate Sigmoid activation |
| SloppyTanh | Approximate Tanh activation |
| SloppySiLU | Approximate SiLU activation |
| SloppyGeLU | Approximate GeLU activation |
| SloppySoftmax | Approximate Softmax activation |
| IntAddSat | Signed saturating addition |
| IntSubSat | Signed saturating subtraction |
| IntMulSat | Signed 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)| Parameter | Type | Description |
|---|---|---|
| inBuffer | byte[] | Input data array (see 5.3 Input data generation) |
| outBuffer | byte[] | Output data array (see 5.4 buffer allocation) |
| param_n | byte | N parameter - total bit width (3-32) |
| param_b | byte | B 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)| Parameter | Type | Description |
|---|---|---|
| inBuffer | byte[] | Input data array |
| outBuffer | byte[] | Output data array |
| param_n | byte | N parameter - total bit width (3-32) |
| param_b | byte | B 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)| Parameter | Type | Description |
|---|---|---|
| inBuffer | byte[] | Input data array |
| outBuffer | byte[] | Output data array |
| param_n | byte | N parameter - total bit width (3-32) |
| param_b | byte | B 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)| Parameter | Type | Description |
|---|---|---|
| inBuffer | byte[] | Input data array |
| outBuffer | byte[] | Output data array |
| param_n | byte | N parameter - total bit width (3-32) |
| param_b | byte | B 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)| Parameter | Type | Description |
|---|---|---|
| inBuffer | byte[] | Input data array |
| outBuffer | byte[] | Output data array |
| param_n | byte | N parameter - total bit width |
| param_b | byte | B parameter - fractional bit width |
| param_d | byte | D parameter - exponent of element count per group (one group = 2^d elements) |
| param_mode | byte | Mode 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(...).
| Mode | Type | Valid parameter range |
|---|---|---|
| 0 (default) | Simple | 3 <= n <= 32, b >= 0, 2 <= d <= 13, 2 <= n-b <= d+1 |
| 1 | Standard | 7 <= n <= 32, b >= 4, d >= 1, 3 <= n-b <= d+2 |
| 2+ | Reserved | Reserved; 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)| Parameter | Type | Description |
|---|---|---|
| aBuffer | byte[] | Input array A (operand A) |
| bBuffer | byte[] | Input array B (operand B) |
| outBuffer | byte[] | Output array (A + B) |
| param_n | byte | N 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)| Parameter | Type | Description |
|---|---|---|
| aBuffer | byte[] | Input array A (minuend) |
| bBuffer | byte[] | Input array B (subtrahend) |
| outBuffer | byte[] | Output array (A - B) |
| param_n | byte | N 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)| Parameter | Type | Description |
|---|---|---|
| aBuffer | byte[] | Input array A (operand A) |
| bBuffer | byte[] | Input array B (operand B) |
| outBuffer | byte[] | Output array (A x B) |
| param_n | byte | N parameter - total bit width of each operand (2-16) |
| param_k | byte | K 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 code | Description |
|---|---|
| 0 | Completed normally |
| -1 | Not connected (device handle was not obtained; Connect was not called or failed) |
| -2 | Failed to obtain an idle BankID (processing failed or no idle bank was found) |
| -3 | Failed to send SetDataDMA command |
| -4 | Failed to send StartCalculation command |
| -5 | Failed to send GetBankStatus command (send failed or status polling timed out) |
| -6 | Failed to send GetDataDMA command |
| -10 | Command-list transfer failed |
| -11 | Command-list generation failed |
| -12 | Input 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
| Term | Description |
|---|---|
| n | Bit width of one input value (for example, 22 bits) |
| b | Fractional-part bit width |
| d | Used only by SloppySoftmax; exponent of the element count in one group (one group = 2^d elements) |
| k | Used 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 |
| bytesPerData | Bytes per item: input = (n+7)/8; output is calculated from output width |
| elementCount | Number of items = inBuffer.length / ((n+7)/8) |
| LSB first | Store bits sequentially starting with bit0 (the least-significant bit) |
5.2 Input/output types
| Method | Input type | Output type | Output bit width | Result type |
|---|---|---|---|---|
| SloppySigmoid | I(1, n-1-b, b) | I(0, 0, b+2) | b + 2 | Unsigned (0-1) |
| SloppyTanh | I(1, n-1-b, b) | I(1, 0, b) | b + 1 | Signed (-1 to +1) |
| SloppySiLU | I(1, n-1-b, b) | I(1, n-1-b, b) | n | Signed |
| SloppyGeLU | I(1, n-1-b, b) | I(1, n-1-b, b) | n | Signed |
| SloppySoftmax | I(1, n-1-b, b) | I(0, 0, n) | n | Unsigned (0-1) |
| IntAddSat | I(1, n-1, 0) | I(1, n-1, 0) | n | Signed |
| IntSubSat | I(1, n-1, 0) | I(1, n-1, 0) | n | Signed |
| IntMulSat | I(1, n-1, 0) | I(1, k-1, 0) | k | Signed |
5.3 Input data
Input-data generation flow
- Mask the value to n bits (for example, use only the lower 22 bits).
- Sign-extend it: when the highest bit is 1, treat it as negative and fill higher bits with 1.
- Pack the bits LSB first.
- 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)
| Byte | Bit contents |
|---|---|
| Byte0 | bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 |
| Byte1 | bit15 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 3FSloppySoftmax 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
- Restore the output-width bits LSB first.
- Interpret the sign according to the output type.
- Signed (Tanh / SiLU / GeLU): use the highest bit as the sign bit and sign-extend it.
- Unsigned (Sigmoid / Softmax): do not sign-extend (fixed-point fraction at or above 0).
Buffer allocation
| Method | Output bit width | Bytes per item |
|---|---|---|
| SloppySigmoid | b + 2 | (b + 2 + 7) / 8 |
| SloppyTanh | b + 1 | (b + 1 + 7) / 8 |
| SloppySiLU / GeLU / Softmax | n | (n + 7) / 8 |
| IntAddSat / IntSubSat | n | (n + 7) / 8 |
| IntMulSat | k | (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 category | Per-call limit | Remarks |
|---|---|---|
| Sigmoid / Tanh / SiLU / GeLU / IntAddSat / IntSubSat / IntMulSat | elementCount <= 15872 | Element unit |
| SloppySoftmax | Group count <= 15872 / 2^d | Input element count must be a multiple of 2^d |
SloppySoftmax maximum group count examples
| d | Per-call limit |
|---|---|
| 2 | 3968 groups |
| 9 | 31 groups |
| 13 | 1 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.