Skip to content
Draft
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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ if(USEGPU)
endif()
elseif (CUDAToolkit_VERSION_MAJOR STREQUAL "12")
set(CUDA_ARCH_LIST "50;52;53;60;61;62;70;72;75;80;86;89;90")
elseif (CUDAToolkit_VERSION_MAJOR STREQUAL "13")
set(CUDA_ARCH_LIST "75;80;86;87;88;89;90;100;103;120;121")
else() # some old CUDA version (<10)
set(CUDA_ARCH_LIST "50") # 5.0 is the oldest non-deprecated CC as of 2024-09-06
endif()
Expand Down Expand Up @@ -132,6 +134,9 @@ option(RUN_GTEST "Downloads google unit test API and runs google test scripts to

#==== Source files
set(SOURCE
# headers
src/nyx/raw_tiff.h
# sources
src/nyx/3rdparty/dsyevj3.cpp
src/nyx/features/basic_morphology.cpp
src/nyx/features/caliper_feret.cpp
Expand Down
59 changes: 30 additions & 29 deletions src/nyx/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
return false; \
} \

#define OKDETL(x,detl) if (x == false) \
{ \
return std::string("error due to ") + detl + " at " + __FILE__ + ":" + std::to_string(__LINE__); \
} \

#define OKV(x) if (x == false) \
{ \
std::cerr << "gpu cache related error in " << __FILE__ << ":" << __LINE__; \
Expand Down Expand Up @@ -76,7 +81,7 @@
return szb;
}

bool GpusideCache::allocate_gpu_cache(
std::optional<std::string> GpusideCache::allocate_gpu_cache(
// out
GpuCache<Pixel2>& clouds, // geo moments
GpuCache<Pixel2>& konturs,
Expand Down Expand Up @@ -107,14 +112,13 @@
int gabor_ker_side)
{
using_contour =
using_erosion =
using_gabor =
using_moments = false;
using_erosion =
using_gabor =
using_moments = false;

//****** plan GPU memory

size_t amt = 0;
OK(gpu_get_free_mem(amt));
OKDETL(gpu_get_free_mem(amt), "gpu_get_free_mem()");

int n_gabFilters = n_gabor_filters + 1; // '+1': an extra filter for the baseline signal

Expand All @@ -130,7 +134,7 @@
n_rois, roi_w, roi_h, n_gabFilters, gabor_ker_side);

batch_len = n_rois;
size_t critAmt = amt * 0.75; // 75% GPU RAM as critical RAM
size_t critAmt = float(amt) * 0.75; // 75% GPU RAM as critical RAM

if (critAmt < szb)
{
Expand All @@ -139,10 +143,7 @@
{
// failed to find a batch ?
if (try_nrois == 0)
{
std::cerr << "error: cannot make a ROI batch \n";
return false;
}
return "cannot rightsize a ROI batch: even 1 ROI requires over critical memory amount " + std::to_string(critAmt);

size_t ccl = roi_area * try_nrois; // combined cloud length
size_t try_szb = ram_comsumption_szb(
Expand All @@ -162,7 +163,7 @@
// have we found a compromise ?
if (batch_len < n_rois)
{
return false;
return "cannot rightsize a ROI batch: batch_len " + std::to_string(batch_len) + " < n_rois " + std::to_string(n_rois);
}
}

Expand All @@ -172,17 +173,17 @@

// ROI clouds (always on)

OK(clouds.clear());
OK(clouds.alloc(batch_roi_cloud_len, batch_len));
OKDETL(clouds.clear(), "clouds.clear()");
OKDETL(clouds.alloc(batch_roi_cloud_len, batch_len), "clouds.alloc()");

// contours

if (needContour)
{
using_contour = true;

OK(konturs.clear());
OK(konturs.alloc(batch_roi_cloud_len, batch_len));
OKDETL(konturs.clear(), "konturs.clear()");
OKDETL(konturs.alloc(batch_roi_cloud_len, batch_len), "konturs.alloc()");
}

// moments
Expand All @@ -192,17 +193,17 @@
using_moments = true;

// moments / real intensities
OK(allocate_on_device((void**)realintens, sizeof(RealPixIntens) * batch_roi_cloud_len));
OKDETL(allocate_on_device((void**)realintens, sizeof(RealPixIntens) * batch_roi_cloud_len), "allocate_on_device(moments1)");

// moments / pre-reduce
OK(allocate_on_device((void**)prereduce, sizeof(double) * batch_roi_cloud_len * 16)); // 16 is the max number of simultaneous totals calculated by a kernel, e.g. RM00-33
OKDETL(allocate_on_device((void**)prereduce, sizeof(double) * batch_roi_cloud_len * 16), "allocate_on_device(moments2)"); // 16 is the max number of simultaneous totals calculated by a kernel, e.g. RM00-33

// moments / intermediate
OK(intermediate.alloc(GpusideState::__COUNT__, batch_len));
OKDETL(intermediate.alloc(GpusideState::__COUNT__, batch_len), "allocate_on_device(moments3)");

// moments / CUB DeviceReduce's temp buffer
OK(devicereduce_evaluate_buffer_szb(devicereduce_buf_szb, batch_roi_cloud_len));
OK(allocate_on_device((void**)devicereduce_buf, devicereduce_buf_szb));
OKDETL(devicereduce_evaluate_buffer_szb(devicereduce_buf_szb, batch_roi_cloud_len), "allocate_on_device(moments4)");
OKDETL(allocate_on_device((void**)devicereduce_buf, devicereduce_buf_szb), "allocate_on_device(moments5)");
}

// erosion / image matrices 1 and 2
Expand All @@ -213,9 +214,9 @@

// imat1 is shared by erosion and Gabor
if (!*imat1)
OK(allocate_on_device((void**)imat1, sizeof(imat1[0]) * roi_w * roi_h));
OKDETL(allocate_on_device((void**)imat1, sizeof(imat1[0]) * roi_w * roi_h), "allocate_on_device(eros1)");

OK(allocate_on_device((void**)imat2, sizeof(imat2[0]) * roi_w * roi_h));
OKDETL(allocate_on_device((void**)imat2, sizeof(imat2[0]) * roi_w * roi_h), "allocate_on_device(eros2)");
}

// Gabor
Expand All @@ -226,16 +227,16 @@

// imat1 is shared by erosion and Gabor
if (!*imat1)
OK(allocate_on_device((void**)imat1, sizeof(imat1[0]) * roi_w * roi_h));
OKDETL(allocate_on_device((void**)imat1, sizeof(imat1[0]) * roi_w * roi_h), "allocate_on_device(gabor)");

size_t gabTotlen = (roi_w + gabor_ker_side - 1) * (roi_h + gabor_ker_side - 1) * n_gabFilters;
OK(gabor_linear_image.alloc(gabTotlen, 1));
OK(gabor_result.alloc(gabTotlen, 1));
OK(gabor_linear_kernel.alloc(gabTotlen, 1));
OK(gabor_energy_image.alloc(gabTotlen, 1));
OKDETL(gabor_linear_image.alloc(gabTotlen, 1), "gabor_linear_image.alloc()");
OKDETL(gabor_result.alloc(gabTotlen, 1), "gabor_result.alloc()");
OKDETL(gabor_linear_kernel.alloc(gabTotlen, 1), "gabor_linear_kernel.alloc()");
OKDETL(gabor_energy_image.alloc(gabTotlen, 1), "gabor_energy_image.alloc()");
}

return true;
return std::nullopt;
}

void GpusideCache::send_roi_batch_data_2_gpu(
Expand Down
5 changes: 4 additions & 1 deletion src/nyx/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "features/pixel.h"
#endif

#include <optional>
#include <string>

class CpusideCache
{
public:
Expand Down Expand Up @@ -148,7 +151,7 @@ class GpusideCache
int n_gabor_filters,
int gabor_ker_side);

bool allocate_gpu_cache(
std::optional<std::string> allocate_gpu_cache(
// out
GpuCache<Pixel2>& clouds,
GpuCache<Pixel2>& konturs,
Expand Down
29 changes: 16 additions & 13 deletions src/nyx/features/contour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,26 +583,29 @@ ContourFeature::ContourFeature() : FeatureMethod("ContourFeature")
// U - unordered subset of C subject to order
// S - ordered subset of C

std::list<Pixel2> U (C.begin(), C.end());


// fix X-crossing points

std::vector<Pixel2> C_fix = C;
int n_xxings = 0;
for (Pixel2 p : U)
for (const Pixel2& p : C)
{
Pixel2 pN (p.x, p.y-1, p.inten),
pS (p.x, p.y+1, p.inten),
pW (p.x-1, p.y, p.inten),
pE (p.x+1, p.y, p.inten);
auto itN = std::find(U.begin(), U.end(), pN);
auto itS = std::find(U.begin(), U.end(), pS);
auto itE = std::find(U.begin(), U.end(), pE);
auto itW = std::find(U.begin(), U.end(), pW);
if (itN != U.end() && itS != U.end() && itW != U.end() && itE != U.end())
Pixel2 pN (p.x, p.y - 1, p.inten),
pS (p.x, p.y + 1, p.inten),
pW (p.x - 1, p.y, p.inten),
pE (p.x + 1, p.y, p.inten);
auto itN = std::find (C_fix.begin(), C_fix.end(), pN);
auto itS = std::find (C_fix.begin(), C_fix.end(), pS);
auto itE = std::find (C_fix.begin(), C_fix.end(), pE);
auto itW = std::find (C_fix.begin(), C_fix.end(), pW);
if (itN != C_fix.end() && itS != C_fix.end() && itW != C_fix.end() && itE != C_fix.end())
{
U.remove(p);
auto itP = std::find (C_fix.begin(), C_fix.end(), p);
C_fix.erase (itP);
n_xxings++;
}
}
std::list<Pixel2> U (C_fix.begin(), C_fix.end());

// find contour by contour
while (!U.empty())
Expand Down
1 change: 0 additions & 1 deletion src/nyx/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ namespace Nyxus
int processDataset_2D_wholeslide(
Environment & env,
const std::vector<std::string>& intensFiles,
const std::vector<std::string>& labelFiles,
int n_threads,
const SaveOption saveOption,
const std::string& outputPath);
Expand Down
2 changes: 1 addition & 1 deletion src/nyx/gpu/erosion.cu
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <iostream>

#include "gpu.h"
#include "../cache.h" //xxxxxxxxxx #include "../gpucache.h"
#include "../cache.h"

#include "../helpers/timing.h"

Expand Down
2 changes: 1 addition & 1 deletion src/nyx/gpu/gabor.cu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <vector>
#include "gabor.cuh"
#include "../cache.h" //xxxxxxxxxxxx ../gpucache.h"
#include "../cache.h"

using namespace std;

Expand Down
2 changes: 1 addition & 1 deletion src/nyx/gpu/geomoments_central.cu
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cuda_runtime_api.h>
#include <builtin_types.h>
#include "gpu.h"
#include "../cache.h" //xxxxxxx #include "../gpucache.h"
#include "../cache.h"
#include "../features/pixel.h"
#include "geomoments.cuh"

Expand Down
2 changes: 1 addition & 1 deletion src/nyx/gpu/geomoments_hu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "../features/image_matrix.h"
#include "gpu.h"
#include "../cache.h" //xxxxxxxxx #include "../gpucache.h"
#include "../cache.h"
#include "geomoments.cuh"

namespace NyxusGpu
Expand Down
2 changes: 1 addition & 1 deletion src/nyx/gpu/geomoments_main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "gpu.h"
#include "geomoments.cuh"
#include "../cache.h" //xxxxxxxxxxxxx #include "../gpucache.h"
#include "../cache.h"

#include "../helpers/timing.h"

Expand Down
2 changes: 1 addition & 1 deletion src/nyx/gpu/geomoments_norm.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "../features/image_matrix.h"
#include "gpu.h"
#include "../cache.h" //xxxxxxxxxx #include "../gpucache.h"
#include "../cache.h"
#include "geomoments.cuh"

namespace NyxusGpu
Expand Down
2 changes: 1 addition & 1 deletion src/nyx/gpu/geomoments_origin.cu
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cuda_runtime_api.h>
#include <builtin_types.h>
#include "gpu.h"
#include "../cache.h" //xxxxx #include "../gpucache.h"
#include "../cache.h"
#include "../features/pixel.h"
#include "geomoments.cuh"

Expand Down
2 changes: 1 addition & 1 deletion src/nyx/gpu/geomoments_raw.cu
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cuda_runtime_api.h>
#include <builtin_types.h>
#include "gpu.h"
#include "../cache.h" //xxxxxxxxx #include "../gpucache.h"
#include "../cache.h"
#include "geomoments.cuh"
#include "../features/pixel.h"

Expand Down
4 changes: 2 additions & 2 deletions src/nyx/gpu/geomoments_weighting.cu
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace NyxusGpu
if (pxIdx >= cloud_len)
return;

StatsInt x = d_roicloud[pxIdx].x,
[[maybe_unused]] StatsInt x = d_roicloud[pxIdx].x,
y = d_roicloud[pxIdx].y;

const Pixel2 & p = d_roicloud[pxIdx],
Expand Down Expand Up @@ -171,4 +171,4 @@ namespace NyxusGpu
return true;
}

}
}
14 changes: 7 additions & 7 deletions src/nyx/gpu/helper_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,23 @@ static const char* _cudaGetErrorEnum(cufftResult error) {
case CUFFT_UNALIGNED_DATA:
return "CUFFT_UNALIGNED_DATA";

case CUFFT_INCOMPLETE_PARAMETER_LIST:
return "CUFFT_INCOMPLETE_PARAMETER_LIST";
//case CUFFT_INCOMPLETE_PARAMETER_LIST:
// return "CUFFT_INCOMPLETE_PARAMETER_LIST";

case CUFFT_INVALID_DEVICE:
return "CUFFT_INVALID_DEVICE";

case CUFFT_PARSE_ERROR:
return "CUFFT_PARSE_ERROR";
//case CUFFT_PARSE_ERROR:
// return "CUFFT_PARSE_ERROR";

case CUFFT_NO_WORKSPACE:
return "CUFFT_NO_WORKSPACE";

case CUFFT_NOT_IMPLEMENTED:
return "CUFFT_NOT_IMPLEMENTED";

case CUFFT_LICENSE_ERROR:
return "CUFFT_LICENSE_ERROR";
//case CUFFT_LICENSE_ERROR:
// return "CUFFT_LICENSE_ERROR";

case CUFFT_NOT_SUPPORTED:
return "CUFFT_NOT_SUPPORTED";
Expand Down Expand Up @@ -973,4 +973,4 @@ inline bool checkCudaCapabilities(int major_version, int minor_version) {

// end of CUDA Helper Functions

#endif // COMMON_HELPER_CUDA_H_
#endif // COMMON_HELPER_CUDA_H_
2 changes: 1 addition & 1 deletion src/nyx/gpu/reducers.cu
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cuda_runtime_api.h>
#include <builtin_types.h>
#include "gpu.h"
#include "../cache.h" //xxxxxxxxxx #include "../gpucache.h"
#include "../cache.h"
#include "../features/pixel.h"
#include "geomoments.cuh"

Expand Down
Loading
Loading