Skip to content

Commit

Permalink
add a job to test KNI in pack-nsis
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-at-orange committed Feb 29, 2024
1 parent 3d0bab8 commit a148594
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 73 deletions.
55 changes: 37 additions & 18 deletions .github/actions/test-kni/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ runs:
shell: cmd
run: |
call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"
set KNI_HOME=%RUNNER_TEMP%\\KNI
cd tutorial
call %GITHUB_WORKSPACE%/packaging/common/KNI/build-c--windows.cmd
- name: Test mono-table example
set KNI_HOME=%GITHUB_WORKSPACE%/KNI
call %GITHUB_WORKSPACE%/packaging/common/KNI/build-c-windows.cmd
- name: Run mono-table example (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
./tutorial/KNIRecodeFile tutorial/data/ModelingIris.kdic SNB_Iris tutorial/data/Iris.txt R_Iris.txt || true
- name: Run mono-table example (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |
set path=%GITHUB_WORKSPACE%/KNI/bin;%path%
call %GITHUB_WORKSPACE%/tutorial/KNIRecodeFile.exe tutorial/data/ModelingIris.kdic SNB_Iris tutorial/data/Iris.txt R_Iris.txt
- name: Check mono-table example
shell: bash
run: |
./tutorial/KNIRecodeFile tutorial/data/ModelingIris.kdic SNB_Iris tutorial/data/Iris.txt R_Iris.txt
if [ ! -f R_Iris.txt ] ;
then
echo "::error::R_Iris.txt is missing"
Expand All @@ -49,14 +59,25 @@ runs:
then
echo "Mono table recoding is OK"
else
echo "::error::Recoding issue with Iris.txt"
echo "::error::Recoding issue with Iris.txt"
false
fi
- name: Test multi-tables example
- name: Run multi-tables example (Linux)
if: runner.os == 'Linux'
shell: bash
run: |-
./tutorial/KNIRecodeMTFiles -d tutorial/data/ModelingSpliceJunction.kdic SNB_SpliceJunction \
-i tutorial/data/SpliceJunction.txt 1 -s DNA tutorial/data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt
-i tutorial/data/SpliceJunction.txt 1 -s DNA tutorial/data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt || true
- name: Run multi-tables example (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |-
set path=%GITHUB_WORKSPACE%/KNI/bin;%path%
call %GITHUB_WORKSPACE%/tutorial/KNIRecodeMTFiles.exe -d tutorial/data/ModelingSpliceJunction.kdic SNB_SpliceJunction ^
-i tutorial/data/SpliceJunction.txt 1 -s DNA tutorial/data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt
- name: Check multi-table example
shell: bash
run: |
if [ ! -f R_SpliceJunction.txt ] ;
then
echo "::error::R_SpliceJunction.txt is missing"
Expand All @@ -70,30 +91,27 @@ runs:
false
fi
- name: setup jna
uses: nvoxland/jar-download-action@v1
with:
groupId: net.java.dev.jna
artifactId: jna
version: 5.13.0
outputDirectory: ./tutorial/java/
shell: bash
run: |
curl https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.13.0/jna-5.13.0.jar --output ./tutorial/jna.jar
- name: Compile java example
shell: bash
run: |
cd tutorial
bash $GITHUB_WORKSPACE/packaging/common/KNI/build-java.sh
cd $GITHUB_WORKSPACE
- name: Run java example (Linux)
shell: bash
if: runner.os == 'Linux'
run: |
cd tutorial
bash $GITHUB_WORKSPACE/packaging/common/KNI/run-java-linux.sh
- name: Test java example (Windows)
shell: bash
shell: cmd
if: runner.os == 'Windows'
run: |
cd tutorial
bash $GITHUB_WORKSPACE/packaging/common/KNI/run-java-windows.sh
set KNI_HOME=%GITHUB_WORKSPACE%/KNI
call %GITHUB_WORKSPACE%/packaging/common/KNI/run-java-windows.cmd
- name: Check java results
shell: bash
run: |-
Expand All @@ -102,10 +120,11 @@ runs:
echo "::error::R_Iris_java.txt is missing"
false
fi
if diff -q tutorial/R_Iris_java.txt $GITHUB_WORKSPACE/packaging/common/KNI/results.ref/R_Iris.txt > /dev/null ;
if diff -q tutorial/R_Iris_java.txt packaging/common/KNI/results.ref/R_Iris.txt > /dev/null ;
then
echo "Mono table recoding is OK"
true
else
echo "::error::Recoding issue with java"
echo "::error::Recoding issue with java"
false
fi
21 changes: 19 additions & 2 deletions .github/workflows/pack-nsis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
with:
name: KNI
path: ./build/windows-msvc-release/packages/KNI-${{ env.KHIOPS_VERSION }}.zip
test:
test-khiops:
needs: build
runs-on: windows-2019
steps:
Expand All @@ -123,10 +123,27 @@ jobs:
uses: actions/checkout@v4
- name: Test the installation
uses: ./.github/actions/test-khiops-install
test-kni:
needs: build
runs-on: windows-2022
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Download KNI zip
uses: actions/download-artifact@v4
with:
name: KNI
- name: Install KNI
shell: bash
run: |
7z x KNI-${{ needs.build.outputs.khiops-version }}.zip -o${GITHUB_WORKSPACE}/KNI
- name: Test KNI zip
uses: ./.github/actions/test-kni

# Release is only executed on tags
release:
if: github.ref_type == 'tag'
needs: [build, test]
needs: [build, test-khiops, test-kni]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-kni-tutorial.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Update KhiopsNativeInterface-tutorial repository
name: Update KNI-tutorial repository
on:
workflow_dispatch:
jobs:
Expand Down
43 changes: 23 additions & 20 deletions packaging/common/KNI/README.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@ Khiops Native Interface @PROJECT_VERSION@
==============================

The purpose of Khiops Native Interface (KNI) is to allow a deeper integration
of Khiops in information systems, by mean of the C programming language, using
a dynamic link library (DLL). This relates specially to the problem of model
deployment, which otherwise requires the use of input and output data files
when using directly the Khiops tool in batch mode. See Khiops Guide for an
introduction to dictionary files, dictionaries, database files and deployment.

The Khiops deployment features are thus made public through an API with a DLL.
of Khiops in information systems, by means of the C programming language, using
a shared library (`.dll` in Windows or `.so` in Linux). This relates specially
to the problem of model deployment, which otherwise requires the use of input
and output data files when using directly the Khiops tool in batch mode. See
Khiops Guide for an introduction to dictionary files, dictionaries, database files
and deployment.

The Khiops deployment API is made public through a shared library.
Therefore, a Khiops model can be deployed directly from any programming
language, such as C, C++, Java, Python, Matlab, etc. This enables real time
model deployment without the overhead of temporary data files or launching
executables. This is critical for certain applications in marketing or targeted
advertising on the web.
executables. This is critical for certain applications, such as marketing or
targeted advertising on the web..

All KNI functions are C functions for easy use with other programming languages.
They return a positive or null value in case of success, and a negative error
code in case of failure. The functions are not reentrant (thread-safe): the DLL
They return a positive or zero value in case of success, and a negative error
code in case of failure.

**Warning** The functions are not reentrant (thread-safe): the library
can be used simultaneously by several executables, but not simultaneously by
several threads in the same executable.

See KhiopsNativeInterface.h for a detailed description of KNI functions and go
to https://github.com/KhiopsML/KNI-tutorial/tree/@PROJECT_VERSION@ to see how
to use the DLL with Java and C.
See KhiopsNativeInterface.h for a detailed description of KNI functions and
for examples of use in Java and C go to the KNI tutorial repo
https://github.com/KhiopsML/KNI-tutorial/tree/@PROJECT_VERSION@.

Files
-----
Expand All @@ -32,12 +35,12 @@ README.txt: this file

LICENSE: license file

bin: DLL for windows
KhiopsNativeInterface64.dll: windows 64 bits
bin: DLL for Windows
KhiopsNativeInterface.dll: windows 64 bits

include: include file, with a detailed description of KNI functions
KhiopsNativeInterface.h

lib:
- librairy for windows C/C++ bindings: KhiopsNativeInterface64.lib (64 bits)
- shared library for linux libKhiopsNativeInterface.so.@PROJECT_VERSION@
lib:
- library for Windows C/C++ bindings: KhiopsNativeInterface.lib (64 bits)
- shared library for Linux libKhiopsNativeInterface.so.@PROJECT_VERSION@
6 changes: 4 additions & 2 deletions packaging/common/KNI/build-c-windows.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
cl cpp/KNIRecodeFile.c %KNI_HOME%\lib\KhiopsNativeInterface64.lib -I %KNI_HOME%\include /link "/LIBPATH:%KNI_HOME%\bin"
cl cpp/KNIRecodeMTFiles.c %KNI_HOME%\lib\KhiopsNativeInterface64.lib -I %KNI_HOME%\include /link "/LIBPATH:%KNI_HOME%\bin"
cl cpp/KNIRecodeFile.c %KNI_HOME%\lib\KhiopsNativeInterface.lib ^
-I %KNI_HOME%\include /link "/LIBPATH:%KNI_HOME%\bin"
cl cpp/KNIRecodeMTFiles.c %KNI_HOME%\lib\KhiopsNativeInterface.lib ^
-I %KNI_HOME%\include /link "/LIBPATH:%KNI_HOME%\bin"
5 changes: 2 additions & 3 deletions packaging/common/KNI/build-java.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
cd java
javac -cp jna-5.13.0.jar KNIRecodeFile.java KNI.java
jar cf kni.jar *.class
javac -cp jna.jar java/KNIRecodeFile.java java/KNI.java
jar cf kni.jar -C java KNI.class -C java KNIRecodeFile.class
3 changes: 2 additions & 1 deletion packaging/common/KNI/run-java-linux.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
java -cp java/kni.jar:java/jna-5.13.0.jar KNIRecodeFile data/ModelingIris.kdic SNB_Iris data/Iris.txt R_Iris_java.txt 2>&1
java -cp kni.jar:jna.jar KNIRecodeFile data/ModelingIris.kdic SNB_Iris \
data/Iris.txt R_Iris_java.txt
3 changes: 3 additions & 0 deletions packaging/common/KNI/run-java-windows.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set path=%KNI_HOME%/bin;%path%
java -cp kni.jar;jna.jar KNIRecodeFile data/ModelingIris.kdic ^
SNB_Iris data/Iris.txt R_Iris_java.txt
1 change: 0 additions & 1 deletion packaging/common/KNI/run-java-windows.sh

This file was deleted.

39 changes: 18 additions & 21 deletions packaging/common/KNI/template-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@

This project provides all the basics to use the Khiops Native Interface (KNI): installation and examples.

The purpose of KNI is to allow a deeper integration of Khiops in information systems, by mean of the C programming language, using a dynamic link library (DLL). This relates specially to the problem of model deployment, which otherwise requires the use of input and output data files when using directly the Khiops tool in batch mode. See Khiops Guide for an introduction to dictionary files, dictionaries, database files and deployment.
The purpose of KNI is to allow a deeper integration of Khiops in information systems, by mean of the C programming language, using a shared library (`.dll` in Windows, `.so` in Linux). This relates specially to the problem of model deployment, which otherwise requires the use of input and output data files when using directly the Khiops tool in batch mode. See Khiops Guide for an introduction to dictionary files, dictionaries, database files and deployment.

The Khiops deployment features are thus made public through an API with a DLL. Therefore, a Khiops model can be deployed directly from any programming language, such as C, C++, Java, Python, Matlab, etc. This enables real time model deployment without the overhead of temporary data files or launching executables. This is critical for certain applications in marketing or targeted advertising on the web.
The Khiops deployment API is thus made public through a shared library. Therefore, a Khiops model can be deployed directly from any programming language, such as C, C++, Java, Python, Matlab, etc. This enables real time model deployment without the overhead of temporary data files or launching executables. This is critical for certain applications, such as marketing or targeted advertising on the web..

All KNI functions are C functions for easy use with other programming languages. They return a positive or null value in case of success, and a negative error code in case of failure.
All KNI functions are C functions for easy use with other programming languages. They return a positive or zero value in case of success, and a negative error code in case of failure.

See [KhiopsNativeInterface.h](include/KhiopsNativeInterface.h) for a detailed description of KNI functions.

> [!CAUTION]
> The functions are not reentrant (thread-safe): the DLL can be used simultaneously by several executables, but not simultaneously by several threads in the same executable.


> The functions are not reentrant (thread-safe): the library can be used simultaneously by several executables, but not simultaneously by several threads in the same executable.
# KNI installation

Expand All @@ -25,7 +22,7 @@ Download [KNI-@[email protected]](https://github.com/KhiopsML/khiops/releases

## Linux

On linux, go to the [release page](https://github.com/KhiopsML/khiops/releases/tag/@PROJECT_VERSION@/) and download the kni package. The name of the package begins with **kni** and ends with the **code name** of the OS. The code name is in the release file of the distribution (here, it is jammy):
On Linux, go to the [release page](https://github.com/KhiopsML/khiops/releases/tag/@PROJECT_VERSION@/) and download the KNI package. The name of the package begins with **kni** and ends with the **code name** of the OS. The code name is in the release file of the distribution (here, it is "jammy"):
```bash
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.4 LTS"
Expand All @@ -41,9 +38,9 @@ BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
```
Download the package according to the code name of your OS and install it with dpkg or yum:
- on debian-like distros: `sudo dpkg -i kni*.deb`
- on fedora-like distros: `sudo yum localinstall kni*.rpm`
Download the package according to the code name of your OS and install it with `dpkg` or `yum`:
- on Debian-like distros: `sudo dpkg -i kni*.deb`
- on Fedora-like distros: `sudo yum localinstall kni*.rpm`

# Application examples

Expand All @@ -56,7 +53,7 @@ KNIRecodeFile <Dictionary file> <Dictionary> <Input File> <Output File> [Error f
# The error file may be useful for debugging purposes. It is optional and may be empty.
```

A more complex example (available only in C) is `KNIRecodeMTFiles`, it recodes a set of multi-tables input files to an output file.
A more complex example (available only in C) is `KNIRecodeMTFiles`, it recodes the input files of multi-table dataset to a single output file.

```bash
KNIRecodeMTFiles
Expand All @@ -76,31 +73,31 @@ The files are located in [cpp directory](cpp/). They allow to build `KNIRecodeFi
## Building the examples
On linux:
On Linux:
```bash
@BUILD_C_LINUX@
```
On windows, open a "Visual Studio Developer Console" and run:
On Windows, open a "Visual Studio Developer Console" and run:
```cmd
@BUILD_C_WINDOWS@
```
## Launch
Recode the iris dataset from the data directory using the SNB_Iris dictionary.
Recode the "Iris" dataset from the data directory using the SNB_Iris dictionary.
```bash
KNIRecodeFile data/ModelingIris.kdic SNB_Iris data/Iris.txt R_Iris.txt
```
Recode the splice junction multi-table dataset using the SNB_SpliceJunction dictionary.
Recode the "Splice Junction" multi-table dataset using the `SNB_SpliceJunction` classifier dictionary.
```bash
KNIRecodeMTFiles -d data/ModelingSpliceJunction.kdic SNB_SpliceJunction -i .data/SpliceJunction.txt 1 \
-s DNA data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt
KNIRecodeMTFiles -d data/ModelingSpliceJunction.kdic SNB_SpliceJunction \
-i .data/SpliceJunction.txt 1 -s DNA data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt
```
# Example with Java
Expand All @@ -109,15 +106,15 @@ The files are located in [java directory](java/). They allow to build `KNIRecode
## Building the examples
To compile Java files and create kni.jar file:
To compile Java files and create the `kni.jar` file:
```bash
@BUILD_JAVA@
```
## Launch
Recodes the iris dataset from the data directory using the SNB_Iris dictionary.
Recodes the "Iris" dataset from the data directory using the `SNB_Iris` classifier dictionary.
On Linux:
Expand All @@ -127,6 +124,6 @@ On Linux:
On Windows:
```bash
```cmd
@RUN_JAVA_WINDOWS@
```
2 changes: 1 addition & 1 deletion packaging/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/build-c-linux.sh BUILD_C_LI
file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/build-c-windows.cmd BUILD_C_WINDOWS)
file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/build-java.sh BUILD_JAVA)
file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/run-java-linux.sh RUN_JAVA_LINUX)
file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/run-java-windows.sh RUN_JAVA_WINDOWS)
file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/run-java-windows.cmd RUN_JAVA_WINDOWS)

configure_file(${PROJECT_SOURCE_DIR}/packaging/common/KNI/README.txt.in ${TMP_DIR}/kni.README.txt @ONLY
NEWLINE_STYLE UNIX)
Expand Down
6 changes: 3 additions & 3 deletions packaging/packaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ The Khiops deployment features are thus made public through an API with a DLL.
Therefore, a Khiops model can be deployed directly from any programming
language, such as C, C++, Java, Python, Matlab, etc. This enables real time
model deployment without the overhead of temporary data files or launching
executables. This is critical for certain applications in marketing or targeted
advertising on the web.
executables. This is critical for certain applications, such as marketing or
targeted advertising on the web.
.
All KNI functions are C functions for easy use with other programming languages.
They return a positive or null value in case of success, and a negative error
They return a positive or zero value in case of success, and a negative error
code in case of failure. The functions are not reentrant (thread-safe): the DLL
can be used simultaneously by several executables, but not simultaneously by
several threads in the same executable.
Expand Down

0 comments on commit a148594

Please sign in to comment.