Skip to content

Commit

Permalink
Support for CPY kernel (ggml-org#14)
Browse files Browse the repository at this point in the history
* Add HSA backend to GPT-2 example

* Remove CPU backend from HSA

* Returning that it is host buffer for NPU memory

* Adding CPY kernels and factoring out kernel code

* Formatting, comments

* Temporary storage for cpy

* Extracting supports_op conditions

* Renaming function
  • Loading branch information
ypapadop-amd committed Feb 17, 2025
1 parent 83c898b commit 27d537d
Show file tree
Hide file tree
Showing 6 changed files with 1,353 additions and 71 deletions.
17 changes: 17 additions & 0 deletions examples/gpt-2/main-sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include "ggml-blas.h"
#endif

#ifdef GGML_USE_HSA
#include "ggml-hsa.h"
#endif


#include "common.h"
#include "common-ggml.h"

Expand Down Expand Up @@ -145,6 +150,18 @@ void init_backends(gpt2_model & model, const gpt_params & params) {
}
#endif

#ifdef GGML_USE_HSA
if (params.n_gpu_layers > 0) {
fprintf(stderr, "%s: using HSA backend\n", __func__);
ggml_backend_t hsa_backend = ggml_backend_hsa_init(0);
if (!hsa_backend) {
fprintf(stderr, "%s: ggml_backend_hsa_init() failed\n", __func__);
} else {
model.backends.push_back(hsa_backend);
}
}
#endif

// always add the CPU backend as a fallback
ggml_backend_t cpu_backend = ggml_backend_cpu_init();
ggml_backend_cpu_set_n_threads(cpu_backend, params.n_threads);
Expand Down
8 changes: 6 additions & 2 deletions src/ggml-hsa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ find_package(hsa-runtime64 1.0 REQUIRED)
message(STATUS "HSA found")

set(GGML_HEADERS_HSA ../../include/ggml-hsa.h)
set(GGML_SOURCES_HSA ggml-hsa.cpp)
set(GGML_SOURCES_HSA
ggml-hsa.cpp
cpy.cpp
mul_mat.cpp
)

ggml_add_backend_library(ggml-hsa
${GGML_HEADERS_HSA}
Expand All @@ -33,7 +37,7 @@ target_include_directories(ggml-hsa PRIVATE . ..)
find_package(Eigen3 3.3 REQUIRED)
target_link_libraries(ggml-hsa PRIVATE Eigen3::Eigen)

target_sources(ggml-hsa PRIVATE common.hpp)
target_sources(ggml-hsa PRIVATE common.hpp kernels.hpp)

set_source_files_properties(${GGML_SOURCES_ROCM} PROPERTIES LANGUAGE CXX)

Expand Down
Loading

0 comments on commit 27d537d

Please sign in to comment.