From 92fc1e1ac66001d6bd755e697c8edd0c337ec7c2 Mon Sep 17 00:00:00 2001 From: devjeonghwan Date: Thu, 1 Jun 2023 16:41:55 +0900 Subject: [PATCH] * Virtualize `nvinfer1::IGpuAllocator` from TensorRT to allow customization (pull #1367) --- CHANGELOG.md | 1 + .../tensorrt/nvinfer/IGpuAllocator.java | 31 ++++++++++++++++--- .../bytedeco/tensorrt/presets/nvinfer.java | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5da5f947380..cd575dbcb4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Virtualize `nvinfer1::IGpuAllocator` from TensorRT to allow customization ([pull #1367](https://github.com/bytedeco/javacpp-presets/pull/1367)) * Add new `SampleJpegEncoder` code for nvJPEG module of CUDA ([pull #1365](https://github.com/bytedeco/javacpp-presets/pull/1365)) * Map `std::vector` of `CameraParams`, `ImageFeatures`, and `MatchesInfo` from `cv::detail` ([issue bytedeco/javacv#2027](https://github.com/bytedeco/javacv/issues/2027)) * Fix H.264 decoder of FFmpeg by increasing MAX_SLICES to 256 ([pull #1349](https://github.com/bytedeco/javacpp-presets/pull/1349)) diff --git a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IGpuAllocator.java b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IGpuAllocator.java index 31344ada410..377f271785a 100644 --- a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IGpuAllocator.java +++ b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IGpuAllocator.java @@ -29,6 +29,15 @@ public class IGpuAllocator extends Pointer { static { Loader.load(); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ public IGpuAllocator(Pointer p) { super(p); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public IGpuAllocator(long size) { super((Pointer)null); allocateArray(size); } + private native void allocateArray(long size); + @Override public IGpuAllocator position(long position) { + return (IGpuAllocator)super.position(position); + } + @Override public IGpuAllocator getPointer(long i) { + return new IGpuAllocator((Pointer)this).offsetAddress(i); + } /** * A thread-safe callback implemented by the application to handle acquisition of GPU memory. @@ -61,7 +70,7 @@ public class IGpuAllocator extends Pointer { //! //! //! - public native @Name("allocate") @NoException(true) Pointer _allocate(@Cast("const uint64_t") long size, @Cast("const uint64_t") long alignment, @Cast("const nvinfer1::AllocatorFlags") int flags); + @Virtual(true) public native @Name("allocate") @NoException(true) Pointer _allocate(@Cast("const uint64_t") long size, @Cast("const uint64_t") long alignment, @Cast("const nvinfer1::AllocatorFlags") int flags); /** * A thread-safe callback implemented by the application to handle release of GPU memory. @@ -85,12 +94,26 @@ public class IGpuAllocator extends Pointer { //! //! - public native @Deprecated @Name("free") @NoException(true) void _free(Pointer memory); + @Virtual(true) public native @Deprecated @Name("free") @NoException(true) void _free(Pointer memory); /** * Destructor declared virtual as general good practice for a class with virtual methods. * TensorRT never calls the destructor for an IGpuAllocator defined by the application. * */ + + + //! + //! + //! + //! + //! + //! + //! + //! + //! + //! + public IGpuAllocator() { super((Pointer)null); allocate(); } + private native void allocate(); /** * A thread-safe callback implemented by the application to resize an existing allocation. @@ -135,7 +158,7 @@ public class IGpuAllocator extends Pointer { //! //! //! - public native @NoException(true) Pointer reallocate(Pointer arg0, @Cast("uint64_t") long arg1, @Cast("uint64_t") long arg2); + @Virtual public native @NoException(true) Pointer reallocate(Pointer arg0, @Cast("uint64_t") long arg1, @Cast("uint64_t") long arg2); /** * A thread-safe callback implemented by the application to handle release of GPU memory. @@ -157,5 +180,5 @@ public class IGpuAllocator extends Pointer { * - Allowed context for the API call * - Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads. * */ - public native @Cast("bool") @Name("deallocate") @NoException(true) boolean _deallocate(Pointer memory); + @Virtual public native @Cast("bool") @Name("deallocate") @NoException(true) boolean _deallocate(Pointer memory); } diff --git a/tensorrt/src/main/java/org/bytedeco/tensorrt/presets/nvinfer.java b/tensorrt/src/main/java/org/bytedeco/tensorrt/presets/nvinfer.java index 797f209d432..037c418d2b8 100644 --- a/tensorrt/src/main/java/org/bytedeco/tensorrt/presets/nvinfer.java +++ b/tensorrt/src/main/java/org/bytedeco/tensorrt/presets/nvinfer.java @@ -142,7 +142,7 @@ public void map(InfoMap infoMap) { "nvinfer1::IAlgorithmIOInfo", "nvinfer1::IAlgorithmVariant", "nvinfer1::IAlgorithmContext", "nvinfer1::IAlgorithm", "nvinfer1::ICastLayer", "nvinfer1::IGridSampleLayer", "nvinfer1::INMSLayer", "nvinfer1::INonZeroLayer", "nvinfer1::INormalizationLayer", "nvinfer1::IReverseSequenceLayer").purify()) .put(new Info("nvinfer1::IGpuAllocator::free").javaNames("_free")) - .put(new Info("nvinfer1::IProfiler", "nvinfer1::ILogger", "nvinfer1::IInt8Calibrator", "nvinfer1::IInt8EntropyCalibrator", + .put(new Info("nvinfer1::IGpuAllocator", "nvinfer1::IProfiler", "nvinfer1::ILogger", "nvinfer1::IInt8Calibrator", "nvinfer1::IInt8EntropyCalibrator", "nvinfer1::IInt8EntropyCalibrator2", "nvinfer1::IInt8MinMaxCalibrator", "nvinfer1::IInt8LegacyCalibrator").virtualize()) .put(new Info("nvinfer1::IPluginRegistry::getPluginCreatorList").javaText( "public native @Cast(\"nvinfer1::IPluginCreator*const*\") PointerPointer getPluginCreatorList(IntPointer numCreators);"))