Skip to content

Commit 8f918ca

Browse files
committed
merge conflict bringing in denoise branch
2 parents bd5e60c + c3617f0 commit 8f918ca

File tree

86 files changed

+12696
-7290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+12696
-7290
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@
77
[submodule "external/c-blosc"]
88
path = external/c-blosc
99
url = https://github.com/Blosc/c-blosc
10-
[submodule "external/pybind11"]
11-
path = external/pybind11
12-
url = https://github.com/pybind/pybind11.git

CMakeLists.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,28 @@ add_library(aprObjLib OBJECT ${SOURCE_FILES} ${SOURCE_FILES_RAYCAST})
168168
if(APR_USE_CUDA)
169169
message(STATUS "APR: Building CUDA for APR")
170170
set(CMAKE_CUDA_STANDARD 14)
171-
set(CMAKE_CUDA_FLAGS "--default-stream per-thread --cudart shared -g -lineinfo -Xptxas -O3,-v -use_fast_math -DAPR_USE_CUDA")
171+
set(CMAKE_CUDA_RUNTIME_LIBRARY "Static")
172+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --default-stream per-thread -Xptxas -v -DAPR_USE_CUDA")
173+
set(CMAKE_CUDA_FLAGS_RELEASE "-O3 --use_fast_math") # -lineinfo for profiling
174+
set(CMAKE_CUDA_FLAGS_DEBUG "-O0 -g -G")
172175
if(APR_BENCHMARK)
173176
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -DAPR_BENCHMARK")
174177
endif()
175178
enable_language(CUDA)
176179
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DAPR_USE_CUDA")
177180
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DAPR_USE_CUDA")
178-
set(APR_CUDA_SROUCE_FILES
181+
set(APR_CUDA_SOURCE_FILES
179182
src/algorithm/ComputeGradientCuda.cu
180183
src/data_structures/Mesh/PixelData.cu
181184
src/algorithm/LocalIntensityScale.cu
182185
src/algorithm/OVPC.cu
183186
src/data_structures/APR/access/GPUAccess.cu
187+
src/numerics/miscCuda.cu
184188
src/numerics/APRDownsampleGPU.cu
185-
src/numerics/APRIsoConvGPU.cu
189+
src/numerics/PixelNumericsGPU.cu
190+
src/numerics/APRIsoConvGPU333.cu
191+
src/numerics/APRIsoConvGPU555.cu
192+
src/numerics/APRNumericsGPU.cu
186193
)
187194
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
188195

@@ -191,7 +198,7 @@ endif()
191198
if(APR_BUILD_STATIC_LIB)
192199
# generate static library used as a intermediate step in generating fat lib
193200
set(STATIC_TARGET_NAME staticLib)
194-
add_library(${STATIC_TARGET_NAME} STATIC $<TARGET_OBJECTS:aprObjLib> ${APR_CUDA_SROUCE_FILES})
201+
add_library(${STATIC_TARGET_NAME} STATIC $<TARGET_OBJECTS:aprObjLib> ${APR_CUDA_SOURCE_FILES})
195202
target_compile_features(${STATIC_TARGET_NAME} PUBLIC cxx_std_14)
196203
set_target_properties(${STATIC_TARGET_NAME} PROPERTIES OUTPUT_NAME ${LIBRARY_NAME})
197204
set_target_properties(${STATIC_TARGET_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION OFF)
@@ -207,7 +214,7 @@ endif()
207214
if(APR_BUILD_SHARED_LIB)
208215
# generate fat shared library
209216
set(SHARED_TARGET_NAME sharedLib)
210-
add_library(${SHARED_TARGET_NAME} SHARED $<TARGET_OBJECTS:aprObjLib> ${APR_CUDA_SROUCE_FILES})
217+
add_library(${SHARED_TARGET_NAME} SHARED $<TARGET_OBJECTS:aprObjLib> ${APR_CUDA_SOURCE_FILES})
211218

212219
target_include_directories(${SHARED_TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
213220
set_target_properties(${SHARED_TARGET_NAME} PROPERTIES OUTPUT_NAME ${LIBRARY_NAME})
@@ -327,11 +334,6 @@ endif(APR_TESTS)
327334
###############################################################################
328335

329336
if(APR_BENCHMARK)
330-
message(STATUS "APR: Benchmarking performance")
337+
message(STATUS "APR: Building performance benchmarks")
331338
add_subdirectory(benchmarks)
332339
endif(APR_BENCHMARK)
333-
334-
###############################################################################
335-
# PYTHON wrappers These are now external please ask us for access
336-
###############################################################################
337-

INSTALL_INSTRUCTIONS.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Install instructions for LibAPR.
2+
3+
The way to use it is configure it via some new APR_* variables (can be set to ON/OFF depending on needs) which describes what to build and if it should be installed through cmake commands:
4+
5+
APR_BUILD_STATIC_LIB=ON
6+
APR_BUILD_SHARED_LIB=OFF
7+
APR_INSTALL=ON
8+
(all other configuration possibilities are now in the top of CMakeLists.txt file)
9+
10+
so full command line would look like:
11+
12+
```
13+
mkdir build
14+
cd build
15+
cmake -DCMAKE_INSTALL_PREFIX=/tmp/APR -DAPR_INSTALL=ON -DAPR_BUILD_STATIC_LIB=ON -DAPR_BUILD_SHARED_LIB=OFF ..
16+
make
17+
make install
18+
```
19+
20+
To use APR the minimalistic CMakeLists.txt file would look like:
21+
22+
```
23+
cmake_minimum_required(VERSION 3.2)
24+
project(myAprProject)
25+
set(CMAKE_CXX_STANDARD 14)
26+
27+
#external libraries needed for APR
28+
find_package(HDF5 REQUIRED)
29+
find_package(TIFF REQUIRED)
30+
include_directories(${HDF5_INCLUDE_DIRS} ${TIFF_INCLUDE_DIR} )
31+
32+
find_package(APR REQUIRED)
33+
34+
add_executable(HelloAPR helloWorld.cpp)
35+
target_link_libraries(HelloAPR ${HDF5_LIBRARIES} ${TIFF_LIBRARIES} apr::staticLib)
36+
```
37+
38+
if shared version is preferred then apr::sharedLib should be used (and of course APR_BUILD_SHARED_LIB=ON during lib build step).
39+
40+
NOTICE: if APR is isntalled in not standard directory then some hint for cmake must be provided by adding install dir to CMAKE_PREFIX_PATH like for above example:
41+
42+
```
43+
export CMAKE_PREFIX_PATH=/tmp/APR:$CMAKE_PREFIX_PATH
44+
```

README.md

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,75 @@ Labeled Zebrafish nuclei: Gopi Shah, Huisken Lab ([MPI-CBG](https://www.mpi-cbg.
99
[![Build Status](https://travis-ci.org/AdaptiveParticles/LibAPR.svg?branch=master)](https://travis-ci.org/AdaptiveParticles/LibAPR)
1010
[![DOI](https://zenodo.org/badge/70479293.svg)](https://zenodo.org/badge/latestdoi/70479293)
1111

12+
13+
## Python support
14+
15+
We now provide python wrappers in a separate repository [PyLibAPR](https://github.com/AdaptiveParticles/PyLibAPR)
16+
17+
In addition to providing wrappers for most of the LibAPR functionality, the Python library contains a number of new features that simplify the generation and handling of the APR. For example:
18+
19+
* Interactive APR conversion
20+
* Interactive APR z-slice viewer
21+
* Interactive APR raycast (maximum intensity projection) viewer
22+
* Interactive lossy compression of particle intensities
23+
24+
25+
## Version 2.0 release notes
26+
27+
The library has changed significantly since release 1.1. __There are changes to IO and iteration that are not compatible
28+
with the older version__.
29+
30+
* New (additional) linear access data structure, explicitly storing coordinates in the sparse dimension,
31+
similar to Compressed Sparse Row.
32+
* Block-based decomposition of the APR generation pipeline, allowing conversion of very large images.
33+
* Expanded and improved functionality for image processing directly on the APR:
34+
* APR filtering (spatial convolutions).
35+
* [APRNumerics](./src/numerics/APRNumerics.hpp) module, including e.g. gradient computations and Richardson-Lucy deconvolution.
36+
* CUDA GPU-accelerated convolutions and RL deconvolution (currently only supports dense 3x3x3 and 5x5x5 stencils)
37+
38+
1239
## Dependencies
1340

1441
* HDF5 1.8.20 or higher
15-
* OpenMP > 3.0 (optional, but suggested)
42+
* OpenMP > 3.0 (optional, but recommended)
1643
* CMake 3.6 or higher
1744
* LibTIFF 4.0 or higher
1845

46+
1947
NB: This update to 2.0 introduces changes to IO and iteration that are not compatable with old versions.
2048

2149
If compiling with APR_DENOISE flag the package also requires:
2250
* Eigen3.
2351

2452
## Building
2553

26-
The repository requires sub-modules, so the repository needs to be cloned recursively:
54+
The repository requires submodules, and needs to be cloned recursively:
2755

2856
```
29-
git clone --recursive https://github.com/cheesema/LibAPR
57+
git clone --recursive https://github.com/AdaptiveParticles/LibAPR.git
3058
```
3159

32-
If you need to update your clone at any point later, run
60+
### CMake build options
3361

62+
Several CMake options can be given to control the build. Use the `-D` argument to set each
63+
desired option. For example, to disable OpenMP, change the cmake calls below to
3464
```
35-
git pull
36-
git submodule update
65+
cmake -DAPR_USE_OPENMP=OFF ..
3766
```
3867

68+
| Option | Description | Default value |
69+
|:--|:--|:--|
70+
| APR_BUILD_SHARED_LIB | Build shared library | ON |
71+
| APR_BUILD_STATIC_LIB | Build static library | OFF |
72+
| APR_BUILD_EXAMPLES | Build executable examples | OFF |
73+
| APR_TESTS | Build unit tests | OFF |
74+
| APR_BENCHMARK | Build executable performance benchmarks | OFF |
75+
| APR_USE_LIBTIFF | Enable LibTIFF (Required for tests and examples) | ON |
76+
| APR_PREFER_EXTERNAL_GTEST | Use installed gtest instead of included sources | OFF |
77+
| APR_PREFER_EXTERNAL_BLOSC | Use installed blosc instead of included sources | OFF |
78+
| APR_USE_OPENMP | Enable multithreading via OpenMP | ON |
79+
| APR_USE_CUDA | Enable CUDA (Under development - APR conversion pipeline is currently not working with CUDA enabled) | OFF |
80+
3981
### Building on Linux
4082

4183
On Ubuntu, install the `cmake`, `build-essential`, `libhdf5-dev` and `libtiff5-dev` packages (on other distributions, refer to the documentation there, the package names will be similar). OpenMP support is provided by the GCC compiler installed as part of the `build-essential` package.
@@ -51,11 +93,7 @@ cmake ..
5193
make
5294
```
5395

54-
This will create the `libapr.so` library in the `build` directory, as well as all of the examples.
55-
56-
### Docker build
57-
58-
We provide a working Dockerfile that install the library within the image on a separate [repo](https://github.com/MSusik/libaprdocker).
96+
This will create the `libapr.so` library in the `build` directory.
5997

6098
### Building on OSX
6199

@@ -72,7 +110,8 @@ cmake ..
72110
make
73111
```
74112

75-
This will create the `libapr.dylib` library in the `build` directory, as well as all of the examples.
113+
This will create the `libapr.dylib` library in the `build` directory.
114+
76115

77116
In case you want to use the homebrew-installed clang (OpenMP support), modify the call to `cmake` above to
78117

@@ -101,56 +140,60 @@ cmake -G "Visual Studio 15 2017 Win64" -DTIFF_INCLUDE_DIR="C:/Program Files/tiff
101140
cmake --build . --config Debug
102141
```
103142

104-
This will set the appropriate hints for Visual Studio to find both LibTIFF and HDF5. This will create the `apr.dll` library in the `build/Debug` directory, as well as all of the examples. If you need a `Release` build, run `cmake --build . --config Release` from the `build` directory.
143+
This will set the appropriate hints for Visual Studio to find both LibTIFF and HDF5. This will create the `apr.dll` library in the `build/Debug` directory. If you need a `Release` build, run `cmake --build . --config Release` from the `build` directory.
144+
145+
### Docker build
146+
147+
We provide a working Dockerfile that installs the library within the image in a separate [repository](https://github.com/MSusik/libaprdocker).
148+
149+
Note: not recently tested.
105150

106151
## Examples and Documentation
107-
These examples can be turned on by adding -DAPR_BUILD_EXAMPLES=ON to the cmake command.
108152

109-
There are nine basic examples, that show how to generate and compute with the APR:
153+
There are 12 basic examples, that show how to generate and compute with the APR. These can be built by adding
154+
-DAPR_BUILD_EXAMPLES=ON to the cmake command.
110155

111156
| Example | How to ... |
112157
|:--|:--|
113158
| [Example_get_apr](./examples/Example_get_apr.cpp) | create an APR from a TIFF and store as hdf5. |
114-
| [Example_apr_iterate](./examples/Example_apr_iterate.cpp) | iterate through a given APR. |
159+
| [Example_get_apr_by_block](./examples/Example_get_apr_by_block.cpp) | create an APR from a (potentially large) TIFF, by decomposing it into smaller blocks, and store as hdf5.
160+
| [Example_apr_iterate](./examples/Example_apr_iterate.cpp) | iterate over APR particles and their spatial properties. |
161+
| [Example_apr_tree](./examples/Example_apr_tree.cpp) | iterate over interior APR tree particles and their spatial properties. |
115162
| [Example_neighbour_access](./examples/Example_neighbour_access.cpp) | access particle and face neighbours. |
116163
| [Example_compress_apr](./examples/Example_compress_apr.cpp) | additionally compress the intensities stored in an APR. |
117164
| [Example_random_access](./examples/Example_random_access.cpp) | perform random access operations on particles. |
118-
| [Example_ray_cast](./examples/Example_ray_cast.cpp) | perform a maximum intensity projection ray cast directly on the APR data structures read from an APR. |
165+
| [Example_ray_cast](./examples/Example_ray_cast.cpp) | perform a maximum intensity projection ray cast directly on the APR. |
119166
| [Example_reconstruct_image](./examples/Example_reconstruct_image.cpp) | reconstruct a pixel image from an APR. |
167+
| [Example_compute_gradient](./examples/Example_compute_gradient.cpp) | compute the gradient magnitude of an APR. |
168+
| [Example_apr_filter](./examples/Example_apr_filter.cpp) | apply a filter (convolution) to an APR. |
169+
| [Example_apr_deconvolution](./examples/Example_apr_deconvolution.cpp) | perform Richardson-Lucy deconvolution on an APR. |
120170

121-
All examples except Example_get_apr require an already produced APR, such as those created by Example_get_apr.
171+
All examples except `Example_get_apr` and `Example_get_apr_by_block` require an already produced APR, such as those created by `Example_get_apr*`.
122172

123173
For tutorial on how to use the examples, and explanation of data-structures see [the library guide](./docs/lib_guide.pdf).
124174

125175
## LibAPR Tests
126176

127-
The testing framework can be turned on by adding -DAPR_TESTS=ON to the cmake command. All tests can then be run by executing on the command line your build folder.
177+
The testing framework can be turned on by adding -DAPR_TESTS=ON to the cmake command. All tests can then be run by executing
128178
```
129179
ctest
130180
```
131-
Please let us know by creating an issue, if any of these tests are failing on your machine.
132-
133-
## Python support
134-
135-
Note: These have been updated and externalised, and will be released shortly.
181+
on the command line in your build folder. Please let us know by creating an issue, if any of these tests are failing on your machine.
136182

137183
## Java wrappers
138184

139185
Basic Java wrappers can be found at [LibAPR-java-wrapper](https://github.com/krzysg/LibAPR-java-wrapper)
140186

141187
## Coming soon
142188

143-
* more examples for APR-based filtering and segmentation
144-
* deployment of the Java wrappers to Maven Central so they can be used in your project directly
145-
* support for loading the APR in [Fiji](https://fiji.sc), including [scenery-based](https://github.com/scenerygraphics/scenery) 3D rendering
146-
* improved java wrapper support
147-
* CUDA GPU-accelerated APR generation and processing
148-
* Block based decomposition for extremely large images.
189+
* Improved documentation and updated library guide.
190+
* More examples of APR-based image processing and segmentation.
191+
* CUDA GPU-accelerated APR generation and additional processing options.
149192
* Time series support.
150193

151194
## Contact us
152195

153-
If anything is not working as you think it should, or would like it to, please get in touch with us!! Further, if you have a project, or algorithm, you would like to try using the APR for also please get in contact we would be glad to help!
196+
If anything is not working as you think it should, or would like it to, please get in touch with us!! Further, dont hesitate to contact us if you have a project or algorithm you would like to try using the APR for. We would be glad to help!
154197

155198
[![Join the chat at https://gitter.im/LibAPR](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/LibAPR/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
156199

benchmarks/APRBenchHelper.hpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct cmdLineBenchOptions{
2626
int number_reps = 1;
2727
int dimension = 3;
2828
bool no_pixel = false;
29+
bool bench_lr = false;
2930

3031
std::string analysis_file_name = "analysis";
3132
std::string output_dir = "";
@@ -86,6 +87,11 @@ cmdLineBenchOptions read_bench_command_line_options(int argc, char **argv){
8687
result.no_pixel = true;
8788
}
8889

90+
if(command_option_exists(argv, argv + argc, "-bench_lr"))
91+
{
92+
result.bench_lr = true;
93+
}
94+
8995
return result;
9096

9197
}
@@ -259,9 +265,9 @@ class APRBenchHelper {
259265

260266
auto it = apr_input.iterator();
261267

262-
float check_y = log2(1.0f * it.org_dims(0));
263-
float check_x = log2(1.0f * it.org_dims(1));
264-
float check_z = log2(1.0f * it.org_dims(2));
268+
float check_y = log2f(1.0f * it.org_dims(0));
269+
float check_x = log2f(1.0f * it.org_dims(1));
270+
float check_z = log2f(1.0f * it.org_dims(2));
265271

266272
//this function only works for datasets that are powers of 2.
267273
bool pow_2y = (check_y - std::floor(check_y)) == 0;
@@ -314,14 +320,14 @@ class APRBenchHelper {
314320
timer.start_timer("first loop");
315321

316322
//first do the y extension.
317-
for (unsigned int level = lin_it.level_min(); level <= lin_it.level_max(); ++level) {
323+
for (int level = lin_it.level_min(); level <= lin_it.level_max(); ++level) {
318324
int z = 0;
319325
int x = 0;
320326

321327
int new_level = level_offset + level;
322328

323329
#ifdef HAVE_OPENMP
324-
#pragma omp parallel for schedule(dynamic) private(z,x) firstprivate(lin_it,lin_it_tiled)
330+
#pragma omp parallel for schedule(dynamic) default(shared) private(z,x) firstprivate(lin_it,lin_it_tiled)
325331
#endif
326332
for (z = 0; z < lin_it.z_num(level); z++) {
327333
for (x = 0; x < lin_it.x_num(level); ++x) {
@@ -358,14 +364,14 @@ class APRBenchHelper {
358364
timer.start_timer("second loop");
359365

360366
//first do the y extension.
361-
for (unsigned int level = lin_it.level_min(); level <= lin_it.level_max(); ++level) {
367+
for (int level = lin_it.level_min(); level <= lin_it.level_max(); ++level) {
362368
int z = 0;
363369
int x = 0;
364370

365371
int new_level = level_offset + level;
366372

367373
#ifdef HAVE_OPENMP
368-
#pragma omp parallel for schedule(dynamic) private(z,x) firstprivate(lin_it,lin_it_tiled)
374+
#pragma omp parallel for schedule(dynamic) default(shared) private(z,x) firstprivate(lin_it,lin_it_tiled)
369375
#endif
370376
for (z = 0; z < lin_it.z_num(level); z++) {
371377
for (x = 0; x < lin_it.x_num(level); ++x) {

benchmarks/BenchCudaAccessInit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ inline void bench_access_partial(APR& apr,ParticleData<partsType>& parts,int num
120120
error_check( cudaGetLastError() )
121121

122122
auto access = apr.gpuAPRHelper();
123-
access.init_gpu(access.total_number_particles(tree_access.level_max()), tree_access);
123+
access.init_gpu(tree_access);
124124
error_check ( cudaDeviceSynchronize() )
125125
error_check( cudaGetLastError() )
126126
}
@@ -137,7 +137,7 @@ inline void bench_access_partial(APR& apr,ParticleData<partsType>& parts,int num
137137

138138
timer2.start_timer("apr access");
139139
auto access = apr.gpuAPRHelper();
140-
access.init_gpu(access.total_number_particles(tree_access.level_max()), tree_access);
140+
access.init_gpu(tree_access);
141141
error_check ( cudaDeviceSynchronize() )
142142
timer2.stop_timer();
143143
apr_time += timer2.timings.back();

0 commit comments

Comments
 (0)