Skip to content

Commit

Permalink
do test and fix load dll on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberhan123 committed Oct 1, 2023
1 parent 9a0611c commit 77ec5f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,9 @@ endif()

if (NOT RWKV_STANDALONE)
set_property(TARGET ggml PROPERTY GGML_STANDALONE OFF)
# if(NOT RWKV_HIPBLAS)
enable_testing()
add_subdirectory(tests)
add_subdirectory(extras)
# endif()
enable_testing()
add_subdirectory(tests)
add_subdirectory(extras)
elseif()
set_property(TARGET ggml PROPERTY GGML_STANDALONE ON)
endif()
11 changes: 9 additions & 2 deletions python/rwkv_cpp/rwkv_cpp_shared_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import ctypes
import pathlib
import platform
from typing import Optional, List, Tuple, Callable

QUANTIZED_FORMAT_NAMES: Tuple[str, str, str, str, str] = (
Expand Down Expand Up @@ -35,8 +36,13 @@ def __init__(self, shared_library_path: str) -> None:
shared_library_path : str
Path to rwkv.cpp shared library. On Windows, it would look like 'rwkv.dll'. On UNIX, 'rwkv.so'.
"""

self.library = ctypes.cdll.LoadLibrary(shared_library_path)
# When Python is greater than 3.8, we need to reprocess the custom dll
# according to the documentation to prevent loading failure errors.
# https://docs.python.org/3/whatsnew/3.8.html#ctypes
if platform.system().lower() == 'windows':
self.library = ctypes.CDLL(shared_library_path, winmode=0)
else:
self.library = ctypes.cdll.LoadLibrary(shared_library_path)

self.library.rwkv_init_from_file.argtypes = [ctypes.c_char_p, ctypes.c_uint32]
self.library.rwkv_init_from_file.restype = ctypes.c_void_p
Expand Down Expand Up @@ -406,6 +412,7 @@ def load_rwkv_shared_library() -> RWKVSharedLibrary:
lambda p: p / 'bin' / file_name,
# Some people prefer to build in the "build" subdirectory.
lambda p: p / 'build' / 'bin' / 'Release' / file_name,
lambda p: p / 'build' / 'bin' / file_name,
lambda p: p / 'build' / file_name,
# Fallback.
lambda p: p / file_name
Expand Down

0 comments on commit 77ec5f4

Please sign in to comment.