Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ggml/src/ggml-et/et-kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
# This keeps kernels in compile_commands.json for full IDE support.

# --- RISC-V toolchain setup (scoped to this directory) ---
# Host-only sanitizer flags (-fsanitize=... from GGML_SANITIZE_*) are added at
# the ggml/src scope and would otherwise propagate here and break the baremetal
# RISC-V kernel link. Strip inherited host build flags for this directory only
# when a sanitizer build is requested.
if (GGML_SANITIZE_ADDRESS OR GGML_SANITIZE_THREAD OR GGML_SANITIZE_UNDEFINED)
set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "")
set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
set_property(DIRECTORY PROPERTY LINK_LIBRARIES "")
endif()
set(TOOLCHAIN_DIR ${ET_PLATFORM_PATH})
include(${ET_PLATFORM_PATH}/lib/cmake/riscv64-ec-toolchain.cmake)
set(CMAKE_ADDR2LINE "${TOOLCHAIN_DIR}/bin/riscv64-unknown-elf-addr2line")
Expand Down
8 changes: 7 additions & 1 deletion ggml/src/ggml-et/ggml-et.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,13 @@ static void ggml_backend_et_get_tensor_async(ggml_backend_t backend,
const std::byte * src_ptr = static_cast<const std::byte *>(tensor->data) + offset;
std::byte * dst_ptr = static_cast<std::byte *>(data);

runtime->memcpyDeviceToHost(stream, src_ptr, dst_ptr, size, true /*barrier*/);
// The runtime performs the host-side copy on a worker thread. We must wait
// for it here: the caller may free the host destination buffer (e.g. the
// logits/output buffer during llama_context teardown) before the next
// stream-level synchronize, which would leave this copy writing into freed
// memory (heap-use-after-free).
rt::EventId event = runtime->memcpyDeviceToHost(stream, src_ptr, dst_ptr, size, true /*barrier*/);
runtime->waitForEvent(event);
}

static bool ggml_backend_et_cpy_tensor_async(ggml_backend_t backend_src,
Expand Down
Loading