GPU Acceleration
In Fahrenheit: with the SDK switched to Fahrenheit (SetTemperatureUnit() and its counterparts, see Temperatures in Fahrenheit), every temperature on this page is read and written in Fahrenheit, and every difference in Fahrenheit degrees; the samples are unchanged.
Overview
The GPU pipeline backend offloads the thermal processing pipeline to the graphics processor using compute shaders. It is always built and always present: there is no build option and nothing to enable; what it accelerates is the frame processing path for larger frames, because its cost is mostly fixed per frame and so pays off once a frame is big enough to amortise it (see How the Pipeline Is Selected).
The GPU backend is held bit-exact to the CPU pipeline on the measurement path: the same Imager API, the same callbacks, the same frame types, the same temperatures. A noise filter is the exception: the GPU filters the energy field and the CPU filters the temperature field, so the same filter at the same strength gives slightly different numbers on the two; see Filters for the measured sizes. kGradient agrees exactly on both. Application code does not need to change when switching between backends. The SDK chooses a backend per camera while the camera opens, and can tell you afterwards which one it chose and why.
Do You Need a GPU?
No. The GPU backend is always present and there is nothing to enable, but a machine without a usable GPU is not a problem: the SDK decides per camera while it opens, and a camera with no usable adapter runs the CPU pipeline and reports the same temperatures.
A software-only adapter (lavapipe or llvmpipe on Linux, for instance) is deliberately not used. The SDK treats it as no GPU and runs the CPU pipeline, because a software adapter is slower than the CPU pipeline rather than faster.
Which GPU API the SDK asks for, per platform:
| Platform | GPU API |
|---|---|
| Linux | Vulkan |
| Windows | DirectX 12 |
macOS is not a platform the SDK ships for.
GPU Colorization
When false-colour output is requested (via SetBgraCallback()), the GPU backend applies the palette lookup, colorization and overlay compositing directly on the GPU. This avoids a CPU round-trip for visualization.
The GPU colorization supports all 17 built-in palettes (Palette::kIronBow through Palette::kLava) and uses the same colour settings as the CPU path (SetPalette(), SetColorRange(), SetAutoScaleMode()).
How the Pipeline Is Selected
The pipeline is chosen per camera while it opens. The rules are applied in order, and the first one that decides wins:
- Sample-point calibration. A camera whose calibration is sample-point runs on the CPU pipeline, because only the CPU pipeline implements it. This overrides everything below.
OTC_FORCE_CPU. If this environment variable is set, every camera in the process runs on the CPU pipeline.- An explicit request. No public API picks a backend by name, so a camera opened through the public API never reports
PipelineReason::kCallerPreference. - Measured camera/mode table. A small built-in table of camera modes where measurements showed the size rule gives the wrong answer (for example the PI 1M high-speed modes) picks the backend directly.
- Size rule. Frames below 65 536 pixels run on the CPU; frames at or above it, and frames whose size is not yet known, run on the GPU. The threshold can be changed with the
OTC_GPU_MIN_PIXELSenvironment variable. - GPU availability. If the GPU was chosen but no usable GPU exists (no adapter, only a software adapter, or a device that could not be created), the camera runs on the CPU pipeline.
The choice is made once during the open and may be corrected once more inside it: the first decision is taken on frame size before the calibration has been read, and is revisited if the calibration turns out to be sample-point. It is made per camera, so two cameras on one PC can run different pipelines; it is made from the mode the camera opens in, and a later operation-mode switch keeps it; and it is not load-based: nothing in it looks at how busy the GPU is or how many cameras it carries. It is not fixed for as long as the camera is open, though: see Automatic Fallback to CPU. Every decision is logged at info level with the reason, and the result can be read back once the open has returned:
- C++:
imager->Processing().Info()returns aPipelineInfowithkind(kCpu/kGpu),reason(aPipelineReason), a human-readableexplanation, the frame geometry and threshold the rule used, and the GPU adapter.optris::sdk::GetGpuInfo()reports the GPU the SDK would use, or why there is none, without a camera. - C:
optris_sdk_imager_get_pipeline_info()andoptris_sdk_get_gpu_info(). - .NET:
ThermalCamera.PipelineInfoandSdk.GpuInfo. - Python:
camera.pipeline_info. Rust:camera.pipeline_info().
Which features depend on the choice. None that a support query answers: every noise filter, detail enhancement (also in a picture the SDK colours itself with the colour output switched off), a region's own emissivity in the picture, and TemperatureAtEmissivity() work on both pipelines. What still differs: a noise filter's numbers at a temperature edge (see Filters), the region outlines, which the GPU pipeline draws into the delivered picture by default and the CPU pipeline only after SetOverlayCompositing(true), and direct GPU rendering (Display::GetGpuInstance(), ConfigureSurface()), which is a GPU performance path.
A simulated camera never runs the GPU pipeline; it goes through the same chooser a real camera does, but asks for the CPU backend by name. It does have a pipeline, and reports PipelineKind::kCpu. Playback has none and reports PipelineKind::kNone, and so does a camera below the pipeline's minimum frame size (8x8). valid == false means there was nothing to report at all: no camera attached, or a source the SDK cannot answer for.
Automatic Fallback to CPU
A GPU camera can end up on the CPU pipeline at two different points, and the availability check is only the first of them.
At selection. When the rules above pick the GPU, the SDK first checks that a usable GPU adapter and device can be created. If not, the camera is placed on the CPU pipeline with reason kGpuUnavailable. No error is raised, so an application built with GPU support works on machines without a GPU. GetGpuInfo().unavailable_reason says which failure it was.
At initialization. Passing the availability check proves only that an adapter and a device could be created. The GPU pipeline itself (its buffers, shaders, compute pipelines and bind groups for this camera's frame size) is built later, when the pipeline is initialized, and that can fail on a machine whose GPU passed the check. The pipeline is initialized when the camera connects, on every operation-mode switch, on a frame-format change, and when the backend is corrected during the open. If the GPU pipeline fails at any of those points, the SDK:
- replaces it with the CPU pipeline and initializes that to the current frame geometry, so the camera keeps producing pictures and temperatures (the two backends are bit-exact on the unfiltered measurement path, so the answer is the same, computed more slowly; if a noise filter is selected the numbers move slightly, see Filters);
- logs the swap at error level, naming the camera's serial number, where it happened (for example
connectoroperation-mode switch) and the reason the GPU pipeline gave; - reports
PipelineReason::kGpuInitFailedfromProcessing().Info()(C:optris_sdk_imager_get_pipeline_info(), .NET:ThermalCamera.PipelineInfo), with the GPU pipeline's own error inexplanation.
A GPU pipeline that never returns from its initialization is caught by the same arm. Initialization runs on its own thread with a bound: 15 000 ms by default, from the build, overridable per process with OTC_GPU_INIT_TIMEOUT_MS, and 0 to wait for ever. Past the bound the thread is abandoned rather than joined, the camera is moved to the CPU pipeline, and the explanation says how long it waited. The abandoned thread keeps its reference to the GPU backend, so nothing it is still inside the graphics driver with is freed underneath it, which means that backend is never released on a machine where the call really does hang.
The camera keeps every processing and picture setting across the move: the noise filter and its strength, the temporal smoothing, detail enhancement, the palette and colour range, a reference-body correction, and each region's own emissivity in the picture.
kGpuInitFailed is the one pipeline reason an application should treat as a fault: every other reason is the SDK working as designed, while this one is a machine that was expected to compute on its GPU and is not.
The application is told. Register a handler and the SDK calls it once per change, on the frame thread, before the first frame the new pipeline computed, with the pipeline before, the pipeline after and the reason: Processing().SetPipelineChangeCallback() in C++, optris_sdk_imager_set_pipeline_change_callback() in C, ThermalCamera.OnPipelineChanged() in .NET, camera.on_pipeline_change() in Python and camera.on_pipeline_change() in Rust. The choice made during the open is not a change and is not reported; read the pipeline information after the open for that.
API Transparency
There is no API difference between the GPU and CPU paths. The same Imager class, the same SetThermalCallback(), the same ThermalFrame, the same temperatures. Application code does not need to know which backend is processing frames.
To find out which backend a camera is on and why, read Processing().Info() as described in How the Pipeline Is Selected. The SDK does not measure per-frame processing latency: the C function optris_sdk_imager_get_processing_latency_us() always fails with OPTRIS_SDK_ERROR_NOT_SUPPORTED and the .NET ThermalCamera.ProcessingLatency property always throws FeatureNotSupportedException. If you need a latency figure, measure it in your application. FrameMetadata::timestamp_us will serve on Linux, where it is steady_clock microseconds since the host booted and so comparable with your own steady_clock reading when the frame arrives. On Windows the epoch is the capture stack's own, so treat only the differences between frames as meaningful there. Never subtract it from a wall clock on any platform; it is not a date.
GetDroppedFrameCount() does not distinguish the backends either: it counts frames discarded from the pull queue (AcquireFrame()) because the consumer did not keep up, and nothing else.
Example
This example works regardless of which backend the camera ends up on:
#include <iostream> #include <print> #include "optris/sdk.h" int main() { try { // Open the first camera -- the SDK chooses GPU or CPU while it opens. auto imager = optris::sdk::Imager::Create(); // Which pipeline, and why. Read it after Create() has returned. const auto info = imager->Processing().Info(); if (info.valid) { std::println("Pipeline: {} ({})", optris::sdk::ToString(info.kind), info.explanation); if (info.reason == optris::sdk::PipelineReason::kGpuInitFailed) { std::println(stderr, "Warning: the GPU pipeline failed to initialize; running on CPU."); } } // Told if the camera moves pipelines later -- a GPU pipeline that // fails at a mode switch moves it to the CPU, settings and all. imager->Processing().SetPipelineChangeCallback( [](const optris::sdk::PipelineChange& change) { std::println("Pipeline now {}: {}", optris::sdk::ToString(change.current), change.explanation); }); // Same callback regardless of backend. imager->SetThermalCallback([](const optris::sdk::ThermalFrame& f) { // Frames from before the startup calibration has finished // arrive too, and are not measurements. if (!f.GetMetadata().thermal_data_reliable) return; std::println("Frame: min={:.1f} max={:.1f}", f.GetMinTemperature(), f.GetMaxTemperature()); }); // False-colour output. On the GPU pipeline, colorization runs on the GPU. imager->SetPalette(optris::sdk::Palette::kIronBow); imager->SetBgraCallback([](const optris::sdk::BgraFrame& f) { // f.GetData() is BGRA8 pixel data ready for display. }); imager->Start(); std::println("Streaming. Press Enter to quit."); std::cin.get(); std::println("Frames dropped by the pull queue: {}", imager->GetDroppedFrameCount()); imager->Stop(); } catch (const optris::sdk::SdkException& e) { std::println(stderr, "Error: {}", e.what()); return 1; } }
optris_sdk_imager *camera = NULL; optris_sdk_pipeline_info info; uint64_t dropped = 0; /* Open the first camera -- the SDK chooses GPU or CPU while it opens. */ if (optris_sdk_imager_create(&camera) != OPTRIS_SDK_OK) { fprintf(stderr, "Error: %s\n", optris_sdk_last_error_message()); return 1; } /* Which pipeline, and why. Read it after the create has returned. */ optris_sdk_pipeline_info_init(&info, sizeof(info)); optris_sdk_imager_get_pipeline_info(camera, &info); printf("Pipeline: %s\n", info.reason_text); if (info.reason == OPTRIS_SDK_PIPELINE_REASON_GPU_INIT_FAILED) { fprintf(stderr, "Warning: the GPU pipeline failed to initialize; " "running on CPU.\n"); } /* Told if the camera moves pipelines later. */ optris_sdk_imager_set_pipeline_change_callback(camera, OnPipelineChange, NULL); /* Same callback regardless of backend; on the GPU pipeline the * colorization runs on the GPU too. */ optris_sdk_imager_set_thermal_callback(camera, OnThermal, NULL); optris_sdk_imager_set_palette(camera, OPTRIS_SDK_PALETTE_IRON_BOW); optris_sdk_imager_set_bgra_callback(camera, OnBgra, NULL); optris_sdk_imager_start(camera); getchar(); /* stream until Enter is pressed */ optris_sdk_imager_get_dropped_frame_count(camera, &dropped); printf("Frames dropped by the pull queue: %llu\n", (unsigned long long)dropped); optris_sdk_imager_stop(camera); optris_sdk_imager_destroy(camera);
using Optris.Sdk; // Open the first camera -- the SDK chooses GPU or CPU while it opens. await using ThermalCamera camera = ThermalCamera.Open(); // Which pipeline, and why. Read it after Open() has returned. PipelineInfo info = camera.PipelineInfo; Console.WriteLine($"Pipeline: {info.Pipeline} ({info.ReasonText})"); if (info.Reason == PipelineReason.GpuInitFailed) { Console.Error.WriteLine( "Warning: the GPU pipeline failed to initialize; running on CPU."); } // Told if the camera moves pipelines later. camera.OnPipelineChanged(change => Console.WriteLine($"Pipeline now {change.Current}: {change.ReasonText}")); // Same picture path regardless of backend. On the GPU pipeline the // colorization runs on the GPU. camera.Palette = Palette.IronBow; camera.OnColorImage(image => { /* BGRA8, ready for display */ }); camera.Start(); for (int i = 0; i < 100; i++) { using ThermalFrame frame = await camera.AcquireFrameAsync(TimeSpan.FromSeconds(2)); // Frames from before the startup calibration has finished // arrive too, and are not measurements. if (frame.Metadata.IsThermalDataReliable) { Console.WriteLine( $"Frame: min={frame.MinTemperature:F1} max={frame.MaxTemperature:F1}"); } } Console.WriteLine( $"Frames dropped by the pull queue: {camera.DroppedFrameCount}"); camera.Stop();
import optris_sdk # Open the first camera -- the SDK chooses GPU or CPU while it opens. camera = optris_sdk.Camera.open() # Which pipeline, and why. Read it after open() has returned. info = camera.pipeline_info print(f"Pipeline: {info.reason_text}") if info.reason == optris_sdk.PIPELINE_REASON_GPU_INIT_FAILED: print('Warning: the GPU pipeline failed to initialize; ' 'running on CPU.') # Told if the camera moves pipelines later. camera.on_pipeline_change( lambda change: print(f"Pipeline now {change.reason_text}")) # Same picture path regardless of backend. On the GPU pipeline the # colorization runs on the GPU. camera.palette = optris_sdk.PALETTE_IRON_BOW camera.on_bgra_frame(lambda image: None) # BGRA8, ready for display camera.start() for frame in camera.frames(100): # Frames from before the startup calibration has finished # arrive too, and are not measurements. if frame.thermal_data_reliable: print(f"Frame: min={frame.min_c:.1f} max={frame.max_c:.1f}") print(f"Frames dropped by the pull queue: {camera.dropped_frame_count}") camera.stop() camera.close()
use optris_sdk::{Camera, Palette, PipelineReason}; fn main() -> optris_sdk::Result<()> { // Open the first camera -- the SDK chooses GPU or CPU while it // opens. let mut camera = Camera::open()?; // Which pipeline, and why. Read it after open() has returned. let info = camera.pipeline_info()?; println!("Pipeline: {:?} ({})", info.kind, info.reason_text); if info.reason == PipelineReason::GpuInitFailed { eprintln!( "Warning: the GPU pipeline failed to initialize; \ running on CPU." ); } // Told if the camera moves pipelines later. camera.on_pipeline_change(|change| { println!("Pipeline now {:?}: {}", change.current, change.reason_text); })?; // Same callback regardless of backend; on the GPU pipeline the // colorization runs on the GPU too. camera.on_thermal_frame(|frame| { // Frames from before the startup calibration has finished // arrive too, and are not measurements. if let Ok(info) = frame.info() { if info.thermal_data_reliable { println!("Frame: min={:.1} max={:.1}", info.min_temp_c, info.max_temp_c); } } })?; camera.set_palette(Palette::IronBow)?; camera.on_bgra_image(|_image| { /* BGRA8, ready for display */ })?; camera.start()?; std::thread::sleep(std::time::Duration::from_secs(5)); println!("Frames dropped by the pull queue: {}", camera.dropped_frame_count()?); camera.stop()?; Ok(()) }
To force the CPU pipeline while developing, set OTC_FORCE_CPU=1 in the environment; Processing().Info().reason then reports kForcedCpuEnv.