Skip to content
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
37 changes: 35 additions & 2 deletions benchmarks/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Apache License, Version 2.0
* Copyright 2020 NVIDIA Corporation
* Copyright 2020-2021 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,8 @@

struct AppConfig
{
std::string input_file = "test_data/private/generic_tiff_000.tif";
std::string test_folder;
std::string test_file;
Comment on lines -24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to revisit at some point and look at using std::filesystem::path. Though that requires C++17 and we were already using std::string. So just a future note

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Created a issue for following up:

bool discard_cache = false;
int random_seed = 0;
bool random_start_location = false;
Expand All @@ -42,6 +43,38 @@ struct AppConfig
std::string benchmark_color; // {auto|true|false}
std::string benchmark_counters_tabular;
std::string v; // <verbosity>

std::string get_input_path(const std::string default_value = "generated/tiff_stripe_4096x4096_256.tif") const
{
// If `test_file` is absolute path
if (!test_folder.empty() && test_file.substr(0, 1) == "/")
{
return test_file;
}
else
{
std::string test_data_folder = test_folder;
if (test_data_folder.empty())
{
if (const char* env_p = std::getenv("CUCIM_TESTDATA_FOLDER"))
{
test_data_folder = env_p;
}
else
{
test_data_folder = "test_data";
}
}
if (test_file.empty())
{
return test_data_folder + "/" + default_value;
}
else
{
return test_data_folder + "/" + test_file;
}
}
}
};

#endif // CUCIM_CONFIG_H
23 changes: 15 additions & 8 deletions benchmarks/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,8 @@ static AppConfig g_config;

static void test_cucim(benchmark::State& state)
{
std::string input_path = g_config.get_input_path();

int arg = -1;
for (auto state_item : state)
{
Expand All @@ -46,7 +48,7 @@ static void test_cucim(benchmark::State& state)

if (g_config.discard_cache)
{
int fd = open(g_config.input_file.c_str(), O_RDONLY);
int fd = open(input_path.c_str(), O_RDONLY);
fdatasync(fd);
posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
close(fd);
Expand All @@ -61,7 +63,7 @@ static void test_cucim(benchmark::State& state)
request_location[1] = rand() % (g_config.image_height - state.range(0));
}

cucim::CuImage image = cucim::CuImage(g_config.input_file.c_str());
cucim::CuImage image = cucim::CuImage(input_path.c_str());
cucim::CuImage region =
image.read_region({ request_location[0], request_location[1] }, { state.range(0), state.range(0) }, 0,
cucim::DimIndices{}, "cpu", nullptr, "");
Expand All @@ -70,6 +72,8 @@ static void test_cucim(benchmark::State& state)

static void test_openslide(benchmark::State& state)
{
std::string input_path = g_config.get_input_path();

int arg = -1;
for (auto _ : state)
{
Expand All @@ -84,15 +88,15 @@ static void test_openslide(benchmark::State& state)

if (g_config.discard_cache)
{
int fd = open(g_config.input_file.c_str(), O_RDONLY);
int fd = open(input_path.c_str(), O_RDONLY);
fdatasync(fd);
posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
close(fd);
}
}
state.ResumeTiming();

openslide_t* slide = openslide_open(g_config.input_file.c_str());
openslide_t* slide = openslide_open(input_path.c_str());
uint32_t* buf = static_cast<uint32_t*>(cucim_malloc(state.range(0) * state.range(0) * 4));
int64_t request_location[2] = { 0, 0 };
if (g_config.random_start_location)
Expand Down Expand Up @@ -131,10 +135,12 @@ static bool remove_help_option(int* argc, char** argv)

static bool setup_configuration()
{
openslide_t* slide = openslide_open(g_config.input_file.c_str());
std::string input_path = g_config.get_input_path();

openslide_t* slide = openslide_open(input_path.c_str());
if (slide == nullptr)
{
fmt::print("[Error] Cannot load {}!\n", g_config.input_file);
fmt::print("[Error] Cannot load {}!\n", input_path);
return false;
}
int64_t w, h;
Expand All @@ -159,7 +165,8 @@ int main(int argc, char** argv)
// return 1;

CLI::App app{ "cuCIM Benchmark" };
app.add_option("--test_file", g_config.input_file, "An input .tif/.svs file path");
app.add_option("--test_folder", g_config.test_folder, "An input test folder path");
app.add_option("--test_file", g_config.test_file, "An input test image file path");
app.add_option("--discard_cache", g_config.discard_cache, "Discard page cache for the input file for each iteration");
app.add_option("--random_seed", g_config.random_seed, "A random seed number");
app.add_option(
Expand Down
37 changes: 35 additions & 2 deletions cpp/plugins/cucim.kit.cuslide/benchmarks/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Apache License, Version 2.0
* Copyright 2020 NVIDIA Corporation
* Copyright 2020-2021 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,8 @@

struct AppConfig
{
std::string input_file = "test_data/private/generic_tiff_000.tif";
std::string test_folder;
std::string test_file;
bool discard_cache = false;
int random_seed = 0;
bool random_start_location = false;
Expand All @@ -42,6 +43,38 @@ struct AppConfig
std::string benchmark_color; // {auto|true|false}
std::string benchmark_counters_tabular;
std::string v; // <verbosity>

std::string get_input_path(const std::string default_value = "generated/tiff_stripe_4096x4096_256.tif") const
{
// If `test_file` is absolute path
if (!test_folder.empty() && test_file.substr(0, 1) == "/")
{
return test_file;
}
else
{
std::string test_data_folder = test_folder;
if (test_data_folder.empty())
{
if (const char* env_p = std::getenv("CUCIM_TESTDATA_FOLDER"))
{
test_data_folder = env_p;
}
else
{
test_data_folder = "test_data";
}
}
if (test_file.empty())
{
return test_data_folder + "/" + default_value;
}
else
{
return test_data_folder + "/" + test_file;
}
}
}
};

#endif // CUSLIDE_CONFIG_H
20 changes: 13 additions & 7 deletions cpp/plugins/cucim.kit.cuslide/benchmarks/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ static AppConfig g_config;

static void test_basic(benchmark::State& state)
{
std::string input_path = g_config.get_input_path();

int arg = -1;
for (auto state_item : state)
{
Expand All @@ -57,7 +59,7 @@ static void test_basic(benchmark::State& state)

if (g_config.discard_cache)
{
int fd = open(g_config.input_file.c_str(), O_RDONLY);
int fd = open(input_path.c_str(), O_RDONLY);
fdatasync(fd);
posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
close(fd);
Expand All @@ -83,7 +85,7 @@ static void test_basic(benchmark::State& state)
return;
}

auto handle = image_format->formats[0].image_parser.open(g_config.input_file.c_str());
auto handle = image_format->formats[0].image_parser.open(input_path.c_str());

cucim::io::format::ImageMetadata metadata{};
image_format->formats[0].image_parser.parse(&handle, &metadata.desc());
Expand Down Expand Up @@ -118,6 +120,8 @@ static void test_basic(benchmark::State& state)

static void test_openslide(benchmark::State& state)
{
std::string input_path = g_config.get_input_path();

int arg = -1;
for (auto _ : state)
{
Expand All @@ -132,15 +136,15 @@ static void test_openslide(benchmark::State& state)

if (g_config.discard_cache)
{
int fd = open(g_config.input_file.c_str(), O_RDONLY);
int fd = open(input_path.c_str(), O_RDONLY);
fdatasync(fd);
posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
close(fd);
}
}
state.ResumeTiming();

openslide_t* slide = openslide_open(g_config.input_file.c_str());
openslide_t* slide = openslide_open(input_path.c_str());
uint32_t* buf = static_cast<uint32_t*>(cucim_malloc(state.range(0) * state.range(0) * 4));
int64_t request_location[2] = { 0, 0 };
if (g_config.random_start_location)
Expand Down Expand Up @@ -177,10 +181,11 @@ static bool remove_help_option(int* argc, char** argv)

static bool setup_configuration()
{
openslide_t* slide = openslide_open(g_config.input_file.c_str());
std::string input_path = g_config.get_input_path();
openslide_t* slide = openslide_open(input_path.c_str());
if (slide == nullptr)
{
fmt::print("[Error] Cannot load {}!\n", g_config.input_file);
fmt::print("[Error] Cannot load {}!\n", input_path);
return false;
}

Expand All @@ -205,7 +210,8 @@ int main(int argc, char** argv)
// if (::benchmark::ReportUnrecognizedArguments(argc, argv))
// return 1;
CLI::App app{ "benchmark: cuSlide" };
app.add_option("--test_file", g_config.input_file, "An input .tif/.svs file path");
app.add_option("--test_folder", g_config.test_folder, "An input test folder path");
app.add_option("--test_file", g_config.test_file, "An input test image file path");
app.add_option("--discard_cache", g_config.discard_cache, "Discard page cache for the input file for each iteration");
app.add_option("--random_seed", g_config.random_seed, "A random seed number");
app.add_option(
Expand Down
4 changes: 2 additions & 2 deletions cpp/plugins/cucim.kit.cuslide/tests/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Apache License, Version 2.0
* Copyright 2020 NVIDIA Corporation
* Copyright 2020-2021 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,7 @@ struct AppConfig
std::string test_folder;
std::string test_file;
std::string temp_folder = "/tmp";
std::string get_input_path(const char* default_value = "private/generic_tiff_000.tif") const
std::string get_input_path(const std::string default_value = "generated/tiff_stripe_4096x4096_256.tif") const
{
// If `test_file` is absolute path
if (!test_folder.empty() && test_file.substr(0, 1) == "/")
Expand Down
7 changes: 5 additions & 2 deletions cpp/tests/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
#include <string>
#include <cstdlib>

#define XSTR(x) STR(x)
#define STR(x) #x

struct AppConfig
{
std::string test_folder;
std::string test_file;
std::string temp_folder = "/tmp";
std::string get_input_path(const char* default_value = "private/generic_tiff_000.tif") const
std::string get_input_path(const std::string default_value = "generated/tiff_stripe_4096x4096_256.tif") const
{
// If `test_file` is absolute path
if (!test_folder.empty() && test_file.substr(0, 1) == "/")
Expand Down Expand Up @@ -56,7 +59,7 @@ struct AppConfig
}
}
}
std::string get_plugin_path(const char* default_value = "cucim.kit.cuslide@0.0.0.so")
std::string get_plugin_path(const char* default_value = "cucim.kit.cuslide@" XSTR(CUCIM_VERSION) ".so")
{
std::string plugin_path = default_value;
if (const char* env_p = std::getenv("CUCIM_TEST_PLUGIN_PATH"))
Expand Down
15 changes: 15 additions & 0 deletions cpp/tests/test_read_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ SCENARIO("Verify read_region()", "[test_read_region.cpp]")
// }
printf("\ncucim count: %d\n", hash);
cucim_free(image_data.container.data);
if (image_data.container.shape)
{
cucim_free(image_data.container.shape);
image_data.container.shape = nullptr;
}
if (image_data.container.strides)
{
cucim_free(image_data.container.strides);
image_data.container.strides = nullptr;
}
if (image_data.shm_name)
{
cucim_free(image_data.shm_name);
image_data.shm_name = nullptr;
}
image_format->formats[0].image_parser.close(&handle);

auto end = std::chrono::high_resolution_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion cucim.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"cwd": "${workspaceFolder}",
"env": {
// Workaround the environment variable issue: https://github.com/microsoft/vscode/issues/121470
"PATH": "${env:PATH}"
"PATH": "${env:HOME}/.local/bin:${env:PATH}"
}
},
"presentation": {
Expand Down
1 change: 1 addition & 0 deletions python/cucim/tests/util/gen_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def gen(self):
image_size=image_size,
tile_size=tile_size,
compression=compression)
self.logger.info(' Generated %s...', image_path)
results.append(image_path)

self.logger.info('[Finished] Dataset generation')
Expand Down
11 changes: 9 additions & 2 deletions test_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

Symbolic links for for this folder is available under the following subfolders:

- `cpp/plugins/cucim.kit.cuslide
- `cpp/plugins/cucim.kit.cuslide`
- `python/cucim`

## Generated Test Data (`test_data/generated` folder)

Generated by executing `gen_images.sh`.

- tiff_stripe_32x32_16.tif
- tiff_stripe_4096x4096_256.tif

## Private Test Data (`test_data/private` folder)

- `generic_tiff_000.tif` : 256x256 multi-resolution/tiled TIF conversion of `TUPAC-TR-467.svs` from the dataset
of [Tumor Proliferation Assessment Challenge 2016](http://tupac.tue-image.nl/node/3) (TUPAC16 | MICCAI Grand Challenge) which are publicly
available through [The Cancer Genome Atlas (TCGA)](https://www.cancer.gov/about-nci/organization/ccg/research/structural-genomics/tcga) under [CC BY 3.0 License](https://creativecommons.org/licenses/by/3.0/)
- `philips_tiff_000.tif` : `patient_100_node_0.tif` from the [Camelyon16 challenge data](https://drive.google.com/drive/folders/0BzsdkU4jWx9BUzVXeUg0dUNOR1U) (another [link](https://camelyon17.grand-challenge.org/Data/)) which is under [CC0 License](https://choosealicense.com/licenses/cc0-1.0/)
- `philips_tiff_000.tif` : `normal_042.tif` from the [Camelyon16 challenge data](ftp://parrot.genomics.cn/gigadb/pub/10.5524/100001_101000/100439/CAMELYON16/training/normal/normal_042.tif) (another [link](https://camelyon17.grand-challenge.org/Data/)) which is under [CC0 License](https://choosealicense.com/licenses/cc0-1.0/)
Loading