Skip to content

Commit 935d852

Browse files
committed
Nouveau Backend (en cours)
- utilise les wrapper c++ - teste reference sur CPU (fp32 non optimisé) - init de l' iGPU RDNA3 - allocation memoire sur ce backend HIP - 1ere version du produit matriciel wmma
1 parent f4b0e96 commit 935d852

8 files changed

+837
-0
lines changed

ggml/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ set(GGML_BLAS_VENDOR ${GGML_BLAS_VENDOR_DEFAULT} CACHE STRING
141141
"ggml: BLAS library vendor")
142142
option(GGML_LLAMAFILE "ggml: use LLAMAFILE" ${GGML_LLAMAFILE_DEFAULT})
143143

144+
option(GGML_IGPU "ggml: use IGPU" OFF)
145+
144146
option(GGML_CUDA "ggml: use CUDA" OFF)
145147
option(GGML_MUSA "ggml: use MUSA" OFF)
146148
option(GGML_CUDA_FORCE_MMQ "ggml: use mmq kernels instead of cuBLAS" OFF)
@@ -244,6 +246,7 @@ set(GGML_PUBLIC_HEADERS
244246
include/ggml-blas.h
245247
include/ggml-cann.h
246248
include/ggml-cuda.h
249+
include/ggml-igpu.h
247250
include/ggml-kompute.h
248251
include/ggml-opt.h
249252
include/ggml-metal.h

ggml/cmake/ggml-config.cmake.in

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ if (NOT GGML_SHARED_LIB)
7676
list(APPEND GGML_HIP_INTERFACE_LINK_LIBRARIES hip::host roc::rocblas roc::hipblas)
7777
endif()
7878

79+
if (GGML_IGPU)
80+
find_package(hip REQUIRED)
81+
list(APPEND GGML_HIP_INTERFACE_LINK_LIBRARIES hip::host)
82+
endif()
83+
7984
if (GGML_SYCL)
8085
find_package(DNNL)
8186
if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL")

ggml/include/ggml-igpu.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include "ggml.h"
4+
#include "ggml-backend.h"
5+
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif
10+
11+
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_igpu_reg(void);
12+
13+
14+
#ifdef __cplusplus
15+
}
16+
#endif

ggml/src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ ggml_add_backend(BLAS)
324324
ggml_add_backend(CANN)
325325
ggml_add_backend(CUDA)
326326
ggml_add_backend(HIP)
327+
ggml_add_backend(IGPU)
327328
ggml_add_backend(Kompute)
328329
ggml_add_backend(METAL)
329330
ggml_add_backend(MUSA)

ggml/src/ggml-backend-reg.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
#include "ggml-kompute.h"
6767
#endif
6868

69+
#ifdef GGML_USE_IGPU
70+
#include "ggml-igpu.h"
71+
#endif
72+
6973
// disable C++17 deprecation warning for std::codecvt_utf8
7074
#if defined(__clang__)
7175
# pragma clang diagnostic push
@@ -153,6 +157,9 @@ struct ggml_backend_registry {
153157
std::vector<ggml_backend_dev_t> devices;
154158

155159
ggml_backend_registry() {
160+
#ifdef GGML_USE_IGPU
161+
register_backend(ggml_backend_igpu_reg());
162+
#endif
156163
#ifdef GGML_USE_CUDA
157164
register_backend(ggml_backend_cuda_reg());
158165
#endif

ggml/src/ggml-igpu/CMakeLists.txt

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
if (WIN32)
2+
message(FATAL_ERROR "Not teste on Windows OS")
3+
endif()
4+
5+
# pas encore bon dans
6+
# => /usr/share/cmake/Modules/CMakeDetermineHIPCompiler.cmake
7+
# => /usr/lib64/cmake/hip-lang/hip-lang-config.cmake vs /usr/local/lib64/cmake/hip-lang/hip-lang-config.cmake
8+
# hipcc -v -print-targets | grep "Found HIP installation" => mauvais?
9+
# /usr/lib64/llvm18/bin/clang++ -v -print-targets | grep "Found HIP installation" => mauvais !!!
10+
# clang-18 -v -print-targets | grep "Found HIP installation" => OK
11+
# hipconfig --rocmpath => OK => on va le forcer
12+
13+
# forcer la dernier methode...
14+
if(NOT CMAKE_HIP_COMPILER_ROCM_ROOT)
15+
execute_process(
16+
COMMAND hipconfig --rocmpath
17+
OUTPUT_VARIABLE _CMAKE_HIPCONFIG_ROCMPATH
18+
RESULT_VARIABLE _CMAKE_HIPCONFIG_RESULT
19+
)
20+
if(_CMAKE_HIPCONFIG_RESULT EQUAL 0 AND EXISTS "${_CMAKE_HIPCONFIG_ROCMPATH}")
21+
set(CMAKE_HIP_COMPILER_ROCM_ROOT "${_CMAKE_HIPCONFIG_ROCMPATH}")
22+
endif()
23+
endif()
24+
25+
# Forward AMDGPU_TARGETS to CMAKE_HIP_ARCHITECTURES.
26+
if (AMDGPU_TARGETS AND NOT CMAKE_HIP_ARCHITECTURES)
27+
set(CMAKE_HIP_ARCHITECTURES ${AMDGPU_TARGETS})
28+
endif()
29+
cmake_minimum_required(VERSION 3.21)
30+
31+
enable_language(HIP)
32+
33+
find_package(hip REQUIRED)
34+
35+
# pas testé d'autre version...
36+
if (${hip_VERSION} VERSION_LESS 6.2)
37+
message(FATAL_ERROR "At least ROCM/HIP V6.2 is required")
38+
endif()
39+
40+
message(STATUS "HIP found")
41+
42+
set(TARGET_NAME ggml-igpu)
43+
44+
file(GLOB GGML_SOURCES_ROCM "ggml-igpu.cpp")
45+
#file(GLOB SRCS "*.hip")
46+
#list(APPEND GGML_SOURCES_ROCM ${SRCS})
47+
48+
ggml_add_backend_library(${TARGET_NAME}
49+
../../include/ggml-igpu.h
50+
${GGML_SOURCES_ROCM}
51+
)
52+
53+
add_compile_definitions(GGML_USE_IGPU)
54+
55+
set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE HIP)
56+
57+
if (GGML_STATIC)
58+
message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
59+
endif()
60+
61+
target_link_libraries(${TARGET_NAME} PRIVATE ggml-base hip::host)

0 commit comments

Comments
 (0)