now linking and crashing

This commit is contained in:
mike dupont 2023-12-10 15:07:04 -05:00
parent da5bbd73a8
commit d739470198
4 changed files with 59 additions and 17 deletions

View file

@ -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("$<$<COMPILE_LANGUAGE:C>:${c_flags}>"
"$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>"
"$<$<COMPILE_LANGUAGE:CXX>:${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

View file

@ -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)

View file

@ -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)

View file

@ -16,9 +16,9 @@
#include<caml/backtrace.h>
#include<caml/bigarray.h>
#include<caml/callback.h> // this one's the big important one for embedding OCaml
#include<caml/compact.h>
//#include<caml/compact.h>
#include<caml/compare.h>
#include<caml/compatibility.h>
//#include<caml/compatibility.h>
#include<caml/config.h>
#include<caml/custom.h>
#include<caml/debugger.h>
@ -27,7 +27,7 @@
#include<caml/fail.h>
#include<caml/finalise.h>
#include<caml/fix_code.h>
#include<caml/freelist.h>
//#include<caml/freelist.h>
#include<caml/gc_ctrl.h>
#include<caml/gc.h>
#include<caml/globroots.h>
@ -53,17 +53,17 @@
#include<caml/printexc.h>
#include<caml/reverse.h>
#include<caml/roots.h>
#include<caml/signals_machdep.h>
//#include<caml/signals_machdep.h>
#include<caml/signals.h>
#include<caml/socketaddr.h>
//#include<caml/spacetime.h>
#include<caml/stack.h>
#include<caml/stacks.h>
//#include<caml/stacks.h>
#include<caml/startup_aux.h>
#include<caml/startup.h>
#include<caml/sys.h>
#include<caml/threads.h>
#include<caml/ui.h>
//#include<caml/ui.h>
#include<caml/unixsupport.h>
#include<caml/version.h>
#include<caml/weak.h>