Inferensys

Glossary

Header Files

Header files are interface specification files, typically with a .h extension, that contain function prototypes, macro definitions, and type declarations for libraries or system calls.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
VENDOR SDK AND INTRINSIC MAPPING

What is a Header File?

A header file is a source code file, typically with a .h extension, that declares the public interface for a software library, module, or system component.

In C and C++, a header file contains function prototypes, macro definitions, type declarations, and constant definitions. It acts as a contract, informing the compiler about the names and signatures of functions and data structures available in a separate implementation file (a .c or .cpp file). This separation of interface from implementation is fundamental to modular programming, enabling code reuse and simplifying large-scale project management. When a source file includes a header via the #include preprocessor directive, the compiler's textual substitution merges the header's content, allowing it to perform type checking and generate correct object code.

Within the context of NPU acceleration and vendor SDKs, header files are critical for accessing hardware intrinsics and proprietary APIs. Vendor-specific headers (e.g., vendor_npu.h) define the data types, function prototypes, and macro constants needed to program the accelerator's low-level features, such as tensor cores or specialized memory operations. The compiler uses these declarations to validate calls to the vendor runtime library. Proper management of header file dependencies and inclusion paths is a core task in cross-compilation toolchains targeting specialized hardware.

VENDOR SDK AND INTRINSIC MAPPING

Key Components of a Header File

Header files define the interface between software and hardware, providing the compiler with essential declarations for functions, data types, and hardware-specific operations. In NPU programming, they are critical for accessing vendor SDKs and intrinsics.

01

Function Prototypes

A function prototype declares a function's name, return type, and parameter types without providing its implementation. This allows the compiler to perform type checking and generate correct calling code when the function is used in other source files. For NPU SDKs, prototypes define the entry points to vendor runtime libraries, driver APIs, and optimized kernel libraries.

  • Example: extern int npu_compute_tensor(const void* config, float* input, float* output);
  • Purpose: Informs the compiler that npu_compute_tensor exists and will be linked later, enabling separate compilation.
02

Macro Definitions

Macros are preprocessor directives (#define) that perform text substitution before compilation. They are used for constants, inline code snippets, and conditional compilation. In hardware programming, macros define:

  • Hardware Constants: Register addresses, buffer sizes, and status flags (e.g., #define NPU_REG_STATUS 0x1000).
  • Platform Abstraction: Conditional code for different NPU generations or operating systems using #ifdef.
  • Inline Operations: Simple, performance-critical operations mapped to vendor intrinsics.
03

Type Declarations & Data Structures

Header files define custom data types and structures that model the hardware's data layout and API contracts. This is essential for ensuring binary compatibility between the application and the vendor's Application Binary Interface (ABI).

  • Opaque Handles: Typedefs like typedef void* npu_device_handle_t hide implementation details.
  • Configuration Structs: Packed structures that mirror hardware descriptor formats for kernel launches or memory transfers.
  • Enumerations: Named constants for error codes, operation types, and hardware features (e.g., enum npu_data_format { FORMAT_FP16, FORMAT_INT8 };).
04

Hardware Intrinsic Declarations

Intrinsics are compiler-specific functions that map directly to single or a few low-level machine instructions. Header files provided by the vendor SDK declare intrinsics for accessing specialized NPU operations like tensor cores or SIMD units.

  • Function: Provide a C/C++ callable interface to Vendor ISA instructions without writing assembly.
  • Example: A function like __npu_tensor_multiply_add(...) might compile directly to a proprietary NPU instruction.
  • Benefit: Grants low-level performance control while maintaining portability across compiler versions.
05

Include Guards & Conditional Compilation

Include guards prevent a header file's contents from being included multiple times in a single translation unit, which would cause redefinition errors. Conditional compilation directives tailor the header for different environments.

  • Standard Guard: #ifndef NPU_KERNEL_H / #define NPU_KERNEL_H / #endif
  • Pragma Once: A non-standard but widely supported alternative: #pragma once.
  • Use Case: Guards are universal; conditional compilation (#ifdef TARGET_NPU_V2) selects between features for different hardware versions within the same header.
06

Extern "C" Linkage Specification

In C++, the extern "C" directive specifies that the declared functions should use C linkage and naming conventions. This is critical when header files wrap C-based vendor SDK libraries, ensuring the C++ compiler does not perform name mangling, which would break linking.

  • Syntax: extern "C" { #include "vendor_npu.h" } or wrapping declarations within extern "C" { ... }.
  • Purpose: Guarantees the linker can find the correctly named symbols in the vendor's pre-compiled static library or dynamic library.
COMPILATION FUNDAMENTALS

How Header Files Work in the Compilation Process

Header files are a foundational mechanism in C-based languages for separating interface declarations from implementation, enabling modular code organization and efficient compilation.

A header file is a source code file, conventionally with a .h extension, that contains declarations—such as function prototypes, macro definitions, type definitions (e.g., struct, typedef), and external variable declarations—which specify the public interface of a software module or library. Its primary role is to provide a contract to the compiler about what names, types, and functions exist elsewhere, allowing the compiler to perform type checking and syntax validation on code that uses those interfaces without needing the full implementation details. This separation of interface from implementation is the core of modular programming.

During the preprocessing phase, the #include directive performs a literal text substitution, copying the entire contents of the specified header file into the source .c file. The compiler then processes this combined text. To prevent multiple inclusion errors from duplicate declarations, header files use include guards (#ifndef, #define, #endif) or the #pragma once directive. For hardware acceleration, vendor SDKs provide specialized headers containing intrinsic function prototypes and data type definitions for the NPU's Instruction Set Architecture (ISA), allowing high-level code to map directly to low-level tensor operations.

NPU PROGRAMMING CONTEXT

Types of Header Files and Their Uses

A comparison of header file types encountered when developing for Neural Processing Units (NPUs) and hardware accelerators, detailing their purpose, origin, and typical use cases.

Header TypePurpose / ContentsOrigin / StandardTypical Use CasePortability & Lock-in

Standard Library Headers (e.g., <stdint.h>, <math.h>)

Provides portable type definitions (e.g., uint32_t) and standard function prototypes.

ISO C/C++ Standard

Foundational code for data types and basic operations. Essential for all systems programming.

High Portability ✅

Operating System Headers (e.g., <pthread.h>, <unistd.h>)

Exposes OS-specific APIs for threading, memory mapping, and system calls.

POSIX Standard or OS Vendor (e.g., Linux, Windows)

Managing concurrency, process control, and low-level system resources on the host CPU.

Moderate (OS-dependent) ⚠️

Hardware Abstraction Layer (HAL) Headers

Defines a uniform interface to hardware-specific features, insulating application code from direct hardware access.

Hardware Vendor or Framework (e.g., CMSIS for ARM)

Writing portable embedded code that can target different NPU families from the same vendor.

Vendor-Specific, but abstracts within vendor ecosystem ⚠️

Vendor SDK Headers (e.g., npu_sdk.h, vendor_lib.h)

Declares functions, data structures, and constants for the vendor's proprietary libraries and runtime APIs.

Hardware Vendor (e.g., NVIDIA, Intel, Qualcomm)

Initializing the NPU, managing device memory, submitting inference graphs, and using vendor-specific optimizations.

High Lock-in ❌

Compiler Intrinsic Headers (e.g., <arm_neon.h>, <immintrin.h>)

Declares compiler intrinsics—functions that map directly to specific SIMD or tensor instructions.

Compiler Vendor (e.g., GCC, Clang, ICC) for a target ISA

Explicitly leveraging vector units or specialized instructions (e.g., dot product) from C/C++ code.

ISA-Specific (e.g., ARM NEON, x86 AVX) ❌

Vendor ISA Intrinsic Headers

Declares low-level intrinsics that map 1:1 to instructions in the vendor's NPU-specific Instruction Set Architecture.

Hardware Vendor

Hand-coding performance-critical tensor operation kernels to maximize NPU utilization.

Extreme Lock-in (Specific NPU microarchitecture) ❌

Graph Compiler/Framework Headers (e.g., TensorFlow/c/experimental/stream_executor.h)

Exposes APIs for compiling neural network graphs, managing tensors, and deploying models to accelerators.

ML Framework Vendor (e.g., TensorFlow, PyTorch)

Integrating custom NPU backends into ML frameworks or writing low-level framework extensions.

Framework-Specific, but targets multiple backends ⚠️

Application Binary Interface (ABI) Headers / Stub Headers

Contains minimal declarations (function prototypes, structs) to satisfy linker dependencies, often pointing to a runtime library.

Toolchain Vendor or System Integrator

Linking against a closed-source vendor runtime library during compilation on a host system.

Tied to specific library version ABI ❌

INTERFACE SPECIFICATION

Header Files in NPU and Accelerator Programming

Header files (*.h) define the interface between application code and vendor-specific hardware libraries, providing the compiler with function prototypes, data types, and macro definitions essential for NPU programming.

01

Function Prototypes and API Definition

The primary role of a header file is to declare function prototypes for the vendor's SDK. This tells the compiler the name, return type, and parameters of functions like npu_launch_kernel() or tensor_memory_alloc(), without exposing the implementation. This enables separate compilation—your application code compiles against the declarations, and the linker later resolves them to the pre-compiled vendor library binaries. It defines the Application Programming Interface (API) contract.

02

Hardware-Specific Data Types and Constants

Header files define the custom data structures and constants that map to the accelerator's hardware. This includes:

  • Tensor descriptors (dimensions, data type, layout).
  • Enumerated types for operations (e.g., CONV_2D, MATMUL).
  • Error codes specific to the hardware (NPU_SUCCESS, NPU_MEMORY_ERROR).
  • Magic numbers like MAX_SIMD_WIDTH or SHARED_MEM_SIZE. Using these types ensures data is formatted correctly for the hardware's memory subsystem and instruction set.
03

Compiler Intrinsics and Inline Functions

For low-level performance, headers expose compiler intrinsics—special functions that map directly to single NPU instructions, such as a tensor load/store or a fused multiply-add. They also provide inline functions for common operations, giving the compiler a hint to insert the code directly at the call site to avoid function call overhead. This is critical for kernel fusion and exploiting specific hardware features like SIMD lanes or tensor cores without writing assembly.

04

Macro Definitions for Conditional Compilation

Header files use preprocessor macros (#define) extensively for:

  • Platform abstraction: #ifdef NPU_VENDOR_A / #elif defined(NPU_VENDOR_B) to conditionally include code for different accelerators.
  • Feature flags: ENABLE_FP16_PRECISION to toggle support for mixed-precision.
  • Constant folding: Defining TILE_SIZE as 32 allows the compiler to optimize loops unrolled for that size.
  • Debugging: DEBUG_PRINT macros that compile to nothing in release builds. This enables a single codebase to target multiple NPU generations or vendors.
05

Inclusion Guards and Dependency Management

To prevent multiple inclusion errors, header files use include guards (#ifndef HEADER_NAME_H / #define HEADER_NAME_H / #endif) or the #pragma once directive. They also #include other necessary headers, creating a dependency graph. For example, npu_linear_ops.h might include npu_tensor_types.h. Proper structuring avoids circular dependencies and ensures the compiler has all necessary type definitions. This is vital for large SDKs with hundreds of interdependent headers.

06

ABI Stability and Versioning

Headers are the anchor point for Application Binary Interface (ABI) stability. Changes to function signatures or data structure layouts in a header break binary compatibility. Vendors use versioning macros (e.g., SDK_VERSION_MAJOR 2) and namespace isolation (via prefixing, like vendorx_) to manage evolution. Engineers must include the correct versioned header to match the linked runtime library. Mismatches cause subtle linking errors or runtime crashes.

HEADER FILES

Frequently Asked Questions

Header files are a foundational element of C and C++ programming, providing the interface specification between different parts of a codebase. In the context of NPU acceleration, they are critical for accessing vendor-specific hardware features and SDK libraries.

A header file is a source code file, typically with a .h or .hpp extension, that contains declarations—such as function prototypes, macro definitions, type definitions (structs, enums), and constant values—which specify the interface for a library or module. It works by being included via the #include preprocessor directive in other source files (.c or .cpp). During compilation, the preprocessor literally copies the contents of the header file into the source file at the point of the #include, allowing the compiler to know the signatures of functions and the layout of data structures before they are defined elsewhere. This separation of interface (in the .h file) from implementation (in the .c/.cpp file) enables modular programming, code reuse, and efficient compilation.

For NPU programming, a vendor's SDK will provide critical header files (e.g., vendor_npu.h) that declare functions for device management, kernel launching, and memory operations, as well as data types for tensors and hardware-specific intrinsics.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.