From d7394701983974c848bc66f3746efd93953ffbef Mon Sep 17 00:00:00 2001 From: mike dupont Date: Sun, 10 Dec 2023 15:07:04 -0500 Subject: [PATCH] now linking and crashing --- CMakeLists.txt | 54 +++++++++++++++++++++++++++++++----- Makefile | 8 ++++-- examples/main/CMakeLists.txt | 2 +- plugin_ocaml.cpp | 12 ++++---- 4 files changed, 59 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df9c4c371..75f5f10da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13) # for add_link_options project("llama.cpp" C CXX) find_package (Python3 COMPONENTS Interpreter Development) execute_process(COMMAND "ocamlopt" "-where" OUTPUT_VARIABLE OCAMLC_WHERE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) -set(OCAML_RUNTIMELIBRARY "${OCAMLC_WHERE}/libasmrun_pic.a") +#set(OCAML_RUNTIMELIBRARY "${OCAMLC_WHERE}/libasmrun_pic.a") if (Python3_Interpreter_FOUND) if (UNIX AND NOT APPLE) @@ -504,8 +504,8 @@ if (LLAMA_ALL_WARNINGS) # todo : msvc endif() - set(c_flags ${c_flags} -save-temps --verbose ${warning_flags}) - set(cxx_flags ${cxx_flags} -fpermissive -save-temps --verbose ${warning_flags}) + set(c_flags ${c_flags} -save-temps -fPIC --verbose ${warning_flags}) + set(cxx_flags ${cxx_flags} -fpermissive -fPIC -save-temps --verbose ${warning_flags}) add_compile_options("$<$:${c_flags}>" "$<$:${cxx_flags}>" "$<$:${host_cxx_flags}>") @@ -731,7 +731,7 @@ if (GGML_USE_CPU_HBM) endif() #/usr/local/lib/ocaml/ -set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/lib/ocaml) +set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/lib/ocaml) add_library(libmetacalld SHARED IMPORTED) @@ -748,7 +748,7 @@ add_library(ggml OBJECT plugin_python.cpp plugin_nodejs.cpp plugin_nodejs_metacall.cpp - plugin_ocaml.cpp + plugin_ocaml.cpp ggml-internal.hpp llama-internal.hpp ggml-alloc.cpp @@ -764,11 +764,35 @@ add_library(ggml OBJECT ${GGML_SOURCES_EXTRA} ${GGML_HEADERS_EXTRA} ) -set(LLAMA_EXTRA_INCLUDES ${LLAMA_EXTRA_INCLUDES} "/usr/lib/ocaml/") +set(LLAMA_EXTRA_INCLUDES ${LLAMA_EXTRA_INCLUDES} "/usr/local/lib/ocaml/") target_include_directories(ggml PUBLIC "/usr/include/node/" . ${LLAMA_EXTRA_INCLUDES} ) +# +# "/usr/local/lib/ocaml/libasmrun.a" +# "/usr/local/lib/ocaml/libcamlrun.a" target_compile_features(ggml PUBLIC c_std_23) # always bump -target_link_libraries(ggml PUBLIC Threads::Threads ${LLAMA_EXTRA_LIBS} libmetacalld "/usr/lib/ocaml/libasmrund.a") + # /usr/local/lib/ocaml/libcamlrun_pic.a + # /usr/local/lib/ocaml/libasmrund.a + # /usr/local/lib/ocaml/libasmrun.a + # /usr/local/lib/ocaml/libasmrund.a + # /usr/local/lib/ocaml/libasmruni.a + # #/usr/local/lib/ocaml/libcamlrund.a + +#/usr/bin/c++ -Wall -Wextra -fno-strict-aliasing -fno-rtti -fno-exceptions -D GLIBCXX_FORCE_NEW -fPIC -g -O0 -g3 -pg -rdynamic CMakeFiles/Cppcamlexample.dir/app/MainLoop.cpp.o CMakeFiles/Cppcamlexample.dir/app/main.cpp.o -o Cppcamlexample -Wl,-rpath,/home/mdupont/2023/12/09/Cppcamlexample/build -ldl -lm /usr/local/lib/ocaml/libasmrun_pic.a -Wl,-Bstatic -Wl,-Bdynamic libCppcamlexampleEngine.so game.o -ldl -lm + + +target_link_libraries(ggml PUBLIC Threads::Threads ${LLAMA_EXTRA_LIBS} libmetacalld + + /usr/local/lib/libzstd.a + "${CMAKE_CURRENT_SOURCE_DIR}/build2/ocaml-example-script.o" + /usr/local/lib/ocaml/libasmrun_pic.a + + #/usr/local/lib/ocaml/libcamlrun.a ) + #/usr/local/lib/ocaml/libasmrun_pic.a + # + #/usr/local/lib/ocaml/libcamlrun_pic.a + ) +# /usr/local/lib/ocaml/libcamlrun.a if (GGML_USE_CPU_HBM) target_link_libraries(ggml PUBLIC memkind) endif() @@ -935,3 +959,19 @@ find_ocaml_package(extlib) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fno-strict-aliasing -fPIC") #target_link_libraries(${LIBRARY_NAME} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2GFX_LIBRARIES} ${SDL2MIXER_LIBRARIES} ${SDL2TTF_LIBRARIES} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} dl m ) + + +##ocaml +file(GLOB OCAML_SCRIPT_SOURCES + "${CMAKE_CURRENT_SOURCE_DIR}/caml_src/*.ml" +) + +#WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build" +add_custom_target("ocaml_script" "ocamlopt" "-g" "-fPIC" "-linkall" "-output-obj" "${OCAML_SCRIPT_SOURCES}" "-o" "${CMAKE_CURRENT_SOURCE_DIR}/build2/ocaml-example-script.o" VERBATIM SOURCES ${OCAML_SCRIPT_SOURCES}) + +#nm /usr/local/lib/ocaml/libcamlrun_pic.a |grep unbox +#ocamlc -output-obj -o embed_out.c +#/usr/local/bin/ocamlc ../caml_src/step.ml -output-obj -o embed_out.c + + +#/usr/local/bin/ocamlc caml_src/step.ml -output-obj -o embed_out.c diff --git a/Makefile b/Makefile index 0132a4fb4..f202614f2 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ endif # # keep standard at C11 and C++11 -MK_CPPFLAGS = -I. -Icommon +MK_CPPFLAGS = -I. -Icommon -I/usr/local/lib/ocaml/ MK_CFLAGS = -std=c11 -fPIC MK_CXXFLAGS = -std=c++17 -fPIC -fpermissive @@ -587,11 +587,13 @@ clean: # Examples # -main: examples/main/main.cpp plugin_nodejs.o ggml.o llama.o $(COMMON_DEPS) console.o grammar-parser.o $(OBJS) - $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) /usr/lib/libnode.so +main: examples/main/main.cpp ocaml-example-script.o plugin_nodejs.o plugin_ocaml.o ggml.o llama.o $(COMMON_DEPS) console.o grammar-parser.o $(OBJS) + $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) /usr/lib/libnode.so /usr/local/lib/ocaml/libasmrun_pic.a -lzstd @echo @echo '==== Run ./main -h for help. ====' @echo +ocaml-example-script.o: + ocamlopt -g -fPIC -linkall -output-obj caml_src/step.ml -o ocaml-example-script.o infill: examples/infill/infill.cpp ggml.o llama.o $(COMMON_DEPS) console.o grammar-parser.o $(OBJS) $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) diff --git a/examples/main/CMakeLists.txt b/examples/main/CMakeLists.txt index d4b96cd8a..1f2cbd5d5 100644 --- a/examples/main/CMakeLists.txt +++ b/examples/main/CMakeLists.txt @@ -1,6 +1,6 @@ set(TARGET main) add_executable(${TARGET} main.cpp) install(TARGETS ${TARGET} RUNTIME) -target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} libnode.so ) +target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} libnode.so "/usr/lib/x86_64-linux-gnu/libzstd.a" "/usr/lib/x86_64-linux-gnu/libzstd.so") target_compile_features(${TARGET} PRIVATE cxx_std_20) diff --git a/plugin_ocaml.cpp b/plugin_ocaml.cpp index f537f83e9..8f9b254ab 100644 --- a/plugin_ocaml.cpp +++ b/plugin_ocaml.cpp @@ -16,9 +16,9 @@ #include #include #include // this one's the big important one for embedding OCaml -#include +//#include #include -#include +//#include #include #include #include @@ -27,7 +27,7 @@ #include #include #include -#include +//#include #include #include #include @@ -53,17 +53,17 @@ #include #include #include -#include +//#include #include #include //#include #include -#include +//#include #include #include #include #include -#include +//#include #include #include #include