Python API

Modules

accelize_drm

Accelize DRM Python Library

Copyright 2018 Accelize

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class accelize_drm.DrmManager

Manage Accelize DRM by handling communication with DRM controller IP and Accelize Web service.

The DrmManager require callback functions to access FPGA register.

Parameters
  • conf_file_path (path-like object) – Path to the DRM configuration JSON file.

  • cred_file_path (path-like object) – Path to the user Accelize credential JSON file.

  • read_register (function) – FPGA read register callback function. The function needs to return an int and accept following arguments: register_offset (int), returned_data (int). The function can’t be a non static method. register_offset is relative to first register of DRM controller This function must be thread-safe in case of concurrency on the register bus.

  • write_register (function) – FPGA write register callback function. The function needs to return an int and accept following arguments: register_offset (int), data_to_write (int). The function can’t be a non static method. register_offset is relative to first register of DRM controller This function must be thread-safe in case of concurrency on the register bus.

  • async_error (function) – Asynchronous error handling callback function. This function is called in case of asynchronous error during operation. The function needs to return None and accept following argument: error_message (bytes). The function can’t be a non static method. If not specified, use default callback that raises “accelize_drm.exceptions.DRMException” or its subclasses.

activate(self, bool resume_session_request=False)

Activate DRM session.

This function activate/unlocks the hardware by unlocking the protected IPs in the FPGA and opening a DRM session.

If a session is still pending the behavior depends on “resume_session_request” argument. If true the session is reused. Otherwise the session is closed and a new session is created.

This function will start a thread that keeps the hardware unlocked by automatically updating the license when necessary.

Any error during this thread execution will be reported asynchronously through the “async_error” function, if provided in constructor.

When this function returns and the license is valid, the protected IPs are guaranteed to be unlocked.

Parameters

resume_session_request (bool) – If True, the pending session is reused. If no pending session is found, create a new one. If False and a pending session is found, close it and create a new one. Default to False.

deactivate(self, bool pause_session_request=False)

Deactivate DRM session.

This function deactivates/locks the hardware back and close the session unless the “pause_session_request” argument is True. In this case, the session is kept opened for later use.

This function will join the thread keeping the hardware unlocked.

When the function returns, the hardware are guaranteed to be locked.

Parameters

pause_session_request (bool) – If True, the current session is kept open for later usage. Otherwise, the current session is closed. Default to False.

get(self, *keys)

Get information from the DRM system.

This function gives access to the internal parameter of the DRM system.

Parameters

keys (str) – Parameters names requested.

Returns

If multiple keys are specified, return a dict with

parameters names as keys else return a single value.

Return type

dict or object

set(self, **values)

Set information of the DRM system.

This function overwrites an internal parameter of the DRM system.

Parameters

values – Parameters to set as keyword arguments

accelize_drm.get_api_version()

Get version as named tuple containing :

  • C/C++ library version as major, minor, revision, prerelease, build.

  • Python library version as py_major, py_minor, py_revision, py_prerelease, py_build

  • C/C++ backend library name.

Returns

Containing following values: major, minor, revision, prerelease, build, version, py_major, py_minor, py_revision, py_prerelease, py_build, backend

Return type

namedtuple

accelize_drm.exceptions

DRM exceptions

exception accelize_drm.exceptions.DRMException

Accelize DRM Base exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMAssert

Assertion failed internally (Please contact Accelize)

error_code = 30002

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMBadArg

Bad argument provided

error_code = 1

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMBadFormat

Bad format of provided input or config file

error_code = 2

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMBadFrequency

DRM frequency defined in configuration script differs from real one detected automatically by the DRMLib

error_code = 5

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMBadUsage

Wrong usage of the DRMLib

error_code = 4

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMCtlrError

An error happened on a command on the DRM controller

error_code = 20001

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMDebug

Generated for debug and testing only

error_code = 40001

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMExternFail

Fail happened in an external library

error_code = 3

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMFatal

Fatal error, unknown error (Please contact Accelize)

error_code = 30001

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMWSError

Error returned from Accelize WebService

error_code = 10003

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMWSMayRetry

Error with request to Accelize Webservice, retry advised

error_code = 10004

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMWSReqError

Failed during HTTP request to Accelize WebService

error_code = 10002

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception accelize_drm.exceptions.DRMWSRespError

A malformed response has been received from Accelize WebService

error_code = 10001

Error code

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

accelize_drm.fpga_drivers

FPGA driver for Accelize DRM Python library

Supported driver:
AWS F1 instances types

Require libfpga_mgmt library from AWS FPGA SDK (https://github.com/aws/aws-fpga).

accelize_drm.fpga_drivers.get_driver(name)

Get a driver by name.

Parameters

name (str) – Driver name. Possible values: aws_f1 (AWS F1 instances types).

Returns

driver class.

Return type

FpgaDriverBase subclass

class accelize_drm.fpga_drivers.FpgaDriverBase(fpga_slot_id=0, fpga_image=None, drm_ctrl_base_addr=0)

Base class for FPGA driver to use with accelize_drm.DrmManager.

Parameters
  • fpga_slot_id (int) – FPGA slot ID.

  • fpga_image (str) – FPGA image to use to program FPGA.

  • drm_ctrl_base_addr (int) – DRM Controller base address.

property fpga_image

Programmed FPGA image.

Returns

FPGA image.

Return type

str

program_fpga(fpga_image=None)

Program FPGA with specified image.

Parameters

fpga_image (str) – FPGA image to program.

read_register(register_offset)

Read register.

This method is intended to be called directly, use “read_register_callback” to instantiate “accelize_drm.DrmManager”.

Parameters

register_offset (int) – Register offset.

Returns

32 bits register value.

Return type

int

property read_register_callback

Read register callback to pass to “accelize_drm.DrmManager”.

This method is not intended to be used directly, se “read_register” method for direct call.

Returns

Callback

Return type

function

write_register(register_offset, register_value)

Write register.

This method is intended to be called directly, use “write_register_callback” to instantiate “accelize_drm.DrmManager”.

Parameters
  • register_offset (int) – Register offset.

  • register_value (int) – 32 bits register value to write.

property write_register_callback

Write register callback to pass to “accelize_drm.DrmManager”.

This method is not intended to be used directly, se “write_register” method for direct call.

Returns

Callback

Return type

function

Cython headers

The Accelize DRM Python library provides following Cython headers (.pxd) to be used directly from Cython code.

  • accelize_drm.libaccelize_drm.pxd : Accelize DRM C++ library header.

  • accelize_drm.libaccelize_drmc.pxd : Accelize DRM C library header.