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

Was this helpful?

  1. 4. Example Codes

4-1. CUDA

This is a sample code which retrieves CUDA device information and prints the specifications of the GPU devices you will be using.

#include <cuda_runtime_api.h>
#include <iostream>

int main() {
    int deviceCount = 0;
    cudaError_t error = cudaGetDeviceCount(&deviceCount);
    
    if (error != cudaSuccess) {
        std::cerr << "Error getting device count: " << cudaGetErrorString(error) << std::endl;
        return -1;
    }
    
    std::cout << "Found " << deviceCount << " CUDA capable device(s)" << std::endl;
    
    for (int i = 0; i < deviceCount; i++) {
        cudaDeviceProp deviceProp;
        cudaGetDeviceProperties(&deviceProp, i);
        
        std::cout << "\nDevice " << i << ": \"" << deviceProp.name << "\"" << std::endl;
        std::cout << "  CUDA Capability Major/Minor version: " << deviceProp.major << "." << deviceProp.minor << std::endl;
        std::cout << "  Total Global Memory: " << deviceProp.totalGlobalMem / (1024 * 1024) << " MB" << std::endl;
        std::cout << "  GPU Clock rate: " << deviceProp.clockRate * 1e-3f << " MHz" << std::endl;
        std::cout << "  Memory Clock rate: " << deviceProp.memoryClockRate * 1e-3f << " MHz" << std::endl;
        std::cout << "  Memory Bus Width: " << deviceProp.memoryBusWidth << " bits" << std::endl;
        std::cout << "  L2 Cache Size: " << deviceProp.l2CacheSize / 1024 << " KB" << std::endl;
        std::cout << "  Max Threads per Block: " << deviceProp.maxThreadsPerBlock << std::endl;
        std::cout << "  Multiprocessor Count: " << deviceProp.multiProcessorCount << std::endl;
        std::cout << "  Max Threads per Multiprocessor: " << deviceProp.maxThreadsPerMultiProcessor << std::endl;
        std::cout << "  Max Grid Size: " << deviceProp.maxGridSize[0] << " x " 
                  << deviceProp.maxGridSize[1] << " x " << deviceProp.maxGridSize[2] << std::endl;
    }
    
    return 0;
}
Previous4. Example CodesNext4-2. HEaaN End to End Example

Last updated 7 days ago

Was this helpful?