From 11c5b26917bfaae8d2f3e490950cd32cd1c82c18 Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 10 Dec 2019 20:49:19 +0800 Subject: [PATCH 1/2] update --- CMakeLists.txt | 3 --- include/SlicCudaHost.h | 12 ++++++++++-- src/SlicCudaHost.cu | 3 +++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5d446b..693847c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,6 @@ message(STATUS "Found OpenCV >=3.0 at '${OpenCV_DIR}'") ### CUDA CHECK find_package(CUDA REQUIRED) -set(CUDA_COMPUTE_CAPABILITY "20") -set(CUDA_GENERATE_CODE "arch=compute_${CUDA_COMPUTE_CAPABILITY},code=sm_${CUDA_COMPUTE_CAPABILITY}" CACHE STRING "Which GPU architectures to generate code for (each arch/code pair will be passed as --generate-code option to nvcc, separate multiple pairs by ;)") -set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -arch compute_${CUDA_COMPUTE_CAPABILITY}) ### Compilation diff --git a/include/SlicCudaHost.h b/include/SlicCudaHost.h index e938729..585f8e3 100644 --- a/include/SlicCudaHost.h +++ b/include/SlicCudaHost.h @@ -45,7 +45,6 @@ class SlicCuda { // gpu variable float* d_fClusters; - float* d_fLabels; float* d_fAccAtt; //cudaArray @@ -95,7 +94,16 @@ class SlicCuda { */ void segment(const cv::Mat& frame); cv::Mat getLabels(){ return cv::Mat(m_FrameHeight, m_FrameWidth, CV_32F, h_fLabels); } - + int getLabelsNumber(){ + int maxId = 0; + for( int i=0; imaxId ){ + maxId = int(h_fLabels[i]); + } + } + + return maxId + 1; + } /* Discard orphan clusters (optional) */ diff --git a/src/SlicCudaHost.cu b/src/SlicCudaHost.cu index 027cd4d..8c17246 100644 --- a/src/SlicCudaHost.cu +++ b/src/SlicCudaHost.cu @@ -22,6 +22,9 @@ SlicCuda::~SlicCuda(){ delete[] h_fLabels; gpuErrchk(cudaFree(d_fClusters)); gpuErrchk(cudaFree(d_fAccAtt)); + gpuErrchk(cudaDestroyTextureObject(oTexFrameBGRA)); + gpuErrchk(cudaDestroyTextureObject(oSurfFrameLab)); + gpuErrchk(cudaDestroyTextureObject(oSurfLabels)); gpuErrchk(cudaFreeArray(cuArrayFrameBGRA)); gpuErrchk(cudaFreeArray(cuArrayFrameLab)); gpuErrchk(cudaFreeArray(cuArrayLabels)); From 37160a684b9839f15a01cb7c30c306cb06493b10 Mon Sep 17 00:00:00 2001 From: Yannnnnnnnnnnn Date: Wed, 11 Dec 2019 09:25:17 +0800 Subject: [PATCH 2/2] Update SlicCudaHost.cu --- src/SlicCudaHost.cu | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SlicCudaHost.cu b/src/SlicCudaHost.cu index 8c17246..3ec0748 100644 --- a/src/SlicCudaHost.cu +++ b/src/SlicCudaHost.cu @@ -23,8 +23,8 @@ SlicCuda::~SlicCuda(){ gpuErrchk(cudaFree(d_fClusters)); gpuErrchk(cudaFree(d_fAccAtt)); gpuErrchk(cudaDestroyTextureObject(oTexFrameBGRA)); - gpuErrchk(cudaDestroyTextureObject(oSurfFrameLab)); - gpuErrchk(cudaDestroyTextureObject(oSurfLabels)); + gpuErrchk(cudaDestroySurfaceObject(oSurfFrameLab)); + gpuErrchk(cudaDestroySurfaceObject(oSurfLabels)); gpuErrchk(cudaFreeArray(cuArrayFrameBGRA)); gpuErrchk(cudaFreeArray(cuArrayFrameLab)); gpuErrchk(cudaFreeArray(cuArrayLabels)); @@ -323,4 +323,4 @@ static void getSpxSizeFromDiam(const int imWidth, const int imHeight, const int } *spxWidth = ((diamSpx - wl2) < (wl1 - diamSpx)) ? wl2 : wl1; *spxHeight = ((diamSpx - hl2) < (hl1 - diamSpx)) ? hl2 : hl1; -} \ No newline at end of file +}