Skip to content

Commit

Permalink
add to cpp example
Browse files Browse the repository at this point in the history
  • Loading branch information
cyita committed Jan 26, 2025
1 parent 9f10db8 commit 0cc8064
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,39 @@ if(DEFINED ENV{CONDA_ENV_DIR})
set(LIBRARY_DIR ${ENV_DIR}/bigdl-core-npu)
include_directories(${LIBRARY_DIR}/include)
set(DLL_DIR ${ENV_DIR}/intel_npu_acceleration_library/lib/Release)
set(LLAMA_CPP_LIBRARY_DIR "D:\\yina\\llamacpplibs")
include_directories(${LLAMA_CPP_LIBRARY_DIR}/include)
else()
set(LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
set(LLAMA_CPP_LIBRARY_DIR "D:\\yina\\llamacpplibs")
include_directories(${LLAMA_CPP_LIBRARY_DIR}/include)
endif()

add_library(npu_llm STATIC IMPORTED)
set_target_properties(npu_llm PROPERTIES IMPORTED_LOCATION ${LIBRARY_DIR}/npu_llm.lib)

add_library(llama STATIC IMPORTED)
set_target_properties(llama PROPERTIES IMPORTED_LOCATION ${LLAMA_CPP_LIBRARY_DIR}/llama.lib)

add_library(common STATIC IMPORTED)
set_target_properties(common PROPERTIES IMPORTED_LOCATION ${LLAMA_CPP_LIBRARY_DIR}/common.lib)

add_library(ggml STATIC IMPORTED)
set_target_properties(ggml PROPERTIES IMPORTED_LOCATION ${LLAMA_CPP_LIBRARY_DIR}/ggml.lib)

set(TARGET llama-cli-npu)
add_executable(${TARGET} llama-cli-npu.cpp)
install(TARGETS ${TARGET} RUNTIME)
target_link_libraries(${TARGET} PRIVATE npu_llm)
# target_link_libraries(${TARGET} PRIVATE npu_llm)
target_link_libraries(${TARGET} PRIVATE npu_llm common llama ggml ${CMAKE_THREAD_LIBS_INIT})
target_compile_features(${TARGET} PRIVATE cxx_std_17)

add_custom_command(TARGET llama-cli-npu POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${LIBRARY_DIR}/npu_llm.dll
${LLAMA_CPP_LIBRARY_DIR}/llama.dll
${LLAMA_CPP_LIBRARY_DIR}/ggml.dll
${CMAKE_BINARY_DIR}/Release/
COMMENT "Copying npu_llm.dll to build/Release\n"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
#include "common.h"
#include "npu_llm.h"

#include "llamacpp/arg.h"
#include "llamacpp/common.h"
#include "llamacpp/log.h"
#include "llamacpp/llama.h"
#include <filesystem>
#include <vector>
#include<iostream>


static void print_usage(int, char ** argv) {
printf("\nexample usage:\n");
Expand Down Expand Up @@ -246,7 +254,7 @@ int main(int argc, char ** argv) {
model_params, tok_params, generation_params);

std::cout << output << std::endl << std::endl;
llm_perf_print(model);
// llm_perf_print(model);
}
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ project(LLM_GGUF_TO_NPU VERSION 1.0.0 LANGUAGES CXX)
set (CMAKE_CXX_STANDARD 17)
SET (CMAKE_CXX_STANDARD_REQUIRED True)

set(LIBRARY_DIR "D:\\yina\\llamacpplibs")
include_directories(${LIBRARY_DIR}/include)
set(LLAMA_CPP_LIBRARY_DIR "D:\\yina\\llamacpplibs")
include_directories(${LLAMA_CPP_LIBRARY_DIR}/include)

add_library(llama STATIC IMPORTED)
set_target_properties(llama PROPERTIES IMPORTED_LOCATION ${LIBRARY_DIR}/llama.lib)
set_target_properties(llama PROPERTIES IMPORTED_LOCATION ${LLAMA_CPP_LIBRARY_DIR}/llama.lib)

add_library(common STATIC IMPORTED)
set_target_properties(common PROPERTIES IMPORTED_LOCATION ${LIBRARY_DIR}/common.lib)
set_target_properties(common PROPERTIES IMPORTED_LOCATION ${LLAMA_CPP_LIBRARY_DIR}/common.lib)

add_library(ggml STATIC IMPORTED)
set_target_properties(ggml PROPERTIES IMPORTED_LOCATION ${LIBRARY_DIR}/ggml.lib)
set_target_properties(ggml PROPERTIES IMPORTED_LOCATION ${LLAMA_CPP_LIBRARY_DIR}/ggml.lib)


set(TARGET convert-gguf-to-npu)
Expand All @@ -31,8 +31,8 @@ target_compile_features(${TARGET} PRIVATE cxx_std_17)

add_custom_command(TARGET convert-gguf-to-npu POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${LIBRARY_DIR}/llama.dll
${LIBRARY_DIR}/ggml.dll
${LLAMA_CPP_LIBRARY_DIR}/llama.dll
${LLAMA_CPP_LIBRARY_DIR}/ggml.dll
${CMAKE_BINARY_DIR}/Release/
COMMENT "Copying npu_llm.dll to build/Release\n"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "arg.h"
#include "common.h"
#include "log.h"
#include "llama.h"
#include "llamacpp/arg.h"
#include "llamacpp/common.h"
#include "llamacpp/log.h"
#include "llamacpp/llama.h"
#include <filesystem>
#include <vector>
#include<iostream>
Expand Down

0 comments on commit 0cc8064

Please sign in to comment.