6. GPU accelerating#
ImageSDK supports CUDA with NVIDIA GPUs. The example below demonstrates how to enable GPU acceleration.
#include "P1Image.hpp"
#include <iostream>
using namespace P1::ImageSdk;
int main()
{
try
{
// Enable Cuda
SetArchitecture(Cuda);
// 1. Load IIQ image
RawImage im("Sample.IIQ");
// 2. Check GPU [optional]
{
if (GetArchitecture() != Architecture::Cuda)
{
std::cerr << "Unexpected error\n";
}
std::cout << "ImageSdk is using: " << GetDeviceName(0) << std::endl;
}
// 3. Convert
ConvertConfig config;
BitmapImage bmp = im.Convert(config);
// 4. Export to JPEG
TiffWriter("out.tiff", bmp, im, TiffConfig());
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what();
return -1;
}
}
using P1.ImageSdk;
// Enable GPU acceleration
Sdk.SetArchitecture(Sdk.Architecture.Cuda);
// 1. Load IIQ image
RawImage im = new("Sample.IIQ");
// 2. Check GPU [optional]
{
if(Sdk.GetArchitecture() != Sdk.Architecture.Cuda)
{
Console.WriteLine("Unexpected error");
}
Console.WriteLine($"ImageSDK is using {Sdk.GetDeviceName(0)}");
}
// 3. Convert
ConvertConfig config = new();
IBitmapImage bmp = im.Convert(config);
// 4. Export to Tiff
im.WriteAsTiff("out.tiff", bmp, new TiffConfig());
Note
ImageSDK automatically enables GPU acceleration if a compatible GPU is detected.