Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add presets for LZ4 #1094

Merged
merged 10 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/lz4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: lz4
on:
push:
paths:
- lz4/**
pull_request:
paths:
- lz4/**
workflow_dispatch:
env:
CI_DEPLOY_MODULE: ${{ github.workflow }}
CI_DEPLOY_PLATFORM: ${{ github.job }}
CI_DEPLOY_SETTINGS: ${{ secrets.CI_DEPLOY_SETTINGS }}
CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }}
CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }}
STAGING_REPOSITORY: ${{ secrets.STAGING_REPOSITORY }}
jobs:
linux-x86:
runs-on: ubuntu-18.04
container: centos:7
steps:
- uses: bytedeco/javacpp-presets/.github/actions/deploy-centos@actions
linux-x86_64:
runs-on: ubuntu-18.04
container: centos:7
steps:
- uses: bytedeco/javacpp-presets/.github/actions/deploy-centos@actions
macosx-x86_64:
runs-on: macos-10.15
steps:
- uses: bytedeco/javacpp-presets/.github/actions/deploy-macosx@actions
windows-x86:
runs-on: windows-2019
steps:
- uses: bytedeco/javacpp-presets/.github/actions/deploy-windows@actions
windows-x86_64:
runs-on: windows-2019
steps:
- uses: bytedeco/javacpp-presets/.github/actions/deploy-windows@actions
redeploy:
needs: [linux-x86, linux-x86_64, macosx-x86_64, windows-x86, windows-x86_64]
runs-on: ubuntu-18.04
steps:
- uses: bytedeco/javacpp-presets/.github/actions/redeploy@actions
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

* Include new `llvm-c/Transforms/PassBuilder.h` header file in presets for LLVM ([pull #1093](https://github.com/bytedeco/javacpp-presets/pull/1093))
* Introduce `macosx-arm64` builds to presets for LLVM ([pull #1092](https://github.com/bytedeco/javacpp-presets/pull/1092))
* Add presets for Triton Inference Server 2.14 ([pull #1085](https://github.com/bytedeco/javacpp-presets/pull/1085))
* Add presets for LZ4 1.9.3 ([pull #1094](https://github.com/bytedeco/javacpp-presets/pull/1094)), Triton Inference Server 2.14 ([pull #1085](https://github.com/bytedeco/javacpp-presets/pull/1085))
* Add presets for the NvToolsExt (NVTX) module of CUDA ([issue #1068](https://github.com/bytedeco/javacpp-presets/issues/1068))
* Increase the amount of function pointers available for callbacks in presets for Qt ([pull #1080](https://github.com/bytedeco/javacpp-presets/pull/1080))
* Map C++ JIT classes and functions of TorchScript in presets for PyTorch ([issue #1068](https://github.com/bytedeco/javacpp-presets/issues/1068))
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ JavaCPP Presets
[![arrow](https://github.com/bytedeco/javacpp-presets/workflows/arrow/badge.svg)](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Aarrow)
[![hdf5](https://github.com/bytedeco/javacpp-presets/workflows/hdf5/badge.svg)](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Ahdf5)
[![hyperscan](https://github.com/bytedeco/javacpp-presets/workflows/hyperscan/badge.svg)](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Ahyperscan)
[![lz4](https://github.com/bytedeco/javacpp-presets/workflows/lz4/badge.svg)](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Alz4)
[![mkl](https://github.com/bytedeco/javacpp-presets/workflows/mkl/badge.svg)](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Amkl)
[![mkl-dnn](https://github.com/bytedeco/javacpp-presets/workflows/mkl-dnn/badge.svg)](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Amkl-dnn)
[![dnnl](https://github.com/bytedeco/javacpp-presets/workflows/dnnl/badge.svg)](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Adnnl)
Expand Down Expand Up @@ -186,6 +187,7 @@ Each child module in turn relies by default on the included [`cppbuild.sh` scrip
* Arrow 5.0.x https://arrow.apache.org/install/
* HDF5 1.12.x https://www.hdfgroup.org/downloads/
* Hyperscan 5.4.x https://github.com/intel/hyperscan
* LZ4 1.9.x https://github.com/lz4/lz4
* MKL 2021.x https://software.intel.com/mkl
* MKL-DNN 0.21.x https://github.com/oneapi-src/oneDNN
* DNNL 2.4.x https://github.com/oneapi-src/oneDNN
Expand Down
2 changes: 1 addition & 1 deletion cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function sedinplace {
}

if [[ -z ${PROJECTS:-} ]]; then
PROJECTS=(opencv ffmpeg flycapture spinnaker libdc1394 libfreenect libfreenect2 librealsense librealsense2 videoinput artoolkitplus chilitags flandmark arrow hdf5 hyperscan mkl mkl-dnn dnnl openblas arpack-ng cminpack fftw gsl cpython numpy scipy gym llvm libpostal leptonica tesseract caffe openpose cuda nvcodec opencl mxnet pytorch tensorflow tensorflow-lite tensorrt tritonserver depthai ale onnx ngraph onnxruntime tvm liquidfun qt skia cpu_features modsecurity systems)
PROJECTS=(opencv ffmpeg flycapture spinnaker libdc1394 libfreenect libfreenect2 librealsense librealsense2 videoinput artoolkitplus chilitags flandmark arrow hdf5 hyperscan lz4 mkl mkl-dnn dnnl openblas arpack-ng cminpack fftw gsl cpython numpy scipy gym llvm libpostal leptonica tesseract caffe openpose cuda nvcodec opencl mxnet pytorch tensorflow tensorflow-lite tensorrt tritonserver depthai ale onnx ngraph onnxruntime tvm liquidfun qt skia cpu_features modsecurity systems)
fi

for PROJECT in ${PROJECTS[@]}; do
Expand Down
24 changes: 24 additions & 0 deletions lz4/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
LZ4 Library
Copyright (c) 2011-2020, Yann Collet
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155 changes: 155 additions & 0 deletions lz4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
JavaCPP Presets for LZ4
=======================

[![Gitter](https://badges.gitter.im/bytedeco/javacpp.svg)](https://gitter.im/bytedeco/javacpp) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/lz4/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/lz4) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.bytedeco/lz4.svg)](http://bytedeco.org/builds/)
<sup>Build status for all platforms:</sup> [![lz4](https://github.com/bytedeco/javacpp-presets/workflows/lz4/badge.svg)](https://github.com/bytedeco/javacpp-presets/actions?query=workflow%3Alz4) <sup>Commercial support:</sup> [![xscode](https://img.shields.io/badge/Available%20on-xs%3Acode-blue?style=?style=plastic&logo=appveyor&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////////VXz1bAAAAAJ0Uk5T/wDltzBKAAAAlUlEQVR42uzXSwqAMAwE0Mn9L+3Ggtgkk35QwcnSJo9S+yGwM9DCooCbgn4YrJ4CIPUcQF7/XSBbx2TEz4sAZ2q1RAECBAiYBlCtvwN+KiYAlG7UDGj59MViT9hOwEqAhYCtAsUZvL6I6W8c2wcbd+LIWSCHSTeSAAECngN4xxIDSK9f4B9t377Wd7H5Nt7/Xz8eAgwAvesLRjYYPuUAAAAASUVORK5CYII=)](https://xscode.com/bytedeco/javacpp-presets)


Introduction
------------
This directory contains the JavaCPP Presets module for:

* LZ4 1.9.3 https://github.com/lz4/lz4/

Please refer to the parent README.md file for more detailed information about the JavaCPP Presets.


Documentation
-------------
Java API documentation is available here:

* http://bytedeco.org/javacpp-presets/lz4/apidocs/


Sample Usage
------------
Here is a simple example of LZ4 frame compression.

We can use [Maven 3](http://maven.apache.org/) to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the `pom.xml` and `LZ4FrameCompressionExample.java` source files below, simply execute on the command line:
```bash
$ mvn compile exec:java
```

### The `pom.xml` build file
```xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco.lz4</groupId>
<artifactId>lz4-frame-compression-example</artifactId>
<version>1.5.7-SNAPSHOT</version>
<properties>
<exec.mainClass>LZ4FrameCompressionExample</exec.mainClass>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>lz4-platform</artifactId>
<version>1.9.3-1.5.7-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>.</sourceDirectory>
</build>
</project>
```

### The `LZ4FrameCompressionExample.java` source file
```java
import java.nio.ByteBuffer;
import org.bytedeco.javacpp.*;
import org.bytedeco.lz4.*;
import org.bytedeco.lz4.global.lz4;

public final class LZ4FrameCompressionExample {

private static final int NUM_VALUES = 10 * 1024 * 1024; // 10MB

public static void main(String[] args) throws LZ4Exception {
// Print LZ4 version
System.out.println("LZ4 Version: " + lz4.LZ4_VERSION_STRING.getString());

// Generate some data
final ByteBuffer data = ByteBuffer.allocateDirect(NUM_VALUES);
for (int i = 0; i < NUM_VALUES; i++) {
data.put((byte) i);
}
data.position(0);

// Compress
final ByteBuffer compressed = compress(data);
System.out.println("Uncompressed size: " + data.limit());
System.out.println("Compressed size: " + compressed.limit());

// Decompress
final ByteBuffer decompressed = decompress(compressed, data.limit());

// Verify that decompressed == data
for (int i = 0; i < NUM_VALUES; i++) {
if (data.get(i) != decompressed.get(i)) {
throw new IllegalStateException("Input and output differ.");
}
}
System.out.println("Verified that input data == output data");
}

private static ByteBuffer compress(ByteBuffer data) {
// Output buffer
final int maxCompressedSize = (int) lz4.LZ4F_compressFrameBound(data.limit(), null);
final ByteBuffer compressed = ByteBuffer.allocateDirect(maxCompressedSize);

final Pointer dataPointer = new Pointer(data);
final Pointer dstPointer = new Pointer(compressed);
final long compressedSize = lz4.LZ4F_compressFrame(dstPointer, compressed.limit(), dataPointer, data.limit(),
null);
compressed.limit((int) compressedSize);
return compressed;
}

private static ByteBuffer decompress(ByteBuffer compressed, int uncompressedSize) throws LZ4Exception {
final LZ4FDecompressionContext dctx = new LZ4FDecompressionContext();
final long ctxError = lz4.LZ4F_createDecompressionContext(dctx, lz4.LZ4F_VERSION);
checkForError(ctxError);

// Output buffer
final ByteBuffer decompressed = ByteBuffer.allocateDirect(uncompressedSize);

final SizeTPointer dstSize = new SizeTPointer(1);
final SizeTPointer srcSize = new SizeTPointer(1);

try {
long ret;
do {
dstSize.put(decompressed.remaining());
srcSize.put(compressed.limit());
final Pointer dstPointer = new Pointer(decompressed);
final Pointer compressedPointer = new Pointer(compressed);

ret = lz4.LZ4F_decompress(dctx, dstPointer, dstSize, compressedPointer, srcSize, null);
checkForError(ret);
decompressed.position(decompressed.position() + (int) dstSize.get());
compressed.position(compressed.position() + (int) srcSize.get());
} while (ret != 0);

} finally {
lz4.LZ4F_freeDecompressionContext(dctx);
}

decompressed.position(0);
return decompressed;
}

private static void checkForError(long errorCode) throws LZ4Exception {
if (lz4.LZ4F_isError(errorCode) != 0) {
throw new LZ4Exception(lz4.LZ4F_getErrorName(errorCode).getString());
}
}

private static final class LZ4Exception extends Exception {
public LZ4Exception(final String message) {
super(message);
}
}
}
```
55 changes: 55 additions & 0 deletions lz4/cppbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
# This file is meant to be included by the parent cppbuild.sh script
if [[ -z "$PLATFORM" ]]; then
pushd ..
bash cppbuild.sh "$@" lz4
popd
exit
fi

LZ4_VERSION=1.9.3
download https://github.com/lz4/lz4/archive/refs/tags/v$LZ4_VERSION.tar.gz lz4-$LZ4_VERSION.tar.gz
mkdir -p $PLATFORM
cd $PLATFORM
INSTALL_PATH=`pwd`
tar -xzvf ../lz4-$LZ4_VERSION.tar.gz
cd lz4-$LZ4_VERSION

# TODO add other platforms
case $PLATFORM in
linux-x86)
CC="gcc -m32 -fPIC" make -j $MAKEJ
PREFIX=$INSTALL_PATH make install
;;
linux-x86_64)
CC="gcc -m64 -fPIC" make -j $MAKEJ
PREFIX=$INSTALL_PATH make install
;;
macosx-x86_64)
make -j $MAKEJ
PREFIX=$INSTALL_PATH make install
;;
windows-x86)
cd build/cmake
export CC="cl.exe"
export CXX="cl.exe"
"$CMAKE" -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DBUILD_SHARED_LIBS=OFF .
ninja -j $MAKEJ
ninja install
cd ../..
;;
windows-x86_64)
cd build/cmake
export CC="cl.exe"
export CXX="cl.exe"
"$CMAKE" -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DBUILD_SHARED_LIBS=OFF .
ninja -j $MAKEJ
ninja install
cd ../..
;;
*)
echo "Error: Platform \"$PLATFORM\" is not supported"
;;
esac

cd ../..
Loading