OPAE C API Reference¶
The reference documentation for the OPAE C API is grouped into the following sections:
Types¶
The OPAE C API defines a number of types; most prominent are the types
fpga_token
, fpga_handle
, and fpga_properties
. All regular
types are defined in types.h, while the values of
enumeration types are defined in types_enum.h.
types.h¶
Type definitions for FPGA API.
OPAE uses the three opaque types fpga_properties, fpga_token, and fpga_handle to create a hierarchy of objects that can be used to enumerate, reference, acquire, and query FPGA resources. This object model is designed to be extensible to account for different FPGA architectures and platforms.
Initialization
OPAEs management of the opaque types fpga_properties
, fpga_token
, and fpga_handle
relies on the proper initialization of variables of these types. In other words, before doing anything with a variable of one of these opaque types, you need to first initialize them.
The respective functions that initizalize opaque types are:
- fpgaGetProperties() and fpgaCloneProperties() for
fpga_properties
- fpgaEnumerate() and fpgaCloneToken() for
fpga_token
- fpgaOpen() for
fpga_handle
This should intuitively make sense - fpgaGetProperties() creates fpga_properties
objects, fpgaEnumerate() creates fpga_token
objects, fpgaOpen() creates fpga_handle
objects, and fpgaCloneProperties() and fpgaCloneToken() clone (create) fpga_properties
and fpga_token
objects, respectively.
Since these opaque types are interpreted as pointers (they are typedef’d to a void *
), passing an uninitialized opaque type into any function except the respective initailzation function will result in undefined behaviour, because OPAE will try to follow an invalid pointer. Undefined behaviour in this case may include an unexpected error code, or an application crash.
Typedefs
-
typedef void *
fpga_properties
¶ Object for expressing FPGA resource properties
fpga_properties
objects encapsulate all enumerable information about an FPGA resources. They can be used for two purposes: selective enumeration (discovery) and querying information about existing resources.For selective enumeration, usually an empty
fpga_properties
object is created (using fpgaGetProperties()) and then populated with the desired criteria for enumeration. An array offpga_properties
can then be passed to fpgaEnumerate(), which will return a list offpga_token
objects matching these criteria.For querying properties of existing FPGA resources, fpgaGetProperties() can also take an
fpga_token
and will return anfpga_properties
object populated with information about the resource referenced by that token.After use,
fpga_properties
objects should be destroyed using fpga_destroyProperties() to free backing memory used by thefpga_properties
object.
-
typedef void *
fpga_token
¶ Token for referencing FPGA resources
An
fpga_token
serves as a reference to a specific FPGA resource present in the system. Holding anfpga_token
does not constitute ownership of the FPGA resource - it merely allows the user to query further information about a resource, or to use fpgaOpen() to acquire ownership.fpga_token
s are usually returned by fpgaEnumerate() or fpgaPropertiesGetParent(), and used by fpgaOpen() to acquire ownership and yield a handle to the resource. Some API calls also takefpga_token
s as arguments if they don’t require ownership of the resource in question.
-
typedef void *
fpga_handle
¶ Handle to an FPGA resource
A valid
fpga_handle
object, as populated by fpgaOpen(), denotes ownership of an FPGA resource. Note that ownership can be exclusive or shared, depending on the flags used in fpgaOpen(). Ownership can be released by calling fpgaClose(), which will render the underlying handle invalid.Many OPAE C API functions require a valid token (which is synonymous with ownership of the resource).
-
typedef uint8_t
fpga_guid
[16]¶ Globally unique identifier (GUID)
GUIDs are used widely within OPAE for helping identify FPGA resources. For example, every FPGA resource has a
guid
property, which can be (and in the case of FPGA_ACCELERATOR resource primarily is) used for enumerating a resource of a specific type.fpga_guid
is compatible with libuuid’s uuid_t, so users can use libuuid functions like uuid_parse() to create and work with GUIDs.
-
typedef int
fpga_event_handle
¶ Handle to an event object
OPAE provides an interface to asynchronous events that can be generated by different FPGA resources. The event API provides functions to register for these events; associated with every event a process has registered for is an
fpga_event_handle
, which encapsulates the OS-specific data structure for event objects.On Linux, an
fpga_event_handle
can be used as a file descriptor and passed to select(), poll(), epoll() and similar functions to wait for asynchronous events.
-
struct
fpga_version
¶ - #include <types.h>
Semantic version
Data structure for expressing version identifiers following the semantic versioning scheme. Used in various properties for tracking component versions.
types_enum.h¶
Definitions of enumerated types for the OPAE C API.
This file defines return and error codes, event and object types, states, and flags as used or reported by OPAE C API functions.
Enums
-
enum
fpga_result
¶ OPAE C API function return codes
Every public API function exported by the OPAE C library will return one of these codes. Usually, FPGA_OK denotes successful completion of the requested operation, while any return code other than FPGA_OK indicates an error or other deviation from the expected behavior. Users of the OPAE C API should always check the return codes of the APIs they call, and not use output parameters of functions that did not execute successfully.
The fpgaErrStr() function converts error codes into printable messages.
OPAE also has a logging mechanism that allows a developer to get more information about why a particular call failed with a specific message. If enabled, any function that returns an error code different from FPGA_OK will also print out a message with further details. This mechanism can be enabled by setting the environment variable
LIBOPAE_LOG
to 1 before running the respective application.Values:
-
FPGA_OK
= 0¶ Operation completed successfully
-
FPGA_INVALID_PARAM
¶ Invalid parameter supplied
-
FPGA_BUSY
¶ Resource is busy
-
FPGA_EXCEPTION
¶ An exception occurred
-
FPGA_NOT_FOUND
¶ A required resource was not found
-
FPGA_NO_MEMORY
¶ Not enough memory to complete operation
-
FPGA_NOT_SUPPORTED
¶ Requested operation is not supported
-
FPGA_NO_DRIVER
¶ Driver is not loaded
-
FPGA_NO_DAEMON
¶ FPGA Daemon (fpgad) is not running
-
FPGA_NO_ACCESS
¶ Insufficient privileges or permissions
-
FPGA_RECONF_ERROR
¶ Error while reconfiguring FPGA
-
-
enum
fpga_event_type
¶ FPGA events
OPAE currently defines the following event types that applications can register for. Note that not all FPGA resources and target platforms may support all event types.
Values:
-
FPGA_EVENT_INTERRUPT
= 0¶ Interrupt generated by an accelerator
-
FPGA_EVENT_ERROR
¶ Infrastructure error event
-
FPGA_EVENT_POWER_THERMAL
¶ Infrastructure thermal event
-
-
enum
fpga_accelerator_state
¶ accelerator state
Values:
-
FPGA_ACCELERATOR_ASSIGNED
= 0¶ accelerator is opened exclusively by another process
-
FPGA_ACCELERATOR_UNASSIGNED
¶ accelerator is free to be opened
-
-
enum
fpga_objtype
¶ OPAE FPGA resources (objects)
These are the FPGA resources currently supported by the OPAE object model.
Values:
-
FPGA_DEVICE
= 0¶ FPGA_DEVICE objects represent FPGA devices and their management functionality. These objects can be opened (typically requires a certain privilege level or access permissions) and used for management functions like fpgaReconfigreSlot().
-
FPGA_ACCELERATOR
¶ FPGA_ACCELERATOR objects represent allocatable units for accessing accelerated functions on the FPGA. They are frequently opened for interacting via control registers (MMIO), shared memory, or other, possibly platform-specific functions.
-
-
enum
fpga_buffer_flags
¶ Buffer flags
These flags can be passed to the fpgaPrepareBuffer() function.
Values:
-
FPGA_BUF_PREALLOCATED
= (1u << 0)¶ Use existing buffer
-
FPGA_BUF_QUIET
= (1u << 1)¶ Suppress error messages
-
-
enum
fpga_open_flags
¶ Open flags
These flags can be passed to the fpgaOpen() function.
Values:
-
FPGA_OPEN_SHARED
= (1u << 0)¶ Open FPGA resource for shared access
-
Enumeration API¶
The OPAE enumeration API allows selective discovery of FPGA resources. When enumerating resources, a list of filter criteria can be passed to the respective function to select a subset of all resources in the system. The fpgaEnumerate() function itself then returns a list of fpga_tokens denoting resources, which can be used in subsequent API calls.
Filter criteria are specified using one or more fpga_properties object. These objects need to be created using fpgaGetProperties() (defined in <opae/properties/h>) before being passed to fpgaEnumerate(). Individual attributes of an fpga_properties object are set using specific accessors, which are also defined in <opae/properties.h>.
enum.h¶
APIs for resource enumeration and managing tokens.
These APIs are the first step for any application using OPAE to discover resources that are present on the system. They allow selective enumeration (i.e. getting a list of resources that match a given list of criteria) and methods to manage the lifecycle of tokens generated by fpgaEnumerate().
Functions
-
fpga_result
fpgaEnumerate
(const fpga_properties *filters, uint32_t num_filters, fpga_token *tokens, uint32_t max_tokens, uint32_t *num_matches)¶ Enumerate FPGA resources present in the system
This call allows the user to query the system for FPGA resources that match a certain set of criteria, e.g. all accelerators that are assigned to a host interface and available, all FPGAs of a specific type, etc.
fpgaEnumerate() will create a number of
fpga_token
s to represent the matching resources and populate the arraytokens
with these tokens. Themax_tokens
argument can be used to limit the number of tokens allocated/returned by fpgaEnumerate(); i.e., the number of tokens in the returnedtokens
array will be eithermax_tokens
ornum_matches
(the number of resources matching the filter), whichever is smaller. Use fpgaDestroyToken() to destroy tokens that are no longer needed.To query the number of matches for a particular set of filters (e.g. to allocate a
tokens
array of the appropriate size), call fpgaEnumerate() with the parametertokens
set to NULL; this will only return the number of matches innum_matches
.- Note
- fpgaEnumerate() will allocate memory for the created tokens returned in
tokens
. It is the responsibility of the using application to free this memory after use by calling fpgaDestroyToken() for each of the returned tokens. - Return
- FPGA_OK on success. FPGA_INVALID_PARAM if invalid pointers or objects are passed into the function. FPGA_NO_DRIVER if OPAE can’t find the respective enumeration data structures usually provided by the driver. FPGA_NO_MEMORY if there was not enough memory to create tokens.
- Parameters
filters
: Array offpga_properties
objects describing the properties of the objects that should be returned. A resource is considered matching if its properties match any one of the supplied filters. Passing NULL will match all FPGA resources present in the system.num_filters
: Number of entries in thefilters
array.tokens
: Pointer to an array of fpga_token variables to be populated. If NULL is supplied, fpgaEnumerate() will not create any tokens, but it will return the number of possible matches innum_match
.max_tokens
: Maximum number of tokens that fpgaEnumerate() shall return (length oftokens
array). There may be more or fewer matches than this number;num_matches
is set to the number of actual matches.num_matches
: Number of resources matching thefilter
criteria. This number can be higher than the number of tokens returned in thetokens
array (depending on the value ofmax_tokens
).
-
fpga_result
fpgaCloneToken
(fpga_token src, fpga_token *dst)¶ Clone a fpga_token object
Creates a copy of an fpga_token object.
- Note
- This call creates a new token object and allocates memory for it. It is the responsibility of the using application to free this memory after use by calling fpgaDestroyToken() for the cloned token.
- Return
- FPGA_OK on success
- Parameters
src
: fpga_token object to copydst
: New fpga_token object cloned from ‘src’
-
fpga_result
fpgaDestroyToken
(fpga_token *token)¶ Destroy a Token
This function destroys a token created by fpgaEnumerate() and frees the associated memory.
- Return
- FPGA_OK on success
- Parameters
token
: fpga_token to destroy
properties.h¶
Functions for examining and manipulating fpga_properties
objects.
In OPAE, fpga_properties
objects are used both for obtaining information about resources and for selectively enumerating resources based on their properties. This file provides accessor functions (get/set) to allow reading and writing individual items of an fpga_properties
object. Generally, not all object types supported by OPAE carry all properties. If you call a property accessor method on a fpga_properties
object that does not support this particular property, it will return FPGA_INVALID_PARAM.
Accessor Return Values
In addition to the return values specified in the documentation below, all accessor functions return FPGA_OK on success, FPGA_INVALID_PARAM if you pass NULL or invalid parameters (i.e. non-initialized properties objects), FPGA_EXCEPTION if an internal exception occurred trying to access the properties object, FPGA_NOT_FOUND if the requested property is not part of the supplied properties object.
Functions
-
fpga_result
fpgaGetProperties
(fpga_token token, fpga_properties *prop)¶ Create a fpga_properties object
Initializes the memory pointed at by
prop
to represent a properties object, and populates it with the properties of the resource referred to bytoken
. Individual properties can then be queried using fpgaPropertiesGet*() accessor functions.If
token
is NULL, an “empty” properties object is created to be used as a filter for fpgaEnumerate(). All individual fields are set todon
t care`, which implies that the fpga_properties object would match all FPGA resources if used for an fpgaEnumerate() query. The matching criteria can be further refined by using fpgaSet* functions on the properties object, or the object can be populated with the actual properties of a resource by using fpgaUpdateProperties().- Note
- fpgaGetProperties() will allocate memory for the created properties object returned in
prop
. It is the responsibility of the using application to free this memory after use by calling fpgaDestroyProperties(). - Return
- FPGA_OK on success. FPGA_NO_MEMORY if no memory could be allocated to create the
fpga_properties
object. FPGA_EXCEPTION if an exception happend while initializing thefpga_properties
object. - Parameters
token
: Token to get properties for. Can be NULL, which will create an empty properties object to be used as a filter for fpgaEnumerate().prop
: Pointer to a variable of type fpga_properties
-
fpga_result
fpgaUpdateProperties
(fpga_token token, fpga_properties prop)¶ Update a fpga_properties object
Populates the properties object ‘prop’ with properties of the resource referred to by ‘token’. Unlike fpgaGetProperties(), this call will not create a new properties object or allocate memory for it, but use a previously created properties object.
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if
token
orprop
are not valid objects. FPGA_NOT_FOUND if the resource referred to bytoken
was not found. FPGA_NO_DRIVER if not driver is loaded. FPGA_EXCEPTION if an internal exception occured when trying to updateprop
. - Parameters
token
: Token to retrieve properties forprop
: fpga_properties object to update
-
fpga_result
fpgaClearProperties
(fpga_properties prop)¶ Clear a fpga_properties object
Sets all fields of the properties object pointed at by ‘prop’ to ‘don’t care’, which implies that the fpga_properties object would match all FPGA resources if used for an fpgaEnumerate() query. The matching criteria can be further refined by using fpgaSet* functions on the properties object.
Instead of creating a new fpga_properties object every time, this function can be used to re-use fpga_properties objects from previous queries.
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if
prop
is not a valid object. FPGA_EXCEPTION if an * internal exception occured when trying to accessprop
. - Parameters
prop
: fpga_properties object to clear
-
fpga_result
fpgaCloneProperties
(fpga_properties src, fpga_properties *dst)¶ Clone a fpga_properties object
Creates a copy of an fpga_properties object.
- Note
- This call creates a new properties object and allocates memory for it. Both the ‘src’ and the newly created ‘dst’ objects will eventually need to be destroyed using fpgaDestroyProperties().
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if
src
is not a valid object, or ifdst
is NULL. FPGA_NO_MEMORY if there was not enough memory to allocate anfpga_properties
object fordst
. FPGA_EXCEPTION if an internal exception occurred either accessingsrc
or updatingdst
. - Parameters
src
: fpga_properties object to copydst
: New fpga_properties object cloned from ‘src’
-
fpga_result
fpgaDestroyProperties
(fpga_properties *prop)¶ Destroy a fpga_properties object
Destroys an existing fpga_properties object that the caller has previously created using fpgaGetProperties() or fpgaCloneProperties().
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM is
prop
is not a valid object. FPGA_EXCEPTION if an internal exception occurrred while trying to accessprop
. - Parameters
prop
: Pointer to the fpga_properties object to destroy
-
fpga_result
fpgaPropertiesGetParent
(const fpga_properties prop, fpga_token *parent)¶ Get the token of the parent object
Returns the token of the parent of the queried resource in ‘*parent’.
- Return
- FPGA_NOT_FOUND if resource does not have a parent (e.g. an FPGA_DEVICE resource does not have parents). Also see “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to queryparent
: Pointer to a token variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetParent
(fpga_properties prop, fpga_token parent)¶ Set the token of the parent object
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modifyparent
: Pointer to a token variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetObjectType
(const fpga_properties prop, fpga_objtype *objtype)¶ Get the object type of a resource
Returns the object type of the queried resource.
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to queryobjtype
: Pointer to an object type variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetObjectType
(fpga_properties prop, fpga_objtype objtype)¶ Set the object type of a resource
Sets the object type of the resource. * Currently supported object types are FPGA_DEVICE and FPGA_ACCELERATOR.
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modifyobjtype
: Object type of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetBus
(const fpga_properties prop, uint8_t *bus)¶ Get the PCI bus number of a resource
Returns the bus number the queried resource.
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to querybus
: Pointer to a PCI bus variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetBus
(fpga_properties prop, uint8_t bus)¶ Set the PCI bus number of a resource
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modifybus
: PCI bus number of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetDevice
(const fpga_properties prop, uint8_t *device)¶ Get the PCI device number of a resource
Returns the device number the queried resource.
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to querydevice
: Pointer to a PCI device variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetDevice
(fpga_properties prop, uint8_t device)¶ Set the PCI device number of a resource
Enforces the limitation on the number of devices as specified in the PCI spec.
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modifydevice
: PCI device number of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetFunction
(const fpga_properties prop, uint8_t *function)¶ Get the PCI function number of a resource
Returns the function number the queried resource.
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to queryfunction
: Pointer to PCI function variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetFunction
(fpga_properties prop, uint8_t function)¶ Set the PCI function number of a resource
Enforces the limitation on the number of functions as specified in the PCI spec.
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modifyfunction
: PCI function number of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetSocketID
(const fpga_properties prop, uint8_t *socket_id)¶ Get the socket id of a resource
Returns the socket id of the queried resource.
- Return
- See “Accessor Return Values” in properties.h. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to querysocket_id
: Pointer to a socket id variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetSocketID
(fpga_properties prop, uint8_t socket_id)¶ Set the socket id of the resource
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modifysocket_id
: Socket id of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetDeviceID
(const fpga_properties prop, uint32_t *device_id)¶ Get the device id of the resource
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to querydevice_id
: Pointer to a device id variable of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesSetDeviceID
(fpga_properties prop, uint32_t device_id)¶ Set the device id of the resource
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modifydevice_id
: Device id of the resource ‘prop’ is associated with
-
fpga_result
fpgaPropertiesGetNumSlots
(const fpga_properties prop, uint32_t *num_slots)¶ Get the number of slots of an FPGA resource property
Returns the number of slots present in an FPGA.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to query - must be of type FPGA_DEVICEnum_slots
: Pointer to number of slots variable of the FPGA
-
fpga_result
fpgaPropertiesSetNumSlots
(fpga_properties prop, uint32_t num_slots)¶ Set the number of slots of an FPGA resource property
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modify - must be of type FPGA_DEVICEnum_slots
: Number of slots of the FPGA
-
fpga_result
fpgaPropertiesGetBBSID
(const fpga_properties prop, uint64_t *bbs_id)¶ Get the BBS ID of an FPGA resource property
Returns the blue bitstream id of an FPGA.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to query - must be of type FPGA_DEVICEbbs_id
: Pointer to a bbs id variable of the FPGA
-
fpga_result
fpgaPropertiesSetBBSID
(fpga_properties prop, uint64_t bbs_id)¶ Set the BBS ID of an FPGA resource property
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modify - must be of type FPGA_DEVICEbbs_id
: Blue bitstream id of the FPGA resource
-
fpga_result
fpgaPropertiesGetBBSVersion
(const fpga_properties prop, fpga_version *bbs_version)¶ Get the BBS Version of an FPGA resource property
Returns the blue bitstream version of an FPGA.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to query - must be of type FPGA_DEVICEbbs_version
: Pointer to a bbs version variable of the FPGA
-
fpga_result
fpgaPropertiesSetBBSVersion
(fpga_properties prop, fpga_version version)¶ Set the BBS Version of an FPGA resource property
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modify - must be of type FPGA_DEVICEversion
: Blue bitstream version of the FPGA resource
-
fpga_result
fpgaPropertiesGetVendorID
(const fpga_properties prop, uint16_t *vendor_id)¶ Get the vendor id of an FPGA resource property
Returns the vendor id of an FPGA.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
- This API is not currently supported.
- Parameters
prop
: Properties object to query - must be of type FPGA_DEVICEvendor_id
: Pointer to a vendor id variable of the FPGA
-
fpga_result
fpgaPropertiesSetVendorID
(fpga_properties prop, uint16_t vendor_id)¶ Set the vendor id of an FPGA resource property
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
- This API is not currently supported.
- Parameters
prop
: Properties object to modify - must be of type FPGA_DEVICEvendor_id
: Vendor id of the FPGA resource
-
fpga_result
fpgaPropertiesGetModel
(const fpga_properties prop, char *model)¶ Get the model of an FPGA resource property
Returns the model of an FPGA.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
- This API is not currently supported.
- Parameters
prop
: Properties object to query - must be of type FPGA_DEVICEmodel
: Model of the FPGA resource (string of minimum FPGA_MODEL_LENGTH length
-
fpga_result
fpgaPropertiesSetModel
(fpga_properties prop, char *model)¶ Set the model of an FPGA resource property
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
- This API is not currently supported.
- Parameters
prop
: Properties object to modify - must be of type FPGA_DEVICEmodel
: Model of the FPGA resource (string of maximum FPGA_MODEL_LENGTH length
-
fpga_result
fpgaPropertiesGetLocalMemorySize
(const fpga_properties prop, uint64_t *lms)¶ Get the local memory size of an FPGA resource property
Returns the local memory size of an FPGA.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
- This API is not currently supported.
- Parameters
prop
: Properties object to query - must be of type FPGA_DEVICElms
: Pointer to a memory size variable of the FPGA
-
fpga_result
fpgaPropertiesSetLocalMemorySize
(fpga_properties prop, uint64_t lms)¶ Set the local memory size of an FPGA resource property
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
- This API is not currently supported.
- Parameters
prop
: Properties object to modify - must be of type FPGA_DEVICElms
: Local memory size of the FPGA resource
-
fpga_result
fpgaPropertiesGetCapabilities
(const fpga_properties prop, uint64_t *capabilities)¶ Get the capabilities FPGA resource property
Returns the capabilities of an FPGA. Capabilities is a bitfield value
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
- This API is not currently supported.
- Parameters
prop
: Properties object to query - must be of type FPGA_DEVICEcapabilities
: Pointer to a capabilities variable of the FPGA
-
fpga_result
fpgaPropertiesSetCapabilities
(fpga_properties prop, uint64_t capabilities)¶ Set the capabilities of an FPGA resource property
Capabilities is a bitfield value
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_DEVICE. See also “Accessor Return Values” in properties.h.
- Note
- This API is not currently supported.
- Parameters
prop
: Properties object to modify - must be of type FPGA_DEVICEcapabilities
: Capabilities of the FPGA resource
-
fpga_result
fpgaPropertiesGetGUID
(const fpga_properties prop, fpga_guid *guid)¶ Get the GUID of a resource
Returns the GUID of an FPGA or accelerator object.
For an accelerator, the GUID uniquely identifies a specific accelerator context type, i.e. different accelerators will have different GUIDs. For an FPGA, the GUID is used to identify a certain instance of an FPGA, e.g. to determine whether a given bitstream would be compatible.
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to queryguid
: Pointer to a GUID of the slot variable
-
fpga_result
fpgaPropertiesSetGUID
(fpga_properties prop, fpga_guid guid)¶ Set the GUID of a resource
Sets the GUID of an FPGA or accelerator object.
For an accelerator, the GUID uniquely identifies a specific accelerator context type, i.e. different accelerators will have different GUIDs. For an FPGA, the GUID is used to identify a certain instance of an FPGA, e.g. to determine whether a given bitstream would be compatible.
- Return
- See “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modifyguid
: Pointer to a GUID of the slot variable
-
fpga_result
fpgaPropertiesGetNumMMIO
(const fpga_properties prop, uint32_t *mmio_spaces)¶ Get the number of mmio spaces
Returns the number of mmio spaces of an AFU properties structure.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to query - must be of type FPGA_ACCELERATORmmio_spaces
: Pointer to a variable for number of mmio spaces
-
fpga_result
fpgaPropertiesSetNumMMIO
(fpga_properties prop, uint32_t mmio_spaces)¶ Set the number of mmio spaces
Sets the number of mmio spaces of an AFU properties structure.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modify - must be of type FPGA_ACCELERATORmmio_spaces
: Number of MMIO spaces of the accelerator
-
fpga_result
fpgaPropertiesGetNumInterrupts
(const fpga_properties prop, uint32_t *num_interrupts)¶ Get the number of interrupts
Returns the number of interrupts of an accelerator properties structure.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to query - must be of type FPGA_ACCELERATORnum_interrupts
: Pointer to a variable for number of interrupts
-
fpga_result
fpgaPropertiesSetNumInterrupts
(fpga_properties prop, uint32_t num_interrupts)¶ Set the number of mmio spaces
Sets the number of interrupts of an accelerator properties structure.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modify - must be of type FPGA_ACCELERATORnum_interrupts
: Number of interrupts of the accelerator
-
fpga_result
fpgaPropertiesGetAcceleratorState
(const fpga_properties prop, fpga_accelerator_state *state)¶ Get the state of a accelerator resource property
Returns the accelerator state of a accelerator.
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to query - must be of type FPGA_ACCELERATORstate
: Pointer to a accelerator state variable of the accelerator
-
fpga_result
fpgaPropertiesSetAcceleratorState
(fpga_properties prop, fpga_accelerator_state state)¶ Set the state of an accelerator resource property
- Return
- FPGA_INVALID_PARAM if object type is not FPGA_ACCELERATOR. See also “Accessor Return Values” in properties.h.
- Parameters
prop
: Properties object to modify - must be of type FPGA_ACCELERATORstate
: accelerator state of the accelerator resource
Access API¶
The access API provides functions for opening and closing FPGA resources. Opening a resource yields an fpga_handle, which denotes ownership and can be used in subsequent API calls to interact with a specific resource. Ownership can be exclusive or shared.
access.h¶
Functions to acquire, release, and reset OPAE FPGA resources.
Functions
-
fpga_result
fpgaOpen
(fpga_token token, fpga_handle *handle, int flags)¶ Open an FPGA object
Acquires ownership of the FPGA resource referred to by ‘token’.
Most often this will be used to open an accelerator object to directly interact with an accelerator function, or to open an FPGA object to perform management functions.
- Return
- FPGA_OK on success. FPGA_NOT_FOUND if the resource for ‘token’ could not be found. FPGA_INVALID_PARAM if ‘token’ does not refer to a resource that can be opened, or if either argument is NULL or invalid. FPGA_EXCEPTION if an internal exception occurred while creating the handle. FPGA_NO_DRIVER if the driver is not loaded. FPGA_BUSY if trying to open a resource that has already been opened in exclusive mode. FPGA_NO_ACCESS if the current process’ privileges are not sufficient to open the resource.
- Parameters
token
: Pointer to token identifying resource to acquire ownership ofhandle
: Pointer to preallocated memory to place a handle in. This handle will be used in subsequent API calls.flags
: One of the following flags:- FPGA_OPEN_SHARED allows the resource to be opened multiple times (not supported in ASE)
-
fpga_result
fpgaClose
(fpga_handle handle)¶ Close a previously opened FPGA object
Relinquishes ownership of a previously fpgaOpen()ed resource. This enables others to acquire ownership if the resource was opened exclusively. Also deallocates / unmaps MMIO and UMsg memory areas.
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if handle does not refer to an acquired resource, or if handle is NULL. FPGA_EXCEPTION if an internal error occurred while accessing the handle.
- Parameters
handle
: Handle to previously opened FPGA object
-
fpga_result
fpgaReset
(fpga_handle handle)¶ Reset an FPGA object
Performs an accelerator reset.
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if handle does not refer to an acquired resource or to a resoure that cannot be reset. FPGA_EXCEPTION if an internal error occurred while trying to access the handle or resetting the resource.
- Parameters
handle
: Handle to previously opened FPGA object
Event API¶
The event API provides functions and types for handling asynchronous events such as errors or AFC interrupts.
To natively support asynchronous event, the driver for the FPGA platform needs to support events natively (in which case the OPAE C library will register the event directly with the driver). For some platforms that do not support interrupt-driven event delivery, you need to run the FPGA Daemon (fpgad) to enable asynchronous OPAE events. fpgad will act as a proxy for the application and deliver asynchronous notifications for registered events.
event.h¶
Functions for registering events and managing the lifecycle for fpga_event_handle
s.
OPAE provides an interface to asynchronous events that can be generated by different FPGA resources. The event API provides functions to register for these events; associated with every event a process has registered for is an fpga_event_handle, which encapsulates the OS-specific data structure for event objects. On Linux, an fpga_event_handle can be used as a file descriptor and passed to select(), poll(), epoll() and similar functions to wait for asynchronous events.
Functions
-
fpga_result
fpgaCreateEventHandle
(fpga_event_handle *event_handle)¶ Initialize an event_handle
Platform independent way to initialize an event_handle used for notifications from the driver to application. For Linux, this function creates an eventfd and returns the eventfd file descriptor in
*event_handle
.- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if
event_handle
is NULL. FPGA_NOT_SUPPORTED if platform does not support events. - Parameters
event_handle
: Pointer to event handle variable.
-
fpga_result
fpgaDestroyEventHandle
(fpga_event_handle *event_handle)¶ Destroy an event_handle
Destroy handle and free resources. On Linux this corresponds to closing the file descriptor pointed to by handle
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if
event_handle
is NULL. - Parameters
event_handle
: Pointer to handle to be destroyed
-
fpga_result
fpgaRegisterEvent
(fpga_handle handle, fpga_event_type event_type, fpga_event_handle event_handle, uint32_t flags)¶ Register an FPGA event
This function tells the driver that the caller is interested in notification for the event specified by the type and flags pair.
The event_handle points to an OS specific mechanism for event notification. An event_handle is associated with only a single event.
- Note
- This function is currently not supported.
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if handle does not refer to a resource supporting the requested event, or if event_handle is not valid. FPGA_EXCEPTION if an internal exception occurred while accessing the handle or the event_handle. On Linux: FPGA_NO_DAEMON if the driver does not support the requested event and there is no FPGA Daemon (fpgad) running to proxy it.
- Parameters
handle
: Handle to previously opened FPGA resource.event_type
: Type of eventevent_handle
: Handle to previously opened resource for event notification.flags
: Optional argument for specifying additional information about event. For example irq number for interrupt events.
-
fpga_result
fpgaUnregisterEvent
(fpga_handle handle, fpga_event_type event_type)¶ Unregister an FPGA event
This function tells the driver that the caller is no longer interested in notification for the event associated with the event_handle
The event_handle points to an OS specific mechanism for event notification. An event_handle is associated with only a single event.
- Note
- This function is currently not supported.
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if handle does not refer to a resource supporting the requested event, or if event_handle is not valid. FPGA_EXCEPTION if an internal error occurred accessing the handle or the event_handle.
- Parameters
handle
: Handle to previously opened FPGA resource.event_type
: Type of previously registered event.
Management API¶
The management APIs define functions for reconfiguring an FPGA (writing new partial bitstreams) as well as assigning accelerators to host interfaces.
manage.h¶
Functions for managing FPGA configurations.
FPGA accelerators can be reprogrammed at run time by providing new partial bitstreams (“green bitstreams”). This file defines API functions for programming green bitstreams as well as for assigning accelerators to host interfaces for more complex deployment setups, such as virtualized systems.
Functions
-
fpga_result
fpgaAssignPortToInterface
(fpga_handle fpga, uint32_t interface_num, uint32_t slot_num, int flags)¶ Assign Port to a host interface.
This function assign Port to a host interface for subsequent use. Only Port that have been assigned to a host interface can be opened by fpgaOpen().
- Return
- FPGA_OK on success FPGA_INVALID_PARAM if input parameter combination is not valid. FPGA_EXCEPTION if an exception occcurred accessing the
fpga
handle. FPGA_NOT_SUPPORTED if driver does not support assignment. - Parameters
fpga
: Handle to an FPGA object previously opened that both the host interface and the slot belong tointerface_num
: Host interface numberslot_num
: Slot numberflags
: Flags (to be defined)
-
fpga_result
fpgaAssignToInterface
(fpga_handle fpga, fpga_token accelerator, uint32_t host_interface, int flags)¶ Assign an accelerator to a host interface
This function assigns an accelerator to a host interface for subsequent use. Only accelerators that have been assigned to a host interface can be opened by fpgaOpen().
- Note
- This function is currently not supported.
- Return
- FPGA_OK on success
- Parameters
fpga
: Handle to an FPGA object previously opened that both the host interface and the accelerator belong toaccelerator
: accelerator to assignhost_interface
: Host interface to assign accelerator toflags
: Flags (to be defined)
-
fpga_result
fpgaReleaseFromInterface
(fpga_handle fpga, fpga_token accelerator)¶ Unassign a previously assigned accelerator
This function removes the assignment of an accelerator to an host interface (e.g. to be later assigned to a different host interface). As a consequence, the accelerator referred to by token ‘accelerator’ will be reset during the course of this function.
- Note
- This function is currently not supported.
- Return
- FPGA_OK on success
- Parameters
fpga
: Handle to an FPGA object previously opened that both the host interface and the accelerator belong toaccelerator
: accelerator to unassign/release
-
fpga_result
fpgaReconfigureSlot
(fpga_handle fpga, uint32_t slot, const uint8_t *bitstream, size_t bitstream_len, int flags)¶ Reconfigure a slot
Sends a green bitstream file to an FPGA to reconfigure a specific slot. This call, if successful, will overwrite the currently programmed AFU in that slot with the AFU in the provided bitstream.
As part of the reconfiguration flow, all accelerators associated with this slot will be unassigned and reset.
- Return
- FPGA_OK on success. FPGA_INVALID_PARAM if the provided parameters are not valid. FPGA_EXCEPTION if an internal error occurred accessing the handle or while sending the bitstream data to the driver. FPGA_RECONF_ERROR on errors reported by the driver (such as CRC or protocol errors).
- Parameters
fpga
: Handle to an FPGA object previously openedslot
: Token identifying the slot to reconfigurebitstream
: Pointer to memory holding the bitstreambitstream_len
: Length of the bitstream in bytesflags
: Flags (to be defined)
Utilities¶
Functions for mapping fpga_result values to meaningful error strings are provided by the utilities API.
utils.h¶
Utility functions and macros for the FPGA API.
Functions
-
const char *
fpgaErrStr
(fpga_result e)¶ Return human-readable error message
Returns a pointer to a human-readable error message corresponding to the provided fpga_error error code.
- Return
- Pointer to a descriptive error message string
- Parameters
e
: Error code (as returned by another FPGA API function