Skip to content

Commit

Permalink
* Add presets for the nvJPEG module of CUDA (issue #1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
devjeonghwan authored Jun 30, 2022
1 parent 7ce122a commit 12bb414
Show file tree
Hide file tree
Showing 23 changed files with 1,592 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Add presets for the nvJPEG module of CUDA ([issue #1193](https://github.com/bytedeco/javacpp-presets/issues/1193))
* Introduce Android builds for TensorFlow Lite ([discussion #1180](https://github.com/bytedeco/javacpp-presets/discussions/1180))
* Map `std::vector<cv::Ptr<cv::mcc::CChecker> >` for `CCheckerDetector.getListColorChecker()` ([issue bytedeco/javacpp#571](https://github.com/bytedeco/javacpp/issues/571))
* Include missing `opencv2/mcc/ccm.hpp` header file in presets for OpenCV ([discussion bytedeco/javacpp#568](https://github.com/bytedeco/javacpp/discussions/568))
Expand Down
127 changes: 127 additions & 0 deletions cuda/samples/SampleJpeg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright (C) 2022 Park JeongHwan
*
* Licensed either under the Apache License, Version 2.0, or (at your option)
* under the terms of the GNU General Public License as published by
* the Free Software Foundation (subject to the "Classpath" exception),
* either version 2, or any later version (collectively, the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.gnu.org/licenses/
* http://www.gnu.org/software/classpath/license.html
*
* or as provided in the LICENSE.txt file that accompanied this code.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.bytedeco.cuda.nvjpeg.*;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.PointerPointer;

import static org.bytedeco.cuda.global.cudart.*;
import static org.bytedeco.cuda.global.nvjpeg.*;

public class SampleJpeg {
static class dev_malloc extends tDevMalloc {
final static dev_malloc instance = new dev_malloc().retainReference();

@Override
public int call(PointerPointer pointerPointer, long l) {
return cudaMalloc(pointerPointer, l);
}
}

static class dev_free extends tDevFree {
final static dev_free instance = new dev_free().retainReference();

@Override
public int call(Pointer pointer) {
return cudaFree(pointer);
}
}

static class host_malloc extends tPinnedMalloc {
final static host_malloc instance = new host_malloc().retainReference();

@Override
public int call(PointerPointer pointerPointer, long l, int i) {
return cudaHostAlloc(pointerPointer, l, i);
}
}

static class host_free extends tPinnedFree {
final static host_free instance = new host_free().retainReference();

@Override
public int call(Pointer pointer) {
return cudaFreeHost(pointer);
}
}

public static void CHECK_NVJPEG(String functionName, int result) {
if (result != NVJPEG_STATUS_SUCCESS) {
throw new IllegalStateException(String.format("%s returned '%d'", functionName, result));
}
}

public static void main(String[] args) {
nvjpegDevAllocator_t devAllocator = new nvjpegDevAllocator_t();
devAllocator.dev_malloc(dev_malloc.instance);
devAllocator.dev_free(dev_free.instance);

nvjpegPinnedAllocator_t pinnedAllocator = new nvjpegPinnedAllocator_t();
pinnedAllocator.pinned_malloc(host_malloc.instance);
pinnedAllocator.pinned_free(host_free.instance);

nvjpegHandle handle = new nvjpegHandle();
nvjpegJpegState state = new nvjpegJpegState();

nvjpegJpegDecoder decoder = new nvjpegJpegDecoder();
nvjpegJpegState decoder_state = new nvjpegJpegState();

nvjpegBufferPinned[] pinned_buffers = new nvjpegBufferPinned[]{new nvjpegBufferPinned(), new nvjpegBufferPinned()};
nvjpegBufferDevice bufferDevice = new nvjpegBufferDevice();

nvjpegJpegStream[] streams = new nvjpegJpegStream[]{new nvjpegJpegStream(), new nvjpegJpegStream()};

nvjpegDecodeParams params = new nvjpegDecodeParams();

// Create Components
CHECK_NVJPEG("nvjpegCreateEx", nvjpegCreateEx(NVJPEG_BACKEND_DEFAULT, devAllocator, pinnedAllocator, NVJPEG_FLAGS_DEFAULT, handle));
CHECK_NVJPEG("nvjpegJpegStateCreate", nvjpegJpegStateCreate(handle, state));

CHECK_NVJPEG("nvjpegDecoderCreate", nvjpegDecoderCreate(handle, NVJPEG_BACKEND_DEFAULT, decoder));
CHECK_NVJPEG("nvjpegDecoderStateCreate", nvjpegDecoderStateCreate(handle, decoder, decoder_state));

CHECK_NVJPEG("nvjpegBufferPinnedCreate", nvjpegBufferPinnedCreate(handle, null, pinned_buffers[0]));
CHECK_NVJPEG("nvjpegBufferPinnedCreate", nvjpegBufferPinnedCreate(handle, null, pinned_buffers[1]));
CHECK_NVJPEG("nvjpegBufferDeviceCreate", nvjpegBufferDeviceCreate(handle, null, bufferDevice));

CHECK_NVJPEG("nvjpegJpegStreamCreate", nvjpegJpegStreamCreate(handle, streams[0]));
CHECK_NVJPEG("nvjpegJpegStreamCreate", nvjpegJpegStreamCreate(handle, streams[1]));

CHECK_NVJPEG("nvjpegDecodeParamsCreate", nvjpegDecodeParamsCreate(handle, params));

// Destroy Components
CHECK_NVJPEG("nvjpegDecodeParamsDestroy", nvjpegDecodeParamsDestroy(params));

CHECK_NVJPEG("nvjpegJpegStreamDestroy", nvjpegJpegStreamDestroy(streams[0]));
CHECK_NVJPEG("nvjpegJpegStreamDestroy", nvjpegJpegStreamDestroy(streams[1]));

CHECK_NVJPEG("nvjpegBufferPinnedDestroy", nvjpegBufferPinnedDestroy(pinned_buffers[0]));
CHECK_NVJPEG("nvjpegBufferPinnedDestroy", nvjpegBufferPinnedDestroy(pinned_buffers[1]));
CHECK_NVJPEG("nvjpegBufferDeviceDestroy", nvjpegBufferDeviceDestroy(bufferDevice));

CHECK_NVJPEG("nvjpegJpegStateDestroy", nvjpegJpegStateDestroy(decoder_state));
CHECK_NVJPEG("nvjpegDecoderDestroy", nvjpegDecoderDestroy(decoder));

CHECK_NVJPEG("nvjpegJpegStateDestroy", nvjpegJpegStateDestroy(state));
CHECK_NVJPEG("nvjpegDestroy", nvjpegDestroy(handle));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ public class CUstreamBatchMemOpParams_v1 extends Pointer {
@Name("waitValue.operation") public native @Cast("CUstreamBatchMemOpType") int waitValue_operation(); public native CUstreamBatchMemOpParams_v1 waitValue_operation(int setter);
@Name("waitValue.address") public native @Cast("CUdeviceptr") long waitValue_address(); public native CUstreamBatchMemOpParams_v1 waitValue_address(long setter);
@Name("waitValue.value") public native @Cast("cuuint32_t") int waitValue_value(); public native CUstreamBatchMemOpParams_v1 waitValue_value(int setter);
@Name("waitValue.value64") public native @Cast("cuuint64_t") int waitValue_value64(); public native CUstreamBatchMemOpParams_v1 waitValue_value64(int setter);
@Name("waitValue.value64") public native @Cast("cuuint64_t") long waitValue_value64(); public native CUstreamBatchMemOpParams_v1 waitValue_value64(long setter);
@Name("waitValue.flags") public native @Cast("unsigned int") int waitValue_flags(); public native CUstreamBatchMemOpParams_v1 waitValue_flags(int setter);
/** For driver internal use. Initial value is unimportant. */
@Name("waitValue.alias") public native @Cast("CUdeviceptr") long waitValue_alias(); public native CUstreamBatchMemOpParams_v1 waitValue_alias(long setter);
@Name("writeValue.operation") public native @Cast("CUstreamBatchMemOpType") int writeValue_operation(); public native CUstreamBatchMemOpParams_v1 writeValue_operation(int setter);
@Name("writeValue.address") public native @Cast("CUdeviceptr") long writeValue_address(); public native CUstreamBatchMemOpParams_v1 writeValue_address(long setter);
@Name("writeValue.value") public native @Cast("cuuint32_t") int writeValue_value(); public native CUstreamBatchMemOpParams_v1 writeValue_value(int setter);
@Name("writeValue.value64") public native @Cast("cuuint64_t") int writeValue_value64(); public native CUstreamBatchMemOpParams_v1 writeValue_value64(int setter);
@Name("writeValue.value64") public native @Cast("cuuint64_t") long writeValue_value64(); public native CUstreamBatchMemOpParams_v1 writeValue_value64(long setter);
@Name("writeValue.flags") public native @Cast("unsigned int") int writeValue_flags(); public native CUstreamBatchMemOpParams_v1 writeValue_flags(int setter);
/** For driver internal use. Initial value is unimportant. */
@Name("writeValue.alias") public native @Cast("CUdeviceptr") long writeValue_alias(); public native CUstreamBatchMemOpParams_v1 writeValue_alias(long setter);
@Name("flushRemoteWrites.operation") public native @Cast("CUstreamBatchMemOpType") int flushRemoteWrites_operation(); public native CUstreamBatchMemOpParams_v1 flushRemoteWrites_operation(int setter);
@Name("flushRemoteWrites.flags") public native @Cast("unsigned int") int flushRemoteWrites_flags(); public native CUstreamBatchMemOpParams_v1 flushRemoteWrites_flags(int setter);
public native @Cast("cuuint64_t") int pad(int i); public native CUstreamBatchMemOpParams_v1 pad(int i, int setter);
@MemberGetter public native @Cast("cuuint64_t*") IntPointer pad();
public native @Cast("cuuint64_t") long pad(int i); public native CUstreamBatchMemOpParams_v1 pad(int i, long setter);
@MemberGetter public native @Cast("cuuint64_t*") LongPointer pad();
}
22 changes: 11 additions & 11 deletions cuda/src/gen/java/org/bytedeco/cuda/global/cudart.java
Original file line number Diff line number Diff line change
Expand Up @@ -11617,9 +11617,9 @@ typedef enum CUmemOperationType_enum {
* ::cuStreamBeginCapture,
* ::cuStreamIsCapturing
*/
public static native @Cast("CUresult") int cuStreamGetCaptureInfo(CUstream_st hStream, @Cast("CUstreamCaptureStatus*") IntPointer captureStatus_out, @Cast("cuuint64_t*") IntPointer id_out);
public static native @Cast("CUresult") int cuStreamGetCaptureInfo(CUstream_st hStream, @Cast("CUstreamCaptureStatus*") IntBuffer captureStatus_out, @Cast("cuuint64_t*") IntBuffer id_out);
public static native @Cast("CUresult") int cuStreamGetCaptureInfo(CUstream_st hStream, @Cast("CUstreamCaptureStatus*") int[] captureStatus_out, @Cast("cuuint64_t*") int[] id_out);
public static native @Cast("CUresult") int cuStreamGetCaptureInfo(CUstream_st hStream, @Cast("CUstreamCaptureStatus*") IntPointer captureStatus_out, @Cast("cuuint64_t*") LongPointer id_out);
public static native @Cast("CUresult") int cuStreamGetCaptureInfo(CUstream_st hStream, @Cast("CUstreamCaptureStatus*") IntBuffer captureStatus_out, @Cast("cuuint64_t*") LongBuffer id_out);
public static native @Cast("CUresult") int cuStreamGetCaptureInfo(CUstream_st hStream, @Cast("CUstreamCaptureStatus*") int[] captureStatus_out, @Cast("cuuint64_t*") long[] id_out);

/**
* \brief Query a stream's capture state (11.3+)
Expand Down Expand Up @@ -11674,11 +11674,11 @@ typedef enum CUmemOperationType_enum {
* ::cuStreamUpdateCaptureDependencies
*/
public static native @Cast("CUresult") int cuStreamGetCaptureInfo_v2(CUstream_st hStream, @Cast("CUstreamCaptureStatus*") IntPointer captureStatus_out,
@Cast("cuuint64_t*") IntPointer id_out, @ByPtrPtr CUgraph_st graph_out, @Cast("const CUgraphNode**") @ByPtrPtr PointerPointer dependencies_out, @Cast("size_t*") SizeTPointer numDependencies_out);
@Cast("cuuint64_t*") LongPointer id_out, @ByPtrPtr CUgraph_st graph_out, @Cast("const CUgraphNode**") @ByPtrPtr PointerPointer dependencies_out, @Cast("size_t*") SizeTPointer numDependencies_out);
public static native @Cast("CUresult") int cuStreamGetCaptureInfo_v2(CUstream_st hStream, @Cast("CUstreamCaptureStatus*") IntBuffer captureStatus_out,
@Cast("cuuint64_t*") IntBuffer id_out, @ByPtrPtr CUgraph_st graph_out, @Cast("const CUgraphNode**") @ByPtrPtr PointerPointer dependencies_out, @Cast("size_t*") SizeTPointer numDependencies_out);
@Cast("cuuint64_t*") LongBuffer id_out, @ByPtrPtr CUgraph_st graph_out, @Cast("const CUgraphNode**") @ByPtrPtr PointerPointer dependencies_out, @Cast("size_t*") SizeTPointer numDependencies_out);
public static native @Cast("CUresult") int cuStreamGetCaptureInfo_v2(CUstream_st hStream, @Cast("CUstreamCaptureStatus*") int[] captureStatus_out,
@Cast("cuuint64_t*") int[] id_out, @ByPtrPtr CUgraph_st graph_out, @Cast("const CUgraphNode**") @ByPtrPtr PointerPointer dependencies_out, @Cast("size_t*") SizeTPointer numDependencies_out);
@Cast("cuuint64_t*") long[] id_out, @ByPtrPtr CUgraph_st graph_out, @Cast("const CUgraphNode**") @ByPtrPtr PointerPointer dependencies_out, @Cast("size_t*") SizeTPointer numDependencies_out);

/**
* \brief Update the set of dependencies in a capturing stream (11.3+)
Expand Down Expand Up @@ -12986,7 +12986,7 @@ typedef enum CUexternalSemaphoreHandleType_enum {
* ::cuMemHostRegister,
* ::cuStreamWaitEvent
*/
public static native @Cast("CUresult") int cuStreamWaitValue64(CUstream_st stream, @Cast("CUdeviceptr") long addr, @Cast("cuuint64_t") int value, @Cast("unsigned int") int flags);
public static native @Cast("CUresult") int cuStreamWaitValue64(CUstream_st stream, @Cast("CUdeviceptr") long addr, @Cast("cuuint64_t") long value, @Cast("unsigned int") int flags);

/**
* \brief Write a value to memory
Expand Down Expand Up @@ -13055,7 +13055,7 @@ typedef enum CUexternalSemaphoreHandleType_enum {
* ::cuMemHostRegister,
* ::cuEventRecord
*/
public static native @Cast("CUresult") int cuStreamWriteValue64(CUstream_st stream, @Cast("CUdeviceptr") long addr, @Cast("cuuint64_t") int value, @Cast("unsigned int") int flags);
public static native @Cast("CUresult") int cuStreamWriteValue64(CUstream_st stream, @Cast("CUdeviceptr") long addr, @Cast("cuuint64_t") long value, @Cast("unsigned int") int flags);

/**
* \brief Batch operations to synchronize the stream via memory operations
Expand Down Expand Up @@ -18743,9 +18743,9 @@ typedef enum CUfilter_mode_enum {
* @see
* ::cudaGetDriverEntryPoint
*/
public static native @Cast("CUresult") int cuGetProcAddress(@Cast("const char*") BytePointer symbol, @Cast("void**") PointerPointer pfn, int cudaVersion, @Cast("cuuint64_t") int flags);
public static native @Cast("CUresult") int cuGetProcAddress(@Cast("const char*") BytePointer symbol, @Cast("void**") @ByPtrPtr Pointer pfn, int cudaVersion, @Cast("cuuint64_t") int flags);
public static native @Cast("CUresult") int cuGetProcAddress(String symbol, @Cast("void**") @ByPtrPtr Pointer pfn, int cudaVersion, @Cast("cuuint64_t") int flags);
public static native @Cast("CUresult") int cuGetProcAddress(@Cast("const char*") BytePointer symbol, @Cast("void**") PointerPointer pfn, int cudaVersion, @Cast("cuuint64_t") long flags);
public static native @Cast("CUresult") int cuGetProcAddress(@Cast("const char*") BytePointer symbol, @Cast("void**") @ByPtrPtr Pointer pfn, int cudaVersion, @Cast("cuuint64_t") long flags);
public static native @Cast("CUresult") int cuGetProcAddress(String symbol, @Cast("void**") @ByPtrPtr Pointer pfn, int cudaVersion, @Cast("cuuint64_t") long flags);

/** \} */ /* END CUDA_DRIVER_ENTRY_POINT */

Expand Down
Loading

0 comments on commit 12bb414

Please sign in to comment.