[popsift] Guard nvtx calls rather than trying to macroize names (#46944)

This commit is contained in:
Billy O'Neal 2025-08-18 11:12:27 -07:00 committed by GitHub
parent 4bb07a326d
commit c6f70ddfd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 351 additions and 2 deletions

View File

@ -8,6 +8,7 @@ vcpkg_from_github(
fix_missing_thrust_include.patch
144.patch
cuda_12_1.patch
remove-nvtx-macros.diff
)
vcpkg_find_cuda(OUT_CUDA_TOOLKIT_ROOT CUDA_TOOLKIT_ROOT)

View File

@ -0,0 +1,340 @@
diff --git a/src/application/main.cpp b/src/application/main.cpp
index 0eec1c2..f30be1b 100755
--- a/src/application/main.cpp
+++ b/src/application/main.cpp
@@ -32,9 +32,6 @@
#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
#include <nvToolsExtCuda.h>
-#else
-#define nvtxRangePushA(a)
-#define nvtxRangePop()
#endif
using namespace std;
@@ -183,7 +180,9 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
exit( -1 );
}
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "load and convert image - devil" );
+#endif
ilImage img;
if( img.Load( inputFile.c_str() ) == false ) {
@@ -200,7 +199,9 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
image_data = img.GetData();
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop( ); // "load and convert image - devil"
+#endif
job = PopSift.enqueue( w, h, image_data );
@@ -209,7 +210,10 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
else
#endif
{
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "load and convert image - pgmread" );
+#endif
+
int w{};
int h{};
image_data = readPGMfile( inputFile, w, h );
@@ -217,7 +221,9 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
exit( EXIT_FAILURE );
}
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop( ); // "load and convert image - pgmread"
+#endif
if( ! float_mode )
{
@@ -251,16 +257,20 @@ void read_job( SiftJob* job, bool really_write )
<< endl;
if( really_write ) {
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "Writing features to disk" );
+#endif
std::ofstream of( "output-features.txt" );
feature_list->print( of, write_as_uchar );
}
delete feature_list;
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
if( really_write ) {
nvtxRangePop( ); // Writing features to disk
}
+#endif
}
int main(int argc, char **argv)
diff --git a/src/application/match.cpp b/src/application/match.cpp
index 852d9b6..7483dda 100755
--- a/src/application/match.cpp
+++ b/src/application/match.cpp
@@ -32,9 +32,6 @@
#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
#include <nvToolsExtCuda.h>
-#else
-#define nvtxRangePushA(a)
-#define nvtxRangePop()
#endif
using namespace std;
@@ -171,7 +168,9 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
unsigned char* image_data;
SiftJob* job;
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "load and convert image" );
+#endif
#ifdef USE_DEVIL
if( ! pgmread_loading )
{
@@ -189,7 +188,9 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
cout << "Loading " << w << " x " << h << " image " << inputFile << endl;
image_data = img.GetData();
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop( );
+#endif
// PopSift.init( w, h );
job = PopSift.enqueue( w, h, image_data );
@@ -206,7 +207,9 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
exit( EXIT_FAILURE );
}
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop( );
+#endif
// PopSift.init( w, h );
job = PopSift.enqueue( w, h, image_data );
diff --git a/src/popsift/s_filtergrid.cu b/src/popsift/s_filtergrid.cu
index a766c2d..d8d3bb8 100644
--- a/src/popsift/s_filtergrid.cu
+++ b/src/popsift/s_filtergrid.cu
@@ -11,9 +11,6 @@
#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
#include <nvToolsExtCuda.h>
-#else
-#define nvtxRangePushA(a)
-#define nvtxRangePop()
#endif
#if ! POPSIFT_IS_DEFINED(POPSIFT_DISABLE_GRID_FILTER)
@@ -317,9 +314,13 @@ int Pyramid::extrema_filter_grid( const Config& conf, int ext_total )
}
}
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "writing back count" );
+#endif
writeDescCountersToDevice( );
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop( );
+#endif
return ret_ext_total;
}
diff --git a/src/popsift/s_image.cu b/src/popsift/s_image.cu
index f26b8e3..92060d5 100755
--- a/src/popsift/s_image.cu
+++ b/src/popsift/s_image.cu
@@ -17,9 +17,6 @@
#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
#include <nvToolsExtCuda.h>
-#else
-#define nvtxRangePushA(a)
-#define nvtxRangePop()
#endif
using namespace std;
@@ -98,7 +95,9 @@ void Image::resetDimensions( int w, int h )
destroyTexture( );
createTexture( );
} else {
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "reallocating host-side image memory" );
+#endif
_max_w = max( w, _max_w );
_max_h = max( h, _max_h );
@@ -112,20 +111,26 @@ void Image::resetDimensions( int w, int h )
destroyTexture( );
createTexture( );
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop(); // "reallocating host-side image memory"
+#endif
}
}
void Image::allocate( int w, int h )
{
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "allocating host-side image memory" );
+#endif
_input_image_h.allocHost( w, h, popsift::CudaAllocated );
_input_image_d.allocDev( w, h );
createTexture( );
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop(); // "allocating host-side image memory"
+#endif
}
void Image::destroyTexture( )
@@ -222,7 +227,9 @@ void ImageFloat::resetDimensions( int w, int h )
destroyTexture( );
createTexture( );
} else {
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "reallocating host-side image memory" );
+#endif
_max_w = max( w, _max_w );
_max_h = max( h, _max_h );
@@ -236,20 +243,26 @@ void ImageFloat::resetDimensions( int w, int h )
destroyTexture( );
createTexture( );
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop(); // "reallocating host-side image memory"
+#endif
}
}
void ImageFloat::allocate( int w, int h )
{
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "allocating host-side image memory" );
+#endif
_input_image_h.allocHost( w, h, popsift::CudaAllocated );
_input_image_d.allocDev( w, h );
createTexture( );
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop(); // "allocating host-side image memory"
+#endif
}
void ImageFloat::destroyTexture( )
diff --git a/src/popsift/s_orientation.cu b/src/popsift/s_orientation.cu
index f6b36fc..f5e1011 100644
--- a/src/popsift/s_orientation.cu
+++ b/src/popsift/s_orientation.cu
@@ -20,9 +20,6 @@
#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
#include <nvToolsExtCuda.h>
-#else
-#define nvtxRangePushA(a)
-#define nvtxRangePop()
#endif
using namespace popsift;
diff --git a/src/popsift/sift_desc.cu b/src/popsift/sift_desc.cu
index b0eb0bd..5649edf 100644
--- a/src/popsift/sift_desc.cu
+++ b/src/popsift/sift_desc.cu
@@ -23,9 +23,6 @@
#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
#include <nvToolsExtCuda.h>
-#else
-#define nvtxRangePushA(a)
-#define nvtxRangePop()
#endif
using namespace popsift;
@@ -55,11 +52,15 @@ using namespace std;
__host__
void Pyramid::descriptors( const Config& conf )
{
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA("Reading orientation count");
+#endif
readDescCountersFromDevice( _octaves[0].getStream() );
cudaStreamSynchronize( _octaves[0].getStream() );
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop( );
+#endif
for( int octave=_num_octaves-1; octave>=0; octave-- )
// for( int octave=0; octave<_num_octaves; octave++ )
diff --git a/src/popsift/sift_pyramid.cu b/src/popsift/sift_pyramid.cu
index f5cb3e2..77332dc 100755
--- a/src/popsift/sift_pyramid.cu
+++ b/src/popsift/sift_pyramid.cu
@@ -27,9 +27,6 @@
#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
#include <nvToolsExtCuda.h>
-#else
-#define nvtxRangePushA(a)
-#define nvtxRangePop()
#endif
#define PYRAMID_PRINT_DEBUG 0
@@ -287,12 +284,16 @@ FeaturesHost* Pyramid::get_descriptors( const Config& conf )
readDescCountersFromDevice();
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "download descriptors" );
+#endif
FeaturesHost* features = new FeaturesHost( hct.ext_total, hct.ori_total );
if( hct.ext_total == 0 || hct.ori_total == 0 )
{
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop();
+#endif
return features;
}
@@ -300,9 +301,13 @@ FeaturesHost* Pyramid::get_descriptors( const Config& conf )
prep_features<<<grid,32,0,_download_stream>>>( features->getDescriptors(), up_fac );
POP_SYNC_CHK;
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "register host memory" );
+#endif
features->pin( );
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop();
+#endif
popcuda_memcpy_async( features->getFeatures(),
dobuf_shadow.features,
hct.ext_total * sizeof(Feature),
@@ -315,10 +320,14 @@ FeaturesHost* Pyramid::get_descriptors( const Config& conf )
cudaMemcpyDeviceToHost,
_download_stream );
cudaStreamSynchronize( _download_stream );
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePushA( "unregister host memory" );
+#endif
features->unpin( );
+#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
nvtxRangePop();
nvtxRangePop();
+#endif
return features;
}

View File

@ -1,7 +1,7 @@
{
"name": "popsift",
"version": "0.9",
"port-version": 5,
"port-version": 6,
"description": "PopSift is an implementation of the SIFT algorithm in CUDA.",
"homepage": "https://github.com/alicevision/popsift",
"supports": "!(uwp | arm | arm64 | android | x86)",

View File

@ -409,7 +409,10 @@ pmdk:x64-osx=fail
pmdk:x64-uwp=fail
pmdk:x64-windows-static=fail
pmdk:x86-windows=fail
popsift:x64-windows-release=fail
popsift:x64-windows-static-md=fail
popsift:x64-windows-static=fail
popsift:x64-windows=fail
portable-snippets:arm-uwp=fail
qbittorrent:x64-linux=fail # Not yet ready for these platforms.
qbittorrent:x64-osx=fail # Not yet ready for these platforms.

View File

@ -7518,7 +7518,7 @@
},
"popsift": {
"baseline": "0.9",
"port-version": 5
"port-version": 6
},
"portable-file-dialogs": {
"baseline": "0.1.0",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "3683687d6244a6c7f051930a912ad6ee13566d52",
"version": "0.9",
"port-version": 6
},
{
"git-tree": "df628dcfa7ee8110e38f7a449b599e3b014645eb",
"version": "0.9",