HIPIFY

repository·amd-develop·Indexed 20 days ago

https://github.com/rocm/hipify

A suite of tools for the automatic translation of CUDA source code into portable HIP C++, facilitating migration to the ROCm ecosystem. It includes hipify-clang for API translation and documentation generation, hipify-perl for conversion, and various utility scripts for locating CUDA/HIP source and header files, performing in-place conversions, and generating conversion statistics.

Tokens
171.4K
Snippets
266
Records
362
Agent score
70%

What's inside rocm-hipify

  1. Overview of HIPIFY tools

    amd-develop

    HIPIFY is a ROCm toolset designed to automate the translation of NVIDIA CUDA source code into portable HIP C++ for use on AMD GPUs. It provides two primary tools depending on the complexity of the translation required:

    • hipify-clang: A robust, clang-based tool that parses CUDA code to handle syntax changes, API calls, and kernel launch differences. It provides higher fidelity through code parsing.
    • hipify-perl: A simpler tool that uses text replacement to swap CUDA API calls with HIP equivalents. It is suitable for basic translation needs but offers less error detection than the clang-based version.

    Note on hipify_torch: For PyTorch-specific requirements, hipify_torch is a related independent utility developed for translating CUDA code into portable HIP C++.

  2. Limitations and manual steps in CUDA to HIP migration

    amd-develop

    While HIPIFY automates many aspects of migration, it is not a seamless 1:1 replacement.

    What is automatically converted:

    • CUDA runtime API calls
    • Kernel launch syntax
    • Standard CUDA library functions (where a HIP equivalent exists)
    • Specific keywords like __global__ and __device__

    What requires manual intervention:

    • Unsupported Libraries: CUDA libraries or third-party libraries without HIP equivalents cannot be automatically translated.
    • Performance Optimization: Code optimized specifically for NVIDIA GPUs may require manual rework to achieve optimal performance on AMD GPUs.

    Recommended Post-Migration Workflow:

    1. Code Review: Verify functional correctness of the translated code.
    2. Library Replacement: Replace any unsupported libraries or constructs with HIP or ROCm features.
    3. Debug and Test: Run the new HIP program to ensure it behaves as expected.
    4. Optimize: Perform performance tuning specifically for the target AMD hardware.
  3. Understand the CUDNN API support status indicators in MIOpen

    amd-develop

    When reviewing the tables of CUDNN APIs supported by MIOpen, specific single-letter codes are used to indicate the status and compatibility of each API. Use these markers to determine if an API is safe to use, if it has changed, or if it is unsupported in your current environment:

    • A: Added
    • D: Deprecated
    • C: Changed
    • R: Removed
    • U: Unsupported for specific CUDA version(s)
    • E: Experimental
  4. Understand CUBLAS to hipBLAS API mapping

    amd-develop

    When hipifying CUDA code that uses the cuBLAS library, many constants, types, and enums are mapped to their hipBLAS equivalents. Use the following legend to interpret the support tables:

    • A: Added
    • D: Deprecated
    • C: Changed
    • R: Removed
    • U: Unsupported for specific CUDA version(s)
    • E: Experimental

    For example, CUBLAS_STATUS_SUCCESS maps to HIPBLAS_STATUS_SUCCESS (Added in HIP 1.8.2).

  5. Understand CUSOLVER API support in ROCm

    amd-develop

    When hipifying CUDA code, you can use this reference to check which CUSOLVER data types and functions have corresponding support in ROCm (rocSOLVER/rocBLAS).

    Key for support status columns:

    • A: Added
    • D: Deprecated
    • C: Changed
    • R: Removed
    • U: Unsupported for specific CUDA versions
    • E: Experimental

    If a CUDA type or function is listed with a ROCm equivalent, the table provides the corresponding ROCm token and the version in which it was introduced.

  6. Map CUDA Driver API Data Types to HIP

    amd-develop

    When hipifying CUDA Driver API code, many CUDA data types and enums have direct equivalents in HIP. This mapping is essential for ensuring compatibility when porting low-level driver calls.

    Common mappings include:

    • Graph API: CUgraph_st maps to ihipGraph, CUgraphNode to hipGraphNode_t, and CUgraphNodeType to hipGraphNodeType.
    • Memory Management: CUmemAllocationProp maps to hipMemAllocationProp, CUmemPoolProps to hipMemPoolProps, and CUmem_advise to hipMemoryAdvise.
    • Kernel & Launch: CUkernel maps to hipKernel_t and CUlaunchConfig maps to HIP_LAUNCH_CONFIG.
    • Modules & Libraries: CUmodule maps to hipModule_t and CUlibrary maps to hipLibrary_t.
    • Error Handling: CUresult maps to hipError_t.
  7. Understand CUBLAS API support mapping for HIP and ROCm

    amd-develop

    When hipifying CUDA code, you can use this reference to map cuBLAS types and constants to their hipBLAS (HIP) or rocBLAS (ROCm) equivalents.

    Mapping Legend:

    • A: Added
    • D: Deprecated
    • C: Changed
    • R: Removed
    • U: Unsupported for specific CUDA versions
    • E: Experimental

    This table helps identify which CUDA features have direct equivalents in the HIP and ROCm ecosystems and which versions of the libraries introduced them.