From 37177414ede28e2cf206b7e678f64ffb785c7f81 Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Thu, 2 Jul 2020 13:57:22 +0900 Subject: [PATCH] * Virtualize `IInt8Calibrator` plus subclasses from TensorRT to allow customization (issue #902) --- CHANGELOG.md | 1 + .../tensorrt/nvinfer/IInt8Calibrator.java | 24 +++++++++++-------- .../nvinfer/IInt8EntropyCalibrator.java | 9 +++++++ .../nvinfer/IInt8EntropyCalibrator2.java | 9 +++++++ .../nvinfer/IInt8LegacyCalibrator.java | 19 ++++++++++----- .../nvinfer/IInt8MinMaxCalibrator.java | 9 +++++++ .../bytedeco/tensorrt/nvinfer/ILogger.java | 14 +++++++---- .../bytedeco/tensorrt/nvinfer/IProfiler.java | 14 +++++++---- .../bytedeco/tensorrt/presets/nvinfer.java | 15 ++++-------- 9 files changed, 77 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a57269f5df..13517cd7248 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Virtualize `IInt8Calibrator` plus subclasses from TensorRT to allow customization ([issue #902](https://github.com/bytedeco/javacpp-presets/issues/902)) * Replace `requires` with `requires static` in JPMS `.platform` modules ([pull #900](https://github.com/bytedeco/javacpp-presets/pull/900)) * Add presets for OpenPose 1.6.0 ([pull #898](https://github.com/bytedeco/javacpp-presets/pull/898)) * Add comparison against MKL in `llvm/samples/polly/MatMulBenchmark.java` diff --git a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8Calibrator.java b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8Calibrator.java index 42ba999a5d8..394ae21e7fd 100644 --- a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8Calibrator.java +++ b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8Calibrator.java @@ -33,8 +33,17 @@ @Namespace("nvinfer1") @Properties(inherit = org.bytedeco.tensorrt.presets.nvinfer.class) public class IInt8Calibrator extends Pointer { static { Loader.load(); } + /** Default native constructor. */ + public IInt8Calibrator() { super((Pointer)null); allocate(); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public IInt8Calibrator(long size) { super((Pointer)null); allocateArray(size); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ public IInt8Calibrator(Pointer p) { super(p); } + private native void allocate(); + private native void allocateArray(long size); + @Override public IInt8Calibrator position(long position) { + return (IInt8Calibrator)super.position(position); + } /** * \brief Get the batch size used for calibration batches. @@ -48,7 +57,7 @@ public class IInt8Calibrator extends Pointer { //! //! //! - public native int getBatchSize(); + @Virtual(true) public native @Const({false, false, true}) int getBatchSize(); /** * \brief Get a batch of input for calibration. @@ -70,10 +79,7 @@ public class IInt8Calibrator extends Pointer { //! //! //! - public native @Cast("bool") boolean getBatch(@Cast("void**") PointerPointer bindings, @Cast("const char**") PointerPointer names, int nbBindings); - public native @Cast("bool") boolean getBatch(@Cast("void**") @ByPtrPtr Pointer bindings, @Cast("const char**") @ByPtrPtr BytePointer names, int nbBindings); - public native @Cast("bool") boolean getBatch(@Cast("void**") @ByPtrPtr Pointer bindings, @Cast("const char**") @ByPtrPtr ByteBuffer names, int nbBindings); - public native @Cast("bool") boolean getBatch(@Cast("void**") @ByPtrPtr Pointer bindings, @Cast("const char**") @ByPtrPtr byte[] names, int nbBindings); + @Virtual(true) public native @Cast("bool") boolean getBatch(@Cast("void**") PointerPointer bindings, @Cast("const char**") PointerPointer names, int nbBindings); /** * \brief Load a calibration cache. @@ -95,9 +101,7 @@ public class IInt8Calibrator extends Pointer { //! //! //! - public native @Const Pointer readCalibrationCache(@Cast("std::size_t*") @ByRef LongPointer length); - public native @Const Pointer readCalibrationCache(@Cast("std::size_t*") @ByRef LongBuffer length); - public native @Const Pointer readCalibrationCache(@Cast("std::size_t*") @ByRef long[] length); + @Virtual(true) public native @Const Pointer readCalibrationCache(@Cast("std::size_t*") @ByRef LongPointer length); /** * \brief Save a calibration cache. @@ -112,12 +116,12 @@ public class IInt8Calibrator extends Pointer { //! //! //! - public native void writeCalibrationCache(@Const Pointer ptr, @Cast("std::size_t") long length); + @Virtual(true) public native void writeCalibrationCache(@Const Pointer ptr, @Cast("std::size_t") long length); /** * \brief Get the algorithm used by this calibrator. * * @return The algorithm used by the calibrator. * */ - public native CalibrationAlgoType getAlgorithm(); + @Virtual(true) public native CalibrationAlgoType getAlgorithm(); } diff --git a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8EntropyCalibrator.java b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8EntropyCalibrator.java index 5386a0ccee7..a4894e02e11 100644 --- a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8EntropyCalibrator.java +++ b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8EntropyCalibrator.java @@ -26,8 +26,17 @@ @Namespace("nvinfer1") @Properties(inherit = org.bytedeco.tensorrt.presets.nvinfer.class) public class IInt8EntropyCalibrator extends IInt8Calibrator { static { Loader.load(); } + /** Default native constructor. */ + public IInt8EntropyCalibrator() { super((Pointer)null); allocate(); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public IInt8EntropyCalibrator(long size) { super((Pointer)null); allocateArray(size); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ public IInt8EntropyCalibrator(Pointer p) { super(p); } + private native void allocate(); + private native void allocateArray(long size); + @Override public IInt8EntropyCalibrator position(long position) { + return (IInt8EntropyCalibrator)super.position(position); + } /** * Signal that this is the entropy calibrator. diff --git a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8EntropyCalibrator2.java b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8EntropyCalibrator2.java index dacd4d80588..959d91ba916 100644 --- a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8EntropyCalibrator2.java +++ b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8EntropyCalibrator2.java @@ -26,8 +26,17 @@ @Namespace("nvinfer1") @Properties(inherit = org.bytedeco.tensorrt.presets.nvinfer.class) public class IInt8EntropyCalibrator2 extends IInt8Calibrator { static { Loader.load(); } + /** Default native constructor. */ + public IInt8EntropyCalibrator2() { super((Pointer)null); allocate(); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public IInt8EntropyCalibrator2(long size) { super((Pointer)null); allocateArray(size); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ public IInt8EntropyCalibrator2(Pointer p) { super(p); } + private native void allocate(); + private native void allocateArray(long size); + @Override public IInt8EntropyCalibrator2 position(long position) { + return (IInt8EntropyCalibrator2)super.position(position); + } /** * Signal that this is the entropy calibrator 2. diff --git a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8LegacyCalibrator.java b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8LegacyCalibrator.java index f5d26380ce3..e0feb123a32 100644 --- a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8LegacyCalibrator.java +++ b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8LegacyCalibrator.java @@ -26,8 +26,17 @@ @Namespace("nvinfer1") @Properties(inherit = org.bytedeco.tensorrt.presets.nvinfer.class) public class IInt8LegacyCalibrator extends IInt8Calibrator { static { Loader.load(); } + /** Default native constructor. */ + public IInt8LegacyCalibrator() { super((Pointer)null); allocate(); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public IInt8LegacyCalibrator(long size) { super((Pointer)null); allocateArray(size); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ public IInt8LegacyCalibrator(Pointer p) { super(p); } + private native void allocate(); + private native void allocateArray(long size); + @Override public IInt8LegacyCalibrator position(long position) { + return (IInt8LegacyCalibrator)super.position(position); + } /** * Signal that this is the legacy calibrator. @@ -50,7 +59,7 @@ public class IInt8LegacyCalibrator extends IInt8Calibrator { //! //! //! - public native double getQuantile(); + @Virtual(true) public native @Const({false, false, true}) double getQuantile(); /** * \brief The fraction (between 0 and 1) of the maximum used to define the regression cutoff when using regression @@ -65,7 +74,7 @@ public class IInt8LegacyCalibrator extends IInt8Calibrator { //! //! //! - public native double getRegressionCutoff(); + @Virtual(true) public native @Const({false, false, true}) double getRegressionCutoff(); /** * \brief Load a histogram. @@ -85,9 +94,7 @@ public class IInt8LegacyCalibrator extends IInt8Calibrator { //! //! //! - public native @Const Pointer readHistogramCache(@Cast("std::size_t*") @ByRef LongPointer length); - public native @Const Pointer readHistogramCache(@Cast("std::size_t*") @ByRef LongBuffer length); - public native @Const Pointer readHistogramCache(@Cast("std::size_t*") @ByRef long[] length); + @Virtual(true) public native @Const Pointer readHistogramCache(@Cast("std::size_t*") @ByRef LongPointer length); /** * \brief Save a histogram cache. @@ -97,5 +104,5 @@ public class IInt8LegacyCalibrator extends IInt8Calibrator { * * @see readHistogramCache() * */ - public native void writeHistogramCache(@Const Pointer ptr, @Cast("std::size_t") long length); + @Virtual(true) public native void writeHistogramCache(@Const Pointer ptr, @Cast("std::size_t") long length); } diff --git a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8MinMaxCalibrator.java b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8MinMaxCalibrator.java index 22ca94a2828..5d22440db71 100644 --- a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8MinMaxCalibrator.java +++ b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IInt8MinMaxCalibrator.java @@ -26,8 +26,17 @@ @Namespace("nvinfer1") @Properties(inherit = org.bytedeco.tensorrt.presets.nvinfer.class) public class IInt8MinMaxCalibrator extends IInt8Calibrator { static { Loader.load(); } + /** Default native constructor. */ + public IInt8MinMaxCalibrator() { super((Pointer)null); allocate(); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public IInt8MinMaxCalibrator(long size) { super((Pointer)null); allocateArray(size); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ public IInt8MinMaxCalibrator(Pointer p) { super(p); } + private native void allocate(); + private native void allocateArray(long size); + @Override public IInt8MinMaxCalibrator position(long position) { + return (IInt8MinMaxCalibrator)super.position(position); + } /** * Signal that this is the MinMax Calibrator. diff --git a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/ILogger.java b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/ILogger.java index 75d3f4a82b7..6a111a9d594 100644 --- a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/ILogger.java +++ b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/ILogger.java @@ -30,8 +30,17 @@ @Namespace("nvinfer1") @Properties(inherit = org.bytedeco.tensorrt.presets.nvinfer.class) public class ILogger extends Pointer { static { Loader.load(); } + /** Default native constructor. */ + public ILogger() { super((Pointer)null); allocate(); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public ILogger(long size) { super((Pointer)null); allocateArray(size); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ public ILogger(Pointer p) { super(p); } + private native void allocate(); + private native void allocateArray(long size); + @Override public ILogger position(long position) { + return (ILogger)super.position(position); + } /** * \enum Severity @@ -64,9 +73,4 @@ public enum Severity { * @param msg The log message, null terminated. * */ @Virtual(true) public native void log(Severity severity, String msg); - - - /** Default native constructor. */ - public ILogger() { super((Pointer)null); allocate(); } - private native void allocate(); } diff --git a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IProfiler.java b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IProfiler.java index ddc58e8aebf..540ce1d28a3 100644 --- a/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IProfiler.java +++ b/tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/IProfiler.java @@ -32,8 +32,17 @@ @Namespace("nvinfer1") @Properties(inherit = org.bytedeco.tensorrt.presets.nvinfer.class) public class IProfiler extends Pointer { static { Loader.load(); } + /** Default native constructor. */ + public IProfiler() { super((Pointer)null); allocate(); } + /** Native array allocator. Access with {@link Pointer#position(long)}. */ + public IProfiler(long size) { super((Pointer)null); allocateArray(size); } /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */ public IProfiler(Pointer p) { super(p); } + private native void allocate(); + private native void allocateArray(long size); + @Override public IProfiler position(long position) { + return (IProfiler)super.position(position); + } /** * \brief Layer time reporting callback. @@ -42,9 +51,4 @@ public class IProfiler extends Pointer { * @param ms The time in milliseconds to execute the layer. * */ @Virtual(true) public native void reportLayerTime(String layerName, float ms); - - - /** Default native constructor. */ - public IProfiler() { super((Pointer)null); allocate(); } - private native void allocate(); } 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 f20aab949a6..2b93346dcd9 100644 --- a/tensorrt/src/main/java/org/bytedeco/tensorrt/presets/nvinfer.java +++ b/tensorrt/src/main/java/org/bytedeco/tensorrt/presets/nvinfer.java @@ -114,19 +114,12 @@ public void map(InfoMap infoMap) { .put(new Info("nvinfer1::EnumMax").skip()) .put(new Info("nvinfer1::Weights::values").javaText("public native @Const Pointer values(); public native Weights values(Pointer values);")) .put(new Info("nvinfer1::IRaggedSoftMaxLayer", "nvinfer1::IIdentityLayer", "nvinfer1::ISoftMaxLayer", - "nvinfer1::IConcatenationLayer", "nvinfer1::IInt8EntropyCalibrator", "nvinfer1::IInt8EntropyCalibrator2", - "nvinfer1::IInt8MinMaxCalibrator", "nvinfer1::IParametricReLULayer", "nvinfer1::IShapeLayer", "nvinfer1::ISelectLayer").purify()) + "nvinfer1::IConcatenationLayer", "nvinfer1::IParametricReLULayer", "nvinfer1::IShapeLayer", "nvinfer1::ISelectLayer").purify()) .put(new Info("nvinfer1::IGpuAllocator::free").javaNames("_free")) - .put(new Info("nvinfer1::IProfiler", "nvinfer1::ILogger").purify().virtualize()) + .put(new Info("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);")) - .put(new Info("nvinfer1::IProfiler::~IProfiler").javaText("\n" - + "/** Default native constructor. */\n" - + "public IProfiler() { super((Pointer)null); allocate(); }\n" - + "private native void allocate();\n")) - .put(new Info("nvinfer1::ILogger::~ILogger").javaText("\n" - + "/** Default native constructor. */\n" - + "public ILogger() { super((Pointer)null); allocate(); }\n" - + "private native void allocate();\n")); + ; } }