Skip to content

Commit

Permalink
add workflow and fix macOS build (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Menooker authored Feb 28, 2024
1 parent 8c4abf3 commit 6eeed1b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: C/C++ CI

on: [push,pull_request]

jobs:
build:

runs-on: macos-13

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: make
working-directory: ./
run: mkdir build && cd build && cmake .. && cmake --build . --target Alpha101 --config Release -j
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ endif()
file(GLOB_RECURSE KunTestSrc ${PROJECT_SOURCE_DIR}/tests/cpp/*.cpp)
add_library(KunTest SHARED EXCLUDE_FROM_ALL ${KunTestSrc})
target_link_libraries(KunTest KunRunner)
if(NOT DEFINED PYTHON_EXECUTABLE)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
endif()

message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")

add_subdirectory(projects)
12 changes: 6 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ g++=11.4.0
* Python (3.7+ with f-string and dataclass support)
* cmake
* A working C++ compiler with C++11 support (e.g. clang, g++, msvc)
* x64 CPU with at least AVX2-FMA instruction set
* x86-64 CPU with at least AVX2-FMA instruction set

**Important node**: Currently KunQuant only supports a multiple of 8 as the number of stocks as inputs. That is, you can only input 8, 16, 24, ..., etc. stocks in a batch.

Expand Down Expand Up @@ -83,9 +83,9 @@ If the build is successful, you should be able to see in the terminal:
[100%] Built target Alpha101
```

You can find `KunRunner.cpython-??-{x86_64-linux-gnu.so,amd64.pyd}` and `projects/Alpha101/{libAlpha101.so, Alpha101.dll}` in your build directory.
You can find `KunRunner.cpython-??-{x86_64-linux-gnu.so, amd64.pyd, darwin.so}` and `projects/{libAlpha101.so, libAlpha101.dylib}` (on Linux/macOS) or `projects/Release/Alpha101.dll` (on Windows) in your build directory.

`libAlpha101.so` or `Alpha101.dll` is the compiled code for Alpha101 factors on Linux or Windows. KunRunner is a Cpp extension for Python with helps to load the generated factor libraries. It also contains some supportive functions for the loaded libraries.
`libAlpha101.so`, `Alpha101.dll` or `libAlpha101.dylib` is the compiled code for Alpha101 factors on Linux, Windows or macOS. KunRunner is a Cpp extension for Python with helps to load the generated factor libraries. It also contains some supportive functions for the loaded libraries.

Before running Python, set the environment variable of `PYTHONPATH`:

Expand All @@ -101,7 +101,7 @@ On windows powershell
$env:PYTHONPATH+=";x:\PATH\TO\KunQuant\build\Release"
```

Note that `/PATH/TO/KunQuant/build` or `x:\PATH\TO\KunQuant\build` should be the directory containing `KunRunner.cpython-...{pyd,so}`
Note that `/PATH/TO/KunQuant/build` or `x:\PATH\TO\KunQuant\build\Release` should be the directory containing `KunRunner.cpython-...{pyd,so}`

Then in Python, import KunRunner and load the Alpha101 library:

Expand All @@ -111,7 +111,7 @@ lib = kr.Library.load("./projects/libAlpha101.so")
modu = lib.getModule("alpha_101")
```

Note that you need to give KunRunner a relative or absolute path of the factor library.
Note that you need to give KunRunner a relative or absolute path of the factor library by replacing "./projects/libAlpha101.so" above.

Load your stock data. In this example, load from local pandas files. We assume the open, close, high, low, volumn and amount data for different stocks are stored in different files.

Expand Down Expand Up @@ -179,7 +179,7 @@ transposed = np.ascontiguousarray(transposed)

Now fill the input data in a dict

```
```python
input_dict = dict()
for colname, colidx in col2idx.items():
input_dict[colname] = transposed[colidx]
Expand Down
7 changes: 4 additions & 3 deletions cpp/Kun/Ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,10 @@ struct ReduceRank {
ReduceRank(f32x8 cur) : v{cur} {}
void step(f32x8 input, size_t index) {
using namespace kun_simd;
auto is_nan = sc_isnan(v, input);
auto cmpless = input < v;
auto cmpeq = input == v;
vec_f32x8 input2 = input;
auto is_nan = sc_isnan(v, input2);
auto cmpless = input2 < v;
auto cmpeq = input2 == v;
less_count = sc_select(is_nan, NAN, less_count);
less_count = sc_select(cmpless, less_count + 1.0f, less_count);
eq_count = sc_select(cmpeq, eq_count + 1.0f, eq_count);
Expand Down
4 changes: 2 additions & 2 deletions cpp/KunSIMD/cpu/Math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace kun_simd {

KUN_API alignas(64) extern const uint32_t log_const_table1[32];
KUN_API alignas(64) extern const uint32_t log_const_table2[32];
KUN_API extern const uint32_t log_const_table1[32];
KUN_API extern const uint32_t log_const_table2[32];

template <typename T, int lanes>
inline vec<T, lanes> log(vec<T, lanes> inval) {
Expand Down

0 comments on commit 6eeed1b

Please sign in to comment.