Skip to content

Commit

Permalink
* Virtualize IInt8Calibrator plus subclasses from TensorRT to allo…
Browse files Browse the repository at this point in the history
…w customization (issue #902)
  • Loading branch information
saudet committed Jul 2, 2020
1 parent 706a65b commit 3717741
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 9 additions & 5 deletions tensorrt/src/gen/java/org/bytedeco/tensorrt/nvinfer/ILogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
15 changes: 4 additions & 11 deletions tensorrt/src/main/java/org/bytedeco/tensorrt/presets/nvinfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
;
}
}

0 comments on commit 3717741

Please sign in to comment.