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 IGpuAllocator as virtual class in tensorrt #1367

Merged
merged 5 commits into from
Jun 1, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);"))
Expand Down