Skip to content

Commit

Permalink
Add IGpuAllocator as virtual class in tensorrt
Browse files Browse the repository at this point in the history
  • Loading branch information
devjeonghwan committed May 31, 2023
1 parent 31f53a3 commit ed6492b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
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 @@ -143,7 +143,8 @@ public void map(InfoMap infoMap) {
"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",
"nvinfer1::IInt8EntropyCalibrator2", "nvinfer1::IInt8MinMaxCalibrator", "nvinfer1::IInt8LegacyCalibrator").virtualize())
"nvinfer1::IInt8EntropyCalibrator2", "nvinfer1::IInt8MinMaxCalibrator", "nvinfer1::IInt8LegacyCalibrator",
"nvinfer1::IGpuAllocator").virtualize())
.put(new Info("nvinfer1::IPluginRegistry::getPluginCreatorList").javaText(
"public native @Cast(\"nvinfer1::IPluginCreator*const*\") PointerPointer getPluginCreatorList(IntPointer numCreators);"))
;
Expand Down

0 comments on commit ed6492b

Please sign in to comment.