ROC SDK  2.4.0
Scalable Face Recognition Software
Typedefs | Enumerations | Functions
Initialization

Initializing the SDK. More...

Typedefs

typedef enum roc_license_term roc_license_term
 Optional license terms.
 
typedef void(* roc_progress) (float)
 Pointer to a callback function used to report progress on a long running task. More...
 

Enumerations

enum  roc_license_term {
  ROC_INITIALIZED, ROC_ANALYTICS_ONLY, ROC_EXPLORE, ROC_TATTOO_ENABLED,
  ROC_LIVENESS_ENABLED, ROC_ICAO_ENABLED, ROC_OCR_ENABLED, ROC_OBJECT_ENABLED,
  ROC_WATCH, ROC_GPU, ROC_UNLOCKED_FV, ROC_FACE_ENABLED,
  ROC_FINGERPRINT_ENABLED
}
 Optional license terms. More...
 

Functions

roc_error roc_initialize (const char *license_file, const char *log_file)
 Call once at the start of the application before making any other calls to the API. More...
 
roc_error roc_set_keylok_keys (int validateCode1, int validateCode2, int validateCode3, int clientIDCode1, int clientIDCode2, int readCode3)
 Set Keylok device specific keys. More...
 
roc_error roc_set_floating_license_server (const char *hostname)
 Set floating license server IP address. More...
 
roc_error roc_set_cuda_benchmarking (bool benchmark, bool clear_cache)
 Control CUDA benchmarking. More...
 
roc_error roc_set_cuda_device (int device)
 Control which GPU to use. More...
 
roc_error roc_enable_cuda (bool enabled, roc_progress progress)
 Enabled/disable CUDA acceleration. More...
 
roc_error roc_get_cuda_utilization (float *gpu_utilization_percentage, float *memory_utilization_percentage)
 Retrieve performance characteristics for a GPU. More...
 
roc_error roc_set_opportunistic_batching (int ideal_batch_size, int maximum_latency)
 Control batch processing across threads. More...
 
roc_error roc_enable_snpe (bool enabled, roc_string snpe_model_path)
 Enable/disable Qualcomm Snapdragon chipset acceleration. More...
 
roc_error roc_cuda_device_count (unsigned int *device_count)
 Wraps nvmlDeviceGetCount. More...
 
roc_error roc_cuda_utilization (unsigned int index, unsigned int *gpu, unsigned int *memory)
 Wraps nvmlDeviceGetUtilizationRates. More...
 
roc_error roc_finalize ()
 Call once at the end of the application after making all other calls to the API. More...
 
roc_error roc_get_hostname (roc_string *hostname)
 Retrieve the hostname of the current machine. More...
 
roc_error roc_get_host_id_extended (roc_string *host_id)
 Obtain more complete information about the host system. More...
 
roc_error roc_get_application_certificate (roc_string *app_cert)
 Retrieve the Application Certificate of the current process. More...
 
roc_error roc_get_license_term (roc_license_term license_term, bool *enabled)
 Check if a license term is enabled. More...
 
roc_error roc_get_thread_limit (int *limit)
 Get the thread count limit. More...
 
roc_error roc_set_thread_limit (int limit)
 Set the thread count limit. More...
 
roc_error roc_get_floating_license_limit (uint32_t *clients_remaining, uint64_t *comparisons_remaining)
 Query the floating license server for limits. More...
 
roc_error roc_get_floating_license_status (bool *is_connected)
 Check the status of the floating license connection. More...
 
roc_error roc_set_icao_background_color (uint8_t r, uint8_t g, uint8_t b)
 Assign the color used by ROC_ICAO_BACKGROUND for thumbnail generation. More...
 
roc_error roc_get_host_id (roc_string *host_id)
 Retrieve the Host ID of the current machine. More...
 
roc_error roc_is_hardware_compatible ()
 Compare the system hardware against the SDK requirements. More...
 

Detailed Description

Initializing the SDK.

A ROC application begins with a call to roc_initialize, and ends with a call to roc_finalize. For license management see roc_get_host_id.

Typedef Documentation

◆ roc_progress

typedef void(* roc_progress) (float)

Pointer to a callback function used to report progress on a long running task.

The function should return void and take one float parameter which will range from 0.0 to 100.0 indicating the percent completed.

Any function taking a roc_progress parameter will accept a NULL value indicating not to report progress.

Example
void print_progress(float percent_completed)
{
printf("%.1f percent complete!\n", percent_completed);
}
...
roc_gallery_file gallery_file = ...;
roc_gallery gallery;
roc_open_gallery(gallery_file, &gallery, &print_progress);
// `roc_open_gallery()` will periodically call `print_progress()` with the
// percent completed.

Enumeration Type Documentation

◆ roc_license_term

Optional license terms.

Enumerator
ROC_INITIALIZED 

True if roc_initialize has been called successfully.

ROC_ANALYTICS_ONLY 

A license that disables feature vector construction.

ROC_EXPLORE 

A license that enables the Explore GUI.

ROC_TATTOO_ENABLED 

A license that enables ROC_TATTOO_REPRESENTATION.

ROC_LIVENESS_ENABLED 

A license that allows ROC_SPOOF.

ROC_ICAO_ENABLED 

A license that allows ROC_ICAO_METRICS.

ROC_OCR_ENABLED 

A license that allows ROC_TEXT_DETECTION and ROC_TEXT_REPRESENTATION.

ROC_OBJECT_ENABLED 

A license that allows ROC_ALL_OBJECT_DETECTION.

ROC_WATCH 

A license that enables the Watch VMS system.

ROC_GPU 

A license that allows roc_enable_cuda.

ROC_UNLOCKED_FV 

A license that allows unlocked feature vectors.

For licenses that allow it, the unlocked feature vector can be obtained by calling roc_get_metadata with key UnlockedFV, whose value is a space-separated list of real valued numbers for a high dimensional vector that can be compared in a Euclidean space.

ROC_FACE_ENABLED 

A license that allows ROC_STANDARD_DETECTION, ROC_FRONTAL_DETECTION, ROC_FAST_REPRESENTATION, ROC_STANDARD_REPRESENTATION and ROC_DEEP_REPRESENTATION.

ROC_FINGERPRINT_ENABLED 

A license that allows ROC_FINGERPRINT_REPRESENTATION.

Function Documentation

◆ roc_initialize()

roc_error roc_initialize ( const char *  license_file,
const char *  log_file 
)

Call once at the start of the application before making any other calls to the API.

When using the Android SDK call roc_preinitialize_android first.

License File

The license_file is the path to ROC.lic or the contents thereof.

Note
If license_file ends with .lic then it is treated as a file path, otherwise it is treated as the file contents.

If license_file is NULL (as is the case for the Command Line Interface and Explore), this function will use the value from the ROC_LIC environment variable if it exists. Otherwise it will check for ../ROC.lic first relative to the current working directory, and second relative to the application binary directory (not always possible to determine). It is permissible for ROC.lic to be read-only. See roc_get_host_id for details on obtaining ROC.lic.

Usage Logging

For certain applications the ROC SDK is licensed on a per-function-call basis. In these cases the ROC.lic license file will contain a logging requirement and log_file should be provided, otherwise log_file may be NULL.

log_file is a file path to which the ROC SDK will write encrypted usage statistics. By convention, log_file is named ROC.log. If log_file does not exist then it will be created, otherwise it will be appended to. To satisfy licensing requirements log_file should be periodically sent to Rank One Computing, and may then be deleted locally (when the application is not running). log_file contains no sensitive information, just simple usage statistics.

If log_file is NULL, but the license requires logging, this function will use the value from the ROC_LOG environment variable if it exists, otherwise this function will return an error.

The Command Line Interface uses the ROC_LOG idiom. The contents of log_file can be printed using roc-log.

Note
If multiple concurrent processes are using the ROC SDK, each must specify its own log file.

Process Locking

Most licenses impose a limit on the number of threads across all running processes that can use the ROC SDK simultaneously. If you recieve the error QSystemSemaphore::handle: permission denied please ensure the TMPDIR environment variable is set to a folder for which you have read+write permission.

Example
const char *license_file = ...;
roc_initialize(license_file, NULL);
Parameters
[in]license_fileSee License File.
[in]log_fileFile path to write usage statistics to, or NULL if Usage Logging is not required.
Remarks
This function is thread-unsafe and must only be called once.
See also
roc_finalize

◆ roc_set_keylok_keys()

roc_error roc_set_keylok_keys ( int  validateCode1,
int  validateCode2,
int  validateCode3,
int  clientIDCode1,
int  clientIDCode2,
int  readCode3 
)

Set Keylok device specific keys.

All codes will be contained within the Client.h file provided by Keylok.

Parameters
[in]validateCode1ValidateCode1.
[in]validateCode2ValidateCode2.
[in]validateCode3ValidateCode3.
[in]clientIDCode1ClientIDCode1.
[in]clientIDCode2ClientIDCode2.
[in]readCode3ReadCode3.
Remarks
This function must be called before roc_initialize if using a Keylok dongle.

◆ roc_set_floating_license_server()

roc_error roc_set_floating_license_server ( const char *  hostname)

Set floating license server IP address.

In the typical case, the floating license server IP address is hard-coded in the client license file. However, if it is not specified then it must be set by calling this function before calling roc_initialize.

Example
Parameters
[in]hostnameHostname or IP address of the floating license server.
Remarks
This function is thread-unsafe and must only be called once.

◆ roc_set_cuda_benchmarking()

roc_error roc_set_cuda_benchmarking ( bool  benchmark,
bool  clear_cache 
)

Control CUDA benchmarking.

On load the first time, this function will benchmark and cache execution paths to select the fastest for the particular GPU model. In the unusual case that abnormal results are being observed, you can disable or reset benchmarking by calling this function.

This function should be called before roc_enable_cuda.

Parameters
[in]benchmarkEnable/disable CUDA kernel benchmarking, default is true.
[in]clear_cacheClear kernel benchmarking cache, default is false.
Remarks
This function is thread-safe.

◆ roc_set_cuda_device()

roc_error roc_set_cuda_device ( int  device)

Control which GPU to use.

This function corresponds to the cudaSetDevice API call.

This function should be called before roc_enable_cuda.

Parameters
[in]deviceGPU index, default is 0 (the fastest device on the system).
Remarks
This function should only be called once, at application start, as it is not thread-safe.

◆ roc_enable_cuda()

roc_error roc_enable_cuda ( bool  enabled,
roc_progress  progress 
)

Enabled/disable CUDA acceleration.

By default CUDA acceleration is disabled. Call this function after calling roc_initialize. If you choose to enable CUDA, we advise disabling it at the end of the application, before calling roc_finalize, to cleanly deallocate GPU resources.

CUDA Supported Platforms

Ubuntu 18.04 x64 with CUDA 11.1 and cuDNN 8.1.1

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.1.1/local_installers/cuda-repo-ubuntu1804-11-1-local_11.1.1-455.32.00-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-11-1-local_11.1.1-455.32.00-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu1804-11-1-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
wget https://rankone.s3.amazonaws.com/share/libcudnn8_8.1.1.33-1%2Bcuda11.2_amd64.deb
sudo dpkg -i libcudnn8_8.1.1.33-1+cuda11.2_amd64.deb
rm libcudnn8_8.1.1.33-1+cuda11.2_amd64.deb
wget https://rankone.s3.amazonaws.com/share/libcudnn8-dev_8.1.1.33-1%2Bcuda11.2_amd64.deb
sudo dpkg -i libcudnn8-dev_8.1.1.33-1+cuda11.2_amd64.deb
rm libcudnn8-dev_8.1.1.33-1+cuda11.2_amd64.deb

Windows Server 2016 with CUDA 11.4 and cuDNN 8.5.0

  1. Download and install CUDA
  2. Download and unzip cuDNN, then copy the "bin", "lib" and "include" folders to "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\"

NVIDIA Jetson with CUDA 10.2 and cuDNN 8.2.2

  1. Flash your device with JetPack 4.6.
Example
roc_enable_cuda(true, NULL);
Parameters
[in]enabledEnable/disable CUDA acceleration.
[in]progressOptional progress callback or NULL.
Remarks
This function is thread-unsafe.
See also
roc_set_opportunistic_batching roc_set_cuda_benchmarking roc_set_cuda_device

◆ roc_get_cuda_utilization()

roc_error roc_get_cuda_utilization ( float *  gpu_utilization_percentage,
float *  memory_utilization_percentage 
)

Retrieve performance characteristics for a GPU.

This function can only be called after both roc_enable_cuda and roc_set_cuda_device. gpu_utilization_percentage is determined from a sample period that may be between 1 second and 1/6 second, depending on the GPU being queried.

Parameters
[in]gpu_utilization_percentagePercent of time over the past sample period during which one or more kernels was executing on the GPU.
[in]memory_utilization_percentagePercent of device memory in use.
Remarks
This function is thread-unsafe.
See also
roc_enable_cuda

◆ roc_set_opportunistic_batching()

roc_error roc_set_opportunistic_batching ( int  ideal_batch_size,
int  maximum_latency 
)

Control batch processing across threads.

By default ideal_batch_size equals 1 and threads calling roc_represent will process their data independently. However, there are certain circumstances where greater bandwidth can be achieved by syncing threads at the same stages in the computation. The primary case for this is when using CUDA with roc_enable_cuda, in which case batch sizes that are powers-of-two (up to 32 on current hardware) will result in increasingly greater overall bandwidth, at the expense of increasing latency. An ideal_batch_size of 8 works well for a variety of modern CUDA GPUs supporting tensor cores. When setting ideal_batch_size to a value greater than 1 it is critical to spawn extra threads to feed images to roc_represent, as many threads at any given moment will be waiting for their queued data to be processed by the batch execution engine. For a CPU with C cores we recommend using a thread pool with C + ideal_batch_size threads. Furthermore we recommend using ROC_SERIAL to limit parallelization to one thread per image. Threads will wait until either ideal_batch_size is reached or maximum_latency milliseconds has elapsed, whichever comes first.

Parameters
[in]ideal_batch_sizeControl the maximum batch size, default is 1 which means no batching takes place.
[in]maximum_latencyMaximum allowed latency in milliseconds when accumulating data across threads, default is 1000.
Remarks
This function is thread-safe.
See also
roc_enable_cuda

◆ roc_enable_snpe()

roc_error roc_enable_snpe ( bool  enabled,
roc_string  snpe_model_path 
)

Enable/disable Qualcomm Snapdragon chipset acceleration.

The ROC SDK supports hardware acceleration for ROC_DEEP_REPRESENTATION on Android and Linux Snapdragon chipset devices. By default, Snapdragon acceleration is disabled. Call this function after calling roc_initialize. If you choose to enable SNPE, we advise disabling it at the end of the application, before calling roc_finalize, to cleanly deallocate Snapdragon resources. In order to use Snapdragon acceleration, an "ff-deep.dlc" file (supplied by Rank One) must be placed in a readable location on your device. For example, the path, "/sdcard/roc/" would work well on a mobile Android device.

Example
roc_enable_snpe(true, "/sdcard/roc/"); // Initialize Snapdragon acceleration
... // process faces using Snapdragon acceleration
roc_enable_snpe(false, NULL); // Clean up Snapdragon resources
Parameters
[in]enabledEnable/disable Snapdragon acceleration.
[in]snpe_model_pathPath to Rank One-supplied .dlc file.
Remarks
This function is thread-unsafe.

◆ roc_cuda_device_count()

roc_error roc_cuda_device_count ( unsigned int *  device_count)

Wraps nvmlDeviceGetCount.

Note
This function can be called without calling roc_initialize() but requires linking directly to roc_cuda shared library.
Parameters
[out]device_countThe number of accessible devices.
Remarks
This function is thread-safe.

◆ roc_cuda_utilization()

roc_error roc_cuda_utilization ( unsigned int  index,
unsigned int *  gpu,
unsigned int *  memory 
)

Wraps nvmlDeviceGetUtilizationRates.

Note
This function can be called without calling roc_initialize() but requires linking directly to roc_cuda shared library.
Parameters
[in]indexThe index of the target GPU.
[out]gpuPercent of time over the past sample period during which one or more kernels was executing on the GPU.
[out]memoryPercent of time over the past sample period during which global (device) memory was being read or written.
Remarks
This function is thread-safe.

◆ roc_finalize()

roc_error roc_finalize ( )

Call once at the end of the application after making all other calls to the API.

This will free memory allocated during initialization. Calling roc_initialize after this function to re-initialize the SDK is not supported.

Example
Remarks
This function is thread-unsafe and must only be called once.
See also
roc_initialize

◆ roc_get_hostname()

roc_error roc_get_hostname ( roc_string hostname)

Retrieve the hostname of the current machine.

Example
roc_string hostname;
roc_get_hostname(&hostname);
Parameters
[out]hostnameThe hostname for the current machine.
Remarks
This function is reentrant.

◆ roc_get_host_id_extended()

roc_error roc_get_host_id_extended ( roc_string host_id)

Obtain more complete information about the host system.

This function extends roc_get_host_id with additional context. Free host_id after use with roc_free_string.

Parameters
[out]host_idOutput host information.
Remarks
This function is reentrant.
See also
roc_get_host_id

◆ roc_get_application_certificate()

roc_error roc_get_application_certificate ( roc_string app_cert)

Retrieve the Application Certificate of the current process.

Note
This function is only supported on Android.

Application Certificate

Every Android app is signed with a signing certificate. As an alternative way to check the signing certificate, click on the Gradle menu in Android Studio, expand the Tasks tree, and click on "android" then "signingReport". Look for SHA-256 hash of the corresponding build(s). See this Stack Overflow question for details.

Note
Android developers must call roc_preinitialize_android before calling this function.
Example
Parameters
[out]app_certThe signing certificate SHA-256 hash for the current application.
Remarks
This function is reentrant.

◆ roc_get_license_term()

roc_error roc_get_license_term ( roc_license_term  license_term,
bool *  enabled 
)

Check if a license term is enabled.

Example
bool analytics_only;
Parameters
[in]license_termThe term to query.
[out]enabledThe value for license_term.
Remarks
This function is thread-safe.

◆ roc_get_thread_limit()

roc_error roc_get_thread_limit ( int *  limit)

Get the thread count limit.

The thread count limit is the maximum number of concurrent calls that can be made to ROC SDK functions as specified by the threads value in the ROC.lic license file.

Example
int limit;
Parameters
[out]limitThe thread count limit.
Remarks
This function is thread-safe.
See also
Threads

◆ roc_set_thread_limit()

roc_error roc_set_thread_limit ( int  limit)

Set the thread count limit.

If limit is greater than the thread limit specified in the license file then it will be ignored.

Note
This function must be called before roc_initialize.
Parameters
[in]limitMaximum number threads to use.
Remarks
This function is thread-safe.
See also
Threads

◆ roc_get_floating_license_limit()

roc_error roc_get_floating_license_limit ( uint32_t *  clients_remaining,
uint64_t *  comparisons_remaining 
)

Query the floating license server for limits.

The value for clients_remaining is the instances specified in the client license file less the number of currently active clients (including the client making the request). The value for comparisons_remaining is the roc_comparison_limit reported by the server.

If the license file specified for roc_initialize is not floating then clients_remaining and comparisons_remaining will be set to zero and this function will return without error. If the license does not require Usage Logging then the value returned for comparisons_remaining should be ignored.

Example
uint32_t clients_remaining;
uint64_t comparisons_remaining;
roc_get_floating_license_limit(&clients_remaining, &comparisons_remaining);
Parameters
[out]clients_remainingNumber of client licenses available.
[out]comparisons_remainingNumber of comparisons remaining for licenses that require Usage Logging.
Remarks
This function is thread-safe.
See also
Floating License Server roc_get_floating_license_status

◆ roc_get_floating_license_status()

roc_error roc_get_floating_license_status ( bool *  is_connected)

Check the status of the floating license connection.

Parameters
[out]is_connectedtrue if the most recent attempt to connect to the license server was successful, false otherwise.
Remarks
This function is thread-safe.
See also
Floating License Server roc_get_floating_license_limit

◆ roc_set_icao_background_color()

roc_error roc_set_icao_background_color ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)

Assign the color used by ROC_ICAO_BACKGROUND for thumbnail generation.

The default color is white (255, 255, 255).

Parameters
[in]rRed (0-255).
[in]gGreen (0-255).
[in]bBlue (0-255).
Remarks
This function is thread-unsafe.

◆ roc_get_host_id()

roc_error roc_get_host_id ( roc_string host_id)

Retrieve the Host ID of the current machine.

Host ID

The Host ID is a null-terminated JSON string uniquely identifying the current machine.

Rank One uses the Host ID to generate the ROC.lic license file that should be copied to the ROC SDK root directory, overwriting the placeholder license file of the same name. See License Generation for details.

Free host_id after use with roc_free_string.

This function can be called before roc_initialize.

Note
Android developers must call roc_preinitialize_android before calling this function.
Example
roc_string host_id;
roc_get_host_id(&host_id);
Parameters
[out]host_idThe Host ID for the current machine.
Remarks
This function is thread-unsafe.
See also
roc_get_host_id_extended

◆ roc_is_hardware_compatible()

roc_error roc_is_hardware_compatible ( )

Compare the system hardware against the SDK requirements.

This function calls _cpuid to check the availble instruction sets of the CPU and compares them against the requirements of the ROC SDK. Returns NULL if the hardware matches the API.

Current checks:

  • x86_64 AVX2/FMA3