1
0
Fork 0
mirror of https://gitlab.com/niansa/libjustlm.git synced 2025-03-06 20:49:17 +01:00

Minor improvemens in CMakeFiles and dlhandle

This commit is contained in:
niansa 2023-05-18 22:31:17 +02:00
parent e489f0f53c
commit f279b31d5f
3 changed files with 87 additions and 93 deletions

View file

@ -20,14 +20,15 @@ if (LM_COSCHED)
endif()
function(target_justlm_setup target)
target_include_directories(${target} PUBLIC include/)
function(target_justlm_setup TARGET_NAME)
message(STATUS "Configuring model implementation target ${TARGET_NAME}")
target_include_directories(${TARGET_NAME} PUBLIC include/)
if (LM_COSCHED)
target_compile_definitions(${target} PUBLIC LM_COSCHED)
target_link_libraries(${target} PRIVATE cosched)
target_compile_definitions(${TARGET_NAME} PUBLIC LM_COSCHED)
target_link_libraries(${TARGET_NAME} PRIVATE cosched)
endif()
if (LM_NOEXCEPT)
target_compile_definitions(${target} PUBLIC LM_NOEXCEPT)
target_compile_definitions(${TARGET_NAME} PUBLIC LM_NOEXCEPT)
endif()
endfunction()

View file

@ -1,30 +1,27 @@
#ifndef DLHANDLE_H
#define DLHANDLE_H
#ifndef __WIN32
#include <string>
#include <exception>
#include <stdexcept>
#include <utility>
#include <dlfcn.h>
class Dlhandle {
void *chandle;
public:
class Exception : public std::exception {
std::string errmsg;
class Exception : public std::runtime_error {
public:
Exception(std::string errmsg) {
this->errmsg = errmsg;
}
virtual const char* what() const throw() {
return errmsg.c_str();
}
using std::runtime_error::runtime_error;
};
Dlhandle() : chandle(nullptr) {}
Dlhandle(const std::string& fpath, int flags = RTLD_LAZY) {
chandle = dlopen(fpath.c_str(), flags);
if (!chandle) {
throw Exception("dlopen(): "+fpath);
throw Exception("dlopen(\""+fpath+"\"): "+dlerror());
}
}
Dlhandle(const Dlhandle& o) = delete;
@ -48,7 +45,6 @@ public:
template<typename T>
T* get(const std::string& fname) {
dlerror(); // Clear error
auto fres = reinterpret_cast<T*>(dlsym(chandle, fname.c_str()));
return (dlerror()==NULL)?fres:nullptr;
}
@ -67,22 +63,16 @@ class Dlhandle {
HMODULE chandle;
public:
class Exception : public std::exception {
std::string errmsg;
class Exception : public std::runtime_error {
public:
Exception(std::string errmsg) {
this->errmsg = errmsg;
}
virtual const char* what() const throw() {
return errmsg.c_str();
}
using std::runtime_error::runtime_error;
};
Dlhandle() : chandle(nullptr) {}
Dlhandle(const std::string& fpath) {
chandle = LoadLibraryA(fpath.c_str());
if (!chandle) {
throw Exception("dlopen(): "+fpath);
throw Exception("dlopen(\""+fpath+"\"): Error");
}
}
Dlhandle(const Dlhandle& o) = delete;
@ -106,3 +96,4 @@ public:
}
};
#endif
#endif // DLHANDLE_H

View file

@ -51,16 +51,16 @@ option(LLAMA_SANITIZE_ADDRESS "llama: enable address sanitizer"
option(LLAMA_SANITIZE_UNDEFINED "llama: enable undefined sanitizer" OFF)
# instruction set specific
option(LLAMA_AVX "llama: enable AVX" ON)
option(LLAMA_AVX2 "llama: enable AVX2" ON)
option(LLAMA_AVX512 "llama: enable AVX512" OFF)
option(LLAMA_AVX512_VBMI "llama: enable AVX512-VBMI" OFF)
option(LLAMA_AVX512_VNNI "llama: enable AVX512-VNNI" OFF)
option(LLAMA_FMA "llama: enable FMA" ON)
#option(LLAMA_AVX "llama: enable AVX" ON)
#option(LLAMA_AVX2 "llama: enable AVX2" ON)
#option(LLAMA_AVX512 "llama: enable AVX512" OFF)
#option(LLAMA_AVX512_VBMI "llama: enable AVX512-VBMI" OFF)
#option(LLAMA_AVX512_VNNI "llama: enable AVX512-VNNI" OFF)
#option(LLAMA_FMA "llama: enable FMA" ON)
# in MSVC F16C is implied with AVX2/AVX512
if (NOT MSVC)
option(LLAMA_F16C "llama: enable F16C" ON)
endif()
#if (NOT MSVC)
# option(LLAMA_F16C "llama: enable F16C" ON)
#endif()
# 3rd party libs
option(LLAMA_ACCELERATE "llama: enable Accelerate framework" ON)
@ -207,7 +207,10 @@ if (NOT MSVC)
endif()
endif()
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
function(include_ggml DIRECTORY SUFFIX WITH_LLAMA)
message(STATUS "Configuring ggml implementation target llama${SUFFIX} in ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}")
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
message(STATUS "ARM detected")
if (MSVC)
# TODO: arm msvc?
@ -217,7 +220,7 @@ if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES
endif()
# TODO: armv6,7,8 version specific flags
endif()
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$")
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$")
message(STATUS "x86 detected")
if (MSVC)
if (LLAMA_AVX512)
@ -266,16 +269,15 @@ elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$")
add_compile_options(-mavx512vnni)
endif()
endif()
else()
else()
# TODO: support PowerPC
message(STATUS "Unknown architecture")
endif()
endif()
#
# Build libraries
#
#
# Build libraries
#
function(include_ggml DIRECTORY SUFFIX WITH_LLAMA)
if (LLAMA_CUBLAS)
cmake_minimum_required(VERSION 3.17)