GPU Developer's Guide
  • 1. Introduction
  • 2. GPU Execution Architecture in CODE.HEAAN
  • 3. Start a new project with HEaaN
    • 3-1. Create Project Directory
    • 3-2. Set up Basic Directory Structure
    • 3-3. CMake Configuration
    • 3-4. Build and Compile
    • 3-5. Run (gpu-run)
    • 3-6. Check the results
    • Additional tips
  • 4. Example Codes
    • 4-1. CUDA
    • 4-2. HEaaN End to End Example
  • HEaaN GPU Guideline
    • HEaaN GPU Component Overview
    • CudaTools
    • Device Class
    • HEaaN GPU API in use
  • Not supported features
Powered by GitBook

Copyright©️ 2025 CryptoLab, Inc. All rights reserved.

On this page
  • 2.1 Basic Information
  • 2.2 API Reference
  • 2.2.2 Device Information Retrieval
  • 2.2.3 Device Comparison
  • 2.3 Utility Functions
  • 2.4 ScopedCudaDeviceSelector

Was this helpful?

  1. HEaaN GPU Guideline

Device Class

2.1 Basic Information

  • Class: HEaaN::Device

  • Purpose: Unified management of CPU and GPU devices

2.2 API Reference

2.2.1 Constructors

Device(DeviceType type)
Device(DeviceType type, int device_id)
  • Function: Creates a device object

  • Usage Example:

//Create CPU device (uses CPU device)
Device cpu_device(DeviceType::CPU);

// Create GPU device (uses currently active GPU)
Device gpu_device(DeviceType::GPU);

//Create specific GPU device
Device sepcific_gpu(DeviceType::GPU, 1); // Use GPU 1

device_id is only allowed to use 0.

2.2.2 Device Information Retrieval

DeviceType type() const
int id() const
  • Function: Retrieves device type and ID

  • Usage Example:

Device device(DeviceType::GPU);
if(device.type() == DeviceType::GPU) {
    int gpuId = device.id();
}

2.2.3 Device Comparison

bool operator==(const Device &other) const
bool operator!=(const Device &other) const
bool operator<(const Device &other) const
  • Function: Device object comparison

  • Usage Example:

Device device1(DeviceType::GPU, 0);
Device device2(DeviceType::GPU, 1);
if(device1 != device2) {
    // Different devices
}

2.3 Utility Functions

2.3.1 Default Device

Device getDefaultDevice()
  • Function: Returns the default CPU device.

  • Return Value: Device object of CPU type

2.3.2 CUDA Device Management

Device getCurrentCudaDevice()
void setCurrentCudaDevice(int device_id)
  • Functions: Retrieves and sets the current CUDA device

  • Usage Example:

HEaaN::setCurrentCudaDevice(0);
Device currentDevice = HEaaN::getCurrentDevice();

2.4 ScopedCudaDeviceSelector

This class is used when allocating memory for different devices in a multi-GPU environment.

Within a specific scope, it stores the previous device, sets a new device, and then reverts back to the previous device when exiting that scope.

PreviousCudaToolsNextHEaaN GPU API in use

Last updated 7 days ago

Was this helpful?