Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ggml org Ggml Sycl dpct helper

From Leeroopedia


Knowledge Sources
Domains ML_Infrastructure, GPU_Compute, Hardware_Abstraction
Last Updated 2025-05-15 12:00 GMT

Overview

DPCT (Data Parallel Compatibility Tool) helper layer providing CUDA-like abstractions over SYCL for device management, memory operations, and Intel MKL BLAS integration.

Description

dpct/helper.hpp is the foundational compatibility layer that bridges CUDA programming idioms to SYCL, enabling the SYCL backend to reuse patterns familiar from the CUDA backend. This large header (3002 lines) defines the dpct namespace with:

  • Type aliases: queue_ptr (sycl::queue *), event_ptr (sycl::event *), device_ptr (char *), byte_t (uint8_t) -- mirroring CUDA's stream/event/pointer types.
  • Device management: The dev_mgr singleton class manages SYCL device enumeration and selection, providing device_count(), get_device(), select_device(), and queue management. The device_ext class wraps sycl::device with additional capabilities like default queues.
  • Device info: The device_info class provides hardware capability queries (compute units, memory size, max work-group size) analogous to CUDA's cudaDeviceProp.
  • Memory management: The mem_mgr class with allocation tracking, and memory operation wrappers for device-to-host, host-to-device, and device-to-device transfers.
  • Math helpers: dim3 struct for 3D kernel dimensions, matrix_info_t for oneMKL GEMM parameters, vectorized_binary for SIMD operations, and sub_sat for saturation arithmetic.
  • Platform macros: __dpct_align__(n), __dpct_inline__, __dpct_noinline__ for cross-platform alignment and inlining attributes.
  • Error handling: generic_error_type enum, success/default_error constants, and has_capability_or_fail for device aspect checking.

Usage

Included by common.hpp and transitively by every file in the SYCL backend. Provides the abstraction layer that allows SYCL kernel code to use CUDA-like device management patterns without directly depending on CUDA APIs.

Code Reference

Source Location

  • Repository: GGML
  • File: src/ggml-sycl/dpct/helper.hpp
  • Lines: 3002

Signatures

namespace dpct {
    typedef sycl::queue *queue_ptr;
    typedef sycl::event *event_ptr;
    typedef char *device_ptr;
    typedef uint8_t byte_t;

    // Device management singleton
    class dev_mgr {
    public:
        static dev_mgr &instance();
        int device_count();
        sycl::device &get_device(unsigned int id);
        unsigned int current_device_id();
        void select_device(unsigned int id);
    };

    // Device info wrapper
    class device_info { /* compute capability, memory, work-group size */ };

    // Device extension class
    class device_ext {
        sycl::queue *get_default_queue();
    };

    // Error codes
    enum generic_error_type { success = 0, default_error = 1 };
}

// Utility functions
inline std::string get_device_type_name(const sycl::device &Device);
inline std::string get_device_backend_and_type(const sycl::device &device);

// Matrix info for MKL GEMM
template <typename Ts> struct matrix_info_t {
    oneapi::mkl::transpose transpose_info[2];
    Ts value_info[2];
    std::int64_t size_info[3];
    std::int64_t ld_info[3];
    std::int64_t groupsize_info;
};

I/O Contract

Inputs

Name Type Required Description
(header) - - No runtime inputs; provides compile-time types, classes, and function declarations

Outputs

Name Type Description
(header) - Exports the dpct namespace with device management, memory operations, and CUDA compatibility types

Usage Examples

// Query available devices
int device_count = dpct::dev_mgr::instance().device_count();

// Select a specific device
dpct::select_device(0);

// Get device properties
dpct::device_info prop;
dpct::get_device_info(prop, device);
int compute_units = prop.get_max_compute_units();
size_t global_mem = prop.get_global_mem_size();

// Use queue pointer for kernel launch
dpct::queue_ptr stream = ctx.stream();
stream->parallel_for(range, kernel);

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment