├── .clang-format ├── .github ├── dependabot.yml └── workflows │ ├── build-test.yml │ ├── pages.yml │ ├── release-notification.yml │ └── tests_and_coverage.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE ├── README.md ├── benchmark ├── CMakeLists.txt ├── README.md ├── benchmark_base.cpp ├── benchmark_dummy.cpp ├── benchmark_maximum_projections.cpp ├── benchmark_mean.cpp ├── benchmark_means_comparison.cpp └── benchmark_push_pull.cpp ├── clic ├── CMakeLists.txt ├── clic.hpp.in ├── include │ ├── array.hpp │ ├── backend.hpp │ ├── cache.hpp │ ├── cle.hpp │ ├── device.hpp │ ├── execution.hpp │ ├── fft.hpp │ ├── statistics.hpp │ ├── tier0.hpp │ ├── tier1.hpp │ ├── tier2.hpp │ ├── tier3.hpp │ ├── tier4.hpp │ ├── tier5.hpp │ ├── tier6.hpp │ ├── tier7.hpp │ ├── tier8.hpp │ ├── transform.hpp │ └── utils.hpp ├── src │ ├── array.cpp │ ├── backendmanager.cpp │ ├── cudabackend.cpp │ ├── cudadevice.cpp │ ├── execution.cpp │ ├── fft.cpp │ ├── openclbackend.cpp │ ├── opencldevice.cpp │ ├── statistics.cpp │ ├── tier0.cpp │ ├── tier1 │ │ ├── absolute.cpp │ │ ├── add_image_and_scalar.cpp │ │ ├── add_images_weighted.cpp │ │ ├── binary_and.cpp │ │ ├── binary_edge_detection.cpp │ │ ├── binary_infsup.cpp │ │ ├── binary_not.cpp │ │ ├── binary_or.cpp │ │ ├── binary_subtract.cpp │ │ ├── binary_supinf.cpp │ │ ├── binary_xor.cpp │ │ ├── block_enumerate.cpp │ │ ├── circular_shift.cpp │ │ ├── convolve.cpp │ │ ├── copy.cpp │ │ ├── copy_slice.cpp │ │ ├── crop.cpp │ │ ├── cubic_root.cpp │ │ ├── detect_label_edges.cpp │ │ ├── dilation.cpp │ │ ├── divide_images.cpp │ │ ├── divide_scalar_by_image.cpp │ │ ├── equal.cpp │ │ ├── equal_constant.cpp │ │ ├── erosion.cpp │ │ ├── exponential.cpp │ │ ├── flip.cpp │ │ ├── gaussian_blur.cpp │ │ ├── generate_distance_matrix.cpp │ │ ├── gradients.cpp │ │ ├── greater.cpp │ │ ├── greater_constant.cpp │ │ ├── greater_or_equal.cpp │ │ ├── greater_or_equal_constant.cpp │ │ ├── hessian_eigenvalues.cpp │ │ ├── laplace_filter.cpp │ │ ├── local_cross_correlation.cpp │ │ ├── logarithm.cpp │ │ ├── mask.cpp │ │ ├── mask_label.cpp │ │ ├── maximum_filter.cpp │ │ ├── maximum_image_and_scalar.cpp │ │ ├── maximum_images.cpp │ │ ├── maximum_x_projection.cpp │ │ ├── maximum_y_projection.cpp │ │ ├── maximum_z_projection.cpp │ │ ├── mean_filter.cpp │ │ ├── mean_x_projection.cpp │ │ ├── mean_y_projection.cpp │ │ ├── mean_z_projection.cpp │ │ ├── median.cpp │ │ ├── minimum_filter.cpp │ │ ├── minimum_image_and_scalar.cpp │ │ ├── minimum_images.cpp │ │ ├── minimum_of_masked_pixels_reduction.cpp │ │ ├── minimum_x_projection.cpp │ │ ├── minimum_y_projection.cpp │ │ ├── minimum_z_projection.cpp │ │ ├── mode.cpp │ │ ├── modulo_images.cpp │ │ ├── multiply_image_and_position.cpp │ │ ├── multiply_image_and_scalar.cpp │ │ ├── multiply_images.cpp │ │ ├── multiply_matrix.cpp │ │ ├── nan_to_num.cpp │ │ ├── nonzero_maximum.cpp │ │ ├── nonzero_minimum.cpp │ │ ├── not_equal.cpp │ │ ├── not_equal_constant.cpp │ │ ├── onlyzero_overwrite_maximum.cpp │ │ ├── pad.cpp │ │ ├── paste.cpp │ │ ├── power.cpp │ │ ├── power_images.cpp │ │ ├── range.cpp │ │ ├── read_values_from_positions.cpp │ │ ├── reciprocal.cpp │ │ ├── replace_values.cpp │ │ ├── set.cpp │ │ ├── set_column.cpp │ │ ├── set_image_borders.cpp │ │ ├── set_nonzero_pixels_to_pixelindex.cpp │ │ ├── set_plane.cpp │ │ ├── set_ramp.cpp │ │ ├── set_row.cpp │ │ ├── set_where_x_equals_y.cpp │ │ ├── set_where_x_greater_than_y.cpp │ │ ├── set_where_x_smaller_than_y.cpp │ │ ├── sign.cpp │ │ ├── smaller.cpp │ │ ├── smaller_constant.cpp │ │ ├── smaller_or_equal.cpp │ │ ├── smaller_or_equal_constant.cpp │ │ ├── sobel.cpp │ │ ├── square_root.cpp │ │ ├── std_z_projection.cpp │ │ ├── subtract_image_from_scalar.cpp │ │ ├── sum_projection.cpp │ │ ├── sum_reduction_x.cpp │ │ ├── transpose_xy.cpp │ │ ├── transpose_xz.cpp │ │ ├── transpose_yz.cpp │ │ ├── undefined_to_zero.cpp │ │ ├── variance.cpp │ │ ├── write_values_to_positions.cpp │ │ ├── x_position_of_maximum_x_projection.cpp │ │ ├── x_position_of_minimum_x_projection.cpp │ │ ├── y_position_of_maximum_y_projection.cpp │ │ ├── y_position_of_minimum_y_projection.cpp │ │ ├── z_position_of_maximum_z_projection.cpp │ │ ├── z_position_of_minimum_z_projection.cpp │ │ └── z_position_projection_func.cpp │ ├── tier2 │ │ ├── absolute_difference.cpp │ │ ├── add_images.cpp │ │ ├── bottom_hat.cpp │ │ ├── clip.cpp │ │ ├── closing.cpp │ │ ├── concatenate_along_x.cpp │ │ ├── concatenate_along_y.cpp │ │ ├── concatenate_along_z.cpp │ │ ├── count_touching_neighbors.cpp │ │ ├── crop_border.cpp │ │ ├── degrees_to_radians.cpp │ │ ├── detect_maxima.cpp │ │ ├── detect_minima.cpp │ │ ├── difference_of_gaussian.cpp │ │ ├── divide_by_gaussian_background.cpp │ │ ├── extend_labeling_via_voronoi.cpp │ │ ├── extended_depth_of_focus_variance_projection.cpp │ │ ├── invert.cpp │ │ ├── label_spots.cpp │ │ ├── large_hessian_eigenvalue.cpp │ │ ├── maximum_of_all_pixels.cpp │ │ ├── minimum_of_all_pixels.cpp │ │ ├── minimum_of_masked_pixels.cpp │ │ ├── opening.cpp │ │ ├── radians_to_degrees.cpp │ │ ├── reduce_labels_to_label_edges.cpp │ │ ├── small_hessian_eigenvalue.cpp │ │ ├── square.cpp │ │ ├── squared_difference.cpp │ │ ├── stack_operations.cpp │ │ ├── standard_deviation.cpp │ │ ├── subtract_gaussian_background.cpp │ │ ├── subtract_images.cpp │ │ ├── sum_of_all_pixels.cpp │ │ └── top_hat.cpp │ ├── tier3 │ │ ├── bounding_box.cpp │ │ ├── center_of_mass.cpp │ │ ├── clahe.cpp │ │ ├── flag_existing_labels.cpp │ │ ├── gamma_correction.cpp │ │ ├── generate_binary_overlap_matrix.cpp │ │ ├── generate_touch_matrix.cpp │ │ ├── histogram.cpp │ │ ├── jaccard_index.cpp │ │ ├── labelled_spots_to_pointlist.cpp │ │ ├── maximum_position.cpp │ │ ├── mean_of_all_pixels.cpp │ │ ├── minimum_position.cpp │ │ ├── morphological_chan_vese.cpp │ │ ├── remove_labels.cpp │ │ ├── remove_labels_on_edges.cpp │ │ └── statistics_of_labelled_pixels.cpp │ ├── tier4 │ │ ├── centroids_of_labels.cpp │ │ ├── filter_label_by_values.cpp │ │ ├── label_bounding_box.cpp │ │ ├── mean_squared_error.cpp │ │ ├── parametrics_map.cpp │ │ ├── relabel_sequential.cpp │ │ ├── spots_to_pointlist.cpp │ │ └── threshold_otsu.cpp │ ├── tier5 │ │ ├── array_equal.cpp │ │ ├── combine_labels.cpp │ │ ├── connected_component_labeling.cpp │ │ ├── filter_label_by_size.cpp │ │ └── reduce_labels_to_centroids.cpp │ ├── tier6 │ │ ├── dilate_labels.cpp │ │ ├── erode_labels.cpp │ │ ├── gauss_otsu_labeling.cpp │ │ ├── masked_voronoi_labeling.cpp │ │ ├── remove_objects.cpp │ │ └── voronoi_labeling.cpp │ ├── tier7 │ │ ├── affine_transform.cpp │ │ ├── closing_labels.cpp │ │ ├── erode_connected_labels.cpp │ │ ├── eroded_otsu_labeling.cpp │ │ ├── opening_labels.cpp │ │ ├── rigid_transform.cpp │ │ ├── rotate.cpp │ │ ├── scale.cpp │ │ ├── translate.cpp │ │ └── voronoi_otsu_labeling.cpp │ ├── tier8 │ │ ├── fft.cpp │ │ ├── smooth_connected_labels.cpp │ │ └── smooth_labels.cpp │ └── transform.cpp └── thirdparty │ └── CMakeLists.txt ├── cmake ├── CLIcConfig.cmake.in ├── CMakeBackends.cmake ├── CMakeDoxygen.cmake ├── CMakeRegistery.cmake ├── CMakeSetEnv.cmake ├── Install.cmake ├── Uninstall.cmake.in └── presets │ ├── CMakePresets.json │ ├── linux │ └── CMakePresets.json │ ├── macos │ └── CMakePresets.json │ └── windows │ └── CMakePresets.json ├── docs ├── CMakeLists.txt ├── Doxyfile ├── Doxyfile.in ├── Makefile ├── build_doc.py ├── index.html ├── make.bat └── source │ ├── _templates │ └── versions.html │ ├── api │ ├── array.rst │ ├── backend.rst │ ├── device.rst │ └── tiers.rst │ ├── conf.py │ ├── doc │ ├── compilation.rst │ ├── contributing.rst │ ├── functions.rst │ ├── tests.rst │ └── usage.rst │ ├── images │ ├── logo_d.png │ ├── logo_d_small.png │ └── logo_w.png │ ├── index.rst │ └── versions.yaml └── tests ├── CMakeLists.txt ├── core ├── CMakeLists.txt ├── test_array.cpp ├── test_backends.cpp ├── test_create_dst.cpp ├── test_device.cpp ├── test_execute.cpp ├── test_image.cpp └── test_transform.cpp ├── tier1 ├── CMakeLists.txt ├── test_absolute.cpp ├── test_add_image_and_scalar.cpp ├── test_add_image_weighted.cpp ├── test_binary_and.cpp ├── test_binary_edge_detection.cpp ├── test_binary_inf_sup.cpp ├── test_binary_not.cpp ├── test_binary_or.cpp ├── test_binary_subtract.cpp ├── test_binary_sup_inf.cpp ├── test_binary_xor.cpp ├── test_block_enumerate.cpp ├── test_circular_shift.cpp ├── test_convolve.cpp ├── test_copy.cpp ├── test_copy_horizontal_slice.cpp ├── test_copy_slice.cpp ├── test_copy_vertical_slice.cpp ├── test_crop.cpp ├── test_cubic_root.cpp ├── test_detect_label_edge.cpp ├── test_dilate.cpp ├── test_dilation.cpp ├── test_divide_images.cpp ├── test_divide_scalar_by_image.cpp ├── test_equal.cpp ├── test_equal_constant.cpp ├── test_erode.cpp ├── test_erosion.cpp ├── test_exponential.cpp ├── test_flip.cpp ├── test_gaussian_blur.cpp ├── test_generate_distance_matrix.cpp ├── test_gradient_x.cpp ├── test_gradient_y.cpp ├── test_gradient_z.cpp ├── test_greater.cpp ├── test_greater_constant.cpp ├── test_greater_or_equal.cpp ├── test_greater_or_equal_constant.cpp ├── test_laplace.cpp ├── test_local_cross_correlation.cpp ├── test_logarithm.cpp ├── test_mask.cpp ├── test_mask_label.cpp ├── test_maximum.cpp ├── test_maximum_image_and_scalar.cpp ├── test_maximum_images.cpp ├── test_maximum_x_projection.cpp ├── test_maximum_y_projection.cpp ├── test_maximum_z_projection.cpp ├── test_mean.cpp ├── test_mean_x_projection.cpp ├── test_mean_y_projection.cpp ├── test_mean_z_projection.cpp ├── test_median.cpp ├── test_minimum.cpp ├── test_minimum_image_and_scalar.cpp ├── test_minimum_images.cpp ├── test_minimum_x_projection.cpp ├── test_minimum_y_projection.cpp ├── test_minimum_z_projection.cpp ├── test_mode.cpp ├── test_modulo_images.cpp ├── test_multiply_image_and_position.cpp ├── test_multiply_image_and_scalar.cpp ├── test_multiply_images.cpp ├── test_multiply_matrix.cpp ├── test_nan_to_num.cpp ├── test_nonzero_maximum.cpp ├── test_nonzero_minimum.cpp ├── test_not_equal.cpp ├── test_not_equal_constant.cpp ├── test_onlyzero_overwrite_maximum.cpp ├── test_padding.cpp ├── test_paste.cpp ├── test_power.cpp ├── test_power_images.cpp ├── test_range.cpp ├── test_read_intensities_from_positions.cpp ├── test_read_write_with_positions.cpp ├── test_reciprocal.cpp ├── test_replace_intensities.cpp ├── test_replace_intensity.cpp ├── test_set.cpp ├── test_set_column.cpp ├── test_set_image_border.cpp ├── test_set_nonzero_pixels_to_pixelindex.cpp ├── test_set_plane.cpp ├── test_set_ramp.cpp ├── test_set_row.cpp ├── test_sign.cpp ├── test_smaller.cpp ├── test_smaller_constant.cpp ├── test_smaller_or_equal.cpp ├── test_smaller_or_equal_constant.cpp ├── test_sobel.cpp ├── test_square_root.cpp ├── test_std_z_projection.cpp ├── test_subtract_image_and_scalar.cpp ├── test_sum_reduction_x.cpp ├── test_sum_x_projection.cpp ├── test_sum_y_projection.cpp ├── test_sum_z_projection.cpp ├── test_transpose.cpp ├── test_undefined_to_zero.cpp ├── test_variance.cpp ├── test_where_x.cpp └── test_write_values_to_positions.cpp ├── tier2 ├── CMakeLists.txt ├── test_absolute_difference.cpp ├── test_bottom_hat.cpp ├── test_clip.cpp ├── test_closing.cpp ├── test_concatenate.cpp ├── test_count_neighbour.cpp ├── test_crop_border.cpp ├── test_deg_to_rad.cpp ├── test_detect_maxima.cpp ├── test_detect_minima.cpp ├── test_difference_of_gaussian.cpp ├── test_extend_labeling_via_voronoi.cpp ├── test_hessian_eigenvalues.cpp ├── test_images_operations.cpp ├── test_invert.cpp ├── test_label_spots.cpp ├── test_maximum_all_pixels.cpp ├── test_minimum_all_pixels.cpp ├── test_minimum_of_masked_pixels.cpp ├── test_opening.cpp ├── test_rad_deg.cpp ├── test_reduce_labels_to_label_edges.cpp ├── test_standard_deviation.cpp ├── test_sum_all_pixels.cpp └── test_top_hat.cpp ├── tier3 ├── CMakeLists.txt ├── test_bounding_box.cpp ├── test_exclude_labels.cpp ├── test_flag_existing_labels.cpp ├── test_gamma_correction.cpp ├── test_generate_binary_overlap_matrix.cpp ├── test_generate_touch_mat.cpp ├── test_histogram.cpp ├── test_jaccard_index.cpp ├── test_label_spot_to_pointlist.cpp ├── test_label_statistics.cpp ├── test_minmax_position.cpp └── test_morphological_chan_vese.cpp ├── tier4 ├── CMakeLists.txt ├── test_centroids_of_labels.cpp ├── test_label_bounding_box.cpp ├── test_label_pixelcount_map.cpp ├── test_mean_intensity_map.cpp ├── test_mean_square_error.cpp ├── test_spots_to_pointlist.cpp └── test_threshold_otsu.cpp ├── tier5 ├── CMakeLists.txt ├── test_array_comparison.cpp ├── test_combide_labels.cpp ├── test_connected_component_labeling.cpp ├── test_filter_labels_by_size.cpp └── test_reduce_labels_to_centroids.cpp ├── tier6 ├── CMakeLists.txt ├── test_gauss_otsu_labeling.cpp ├── test_masked_voronoi_labeling.cpp └── test_voronoi_labeling.cpp ├── tier7 ├── CMakeLists.txt ├── test_affine_transform.cpp ├── test_erode_connected_labels.cpp ├── test_eroded_otsu_labeling.cpp ├── test_label_operations.cpp ├── test_rigid_transform.cpp ├── test_rotate.cpp ├── test_scale.cpp ├── test_translation.cpp └── test_voronoi_otsu_labeling.cpp └── tier8 ├── CMakeLists.txt ├── test_fft.cpp ├── test_smooth_connected_labels.cpp └── test_smooth_labels.cpp /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "github-actions" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.github/workflows/release-notification.yml: -------------------------------------------------------------------------------- 1 | name: Release Notification 2 | 3 | on: 4 | release: 5 | types: [published] 6 | workflow_dispatch: # This allows manual triggering 7 | 8 | jobs: 9 | release-notification: 10 | runs-on: ubuntu-latest 11 | steps: 12 | 13 | - name: Fetch latest release tag 14 | run: | 15 | latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) 16 | echo "LATEST_RELEASE_TAG=$latest_release" >> $GITHUB_ENV 17 | 18 | - name: Send dispatch event to bot_playground repository 19 | env: 20 | PAT: ${{ secrets.TOKEN_SR }} 21 | run: | 22 | curl -X POST \ 23 | -H "Accept: application/vnd.github.v3+json" \ 24 | -H "Authorization: token $PAT" \ 25 | https://api.github.com/repos/clEsperanto/pyclesperanto/dispatches \ 26 | -d '{"event_type":"clic_update", "client_payload": {"release_tag": "${{ env.LATEST_RELEASE_TAG }}"}}' 27 | 28 | - name: Send dispatch event to bot_playground repository 29 | env: 30 | PAT: ${{ secrets.TOKEN_SR }} 31 | run: | 32 | curl -X POST \ 33 | -H "Accept: application/vnd.github.v3+json" \ 34 | -H "Authorization: token $PAT" \ 35 | https://api.github.com/repos/clEsperanto/clesperantoj_prototype/dispatches \ 36 | -d '{"event_type":"clic_update", "client_payload": {"release_tag": "${{ env.LATEST_RELEASE_TAG }}"}}' 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Folders 2 | .vscode 3 | build 4 | builds 5 | install 6 | .mypy_cache 7 | .ipynb_checkpoints 8 | 9 | # Specific files/folders 10 | cle_preamble.h 11 | clic.hpp 12 | cleKernelList.hpp 13 | clic/kernels 14 | 15 | #CMake 16 | CMakeUserPresets.json 17 | 18 | 19 | # System files 20 | .DS_Store 21 | 22 | # Prerequisites 23 | *.d 24 | 25 | # Compiled Object Files 26 | *.slo 27 | *.lo 28 | *.o 29 | *.obj 30 | 31 | # Precompiled Headers 32 | *.gch 33 | *.pch 34 | 35 | # Compiled Dynamic Libraries 36 | *.so 37 | *.dylib 38 | *.dll 39 | 40 | #Compiled Static libraries 41 | *.lai 42 | *.la 43 | *.a 44 | *.lib 45 | 46 | # Executables 47 | *.exe 48 | *.out 49 | *.app 50 | *.iml 51 | /.idea/ 52 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See https://pre-commit.com for more information 2 | # See https://pre-commit.com/hooks.html for more hooks 3 | ci: 4 | autoupdate_schedule: monthly 5 | autofix_commit_msg: "style(pre-commit.ci): auto fixes" 6 | autoupdate_commit_msg: "ci(pre-commit.ci): auto update" 7 | 8 | repos: 9 | - repo: https://github.com/pre-commit/pre-commit-hooks 10 | rev: v5.0.0 11 | hooks: 12 | - id: check-yaml 13 | - id: trailing-whitespace 14 | - id: end-of-file-fixer 15 | - id: check-added-large-files 16 | - id: check-case-conflict 17 | - id: check-merge-conflict 18 | - id: check-symlinks 19 | - id: mixed-line-ending 20 | 21 | - repo: https://github.com/pre-commit/mirrors-clang-format 22 | rev: v20.1.3 23 | hooks: 24 | - id: clang-format 25 | types_or: [c++, c] 26 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | 3 | project(CLIc VERSION 0.17.1) 4 | 5 | set(kernel_version_tag "3.2.0" CACHE STRING "clEsperanto kernel version tag") # "3.1.1" 6 | set(eigen_lib_version_tag "3.4.0" CACHE STRING "Eigen library version tag") 7 | 8 | # if not set, set the default build type to Release 9 | if(NOT CLE_BACKEND_TYPE) 10 | set(CLE_BACKEND_TYPE "OPENCL" CACHE STRING "Backend to use (CUDA or OCL)") 11 | endif() 12 | 13 | # set environment variables 14 | include(${PROJECT_SOURCE_DIR}/cmake/CMakeSetEnv.cmake) 15 | # find library dependencies 16 | include(${PROJECT_SOURCE_DIR}/cmake/CMakeBackends.cmake) 17 | 18 | # build clic library 19 | add_subdirectory(clic) 20 | 21 | # Build and run tests if BUILD_TESTING is ON (-DBUILD_TESTING=ON) 22 | if(BUILD_TESTING) 23 | include(CTest) 24 | add_subdirectory(${PROJECT_SOURCE_DIR}/tests) 25 | endif(BUILD_TESTING) 26 | 27 | # Build documentation if BUILD_DOCUMENTATION is ON (-DBUILD_DOCUMENTATION=ON) 28 | if (BUILD_DOCUMENTATION) 29 | add_subdirectory(${PROJECT_SOURCE_DIR}/docs) 30 | endif() 31 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "cmakeMinimumRequired": { 4 | "major": 3, 5 | "minor": 20, 6 | "patch": 0 7 | }, 8 | "include": [ 9 | "cmake/presets/linux/CMakePresets.json", 10 | "cmake/presets/macos/CMakePresets.json", 11 | "cmake/presets/windows/CMakePresets.json" 12 | ], 13 | "configurePresets": [], 14 | "buildPresets": [], 15 | "testPresets": [] 16 | } 17 | -------------------------------------------------------------------------------- /benchmark/README.md: -------------------------------------------------------------------------------- 1 | # Benchmarking CLIc 2 | This is the result of a small student project. 3 | 4 | To create a new benchmark have a look at `benchmark_mean.cpp` or `benchmark_dummy.cpp`. 5 | More complicated examples are `benchmark_means_comparison.cpp` and `benchmark_maximum_projections.cpp`. 6 | 7 | To build the benchmarks build the main project with `BUILD_BENCHMARK` set to `ON`. 8 | 9 | Keep in mind that your new benchmark has to be added manually to this directories `CMakeLists.txt`. 10 | -------------------------------------------------------------------------------- /benchmark/benchmark_dummy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | class DummyBenchmark : public BenchmarkBase 9 | { 10 | protected: 11 | auto 12 | Setup() -> void override 13 | {} 14 | 15 | auto 16 | Iteration() -> void override 17 | { 18 | std::this_thread::sleep_for(std::chrono::microseconds(700)); 19 | }; 20 | 21 | auto 22 | Teardown() -> void override 23 | {} 24 | 25 | auto 26 | InterpretTiming(const std::string & title, const unsigned long time) -> void override 27 | { 28 | std::cout << title << ": " << static_cast(time - 700) / static_cast(700 * 100) << "% wait inaccuracy" 29 | << std::endl; 30 | } 31 | 32 | public: 33 | ~DummyBenchmark() = default; 34 | }; 35 | 36 | auto 37 | main() -> int 38 | { 39 | DummyBenchmark dummy; 40 | dummy.Run(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /benchmark/benchmark_mean.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "clesperanto.hpp" 6 | 7 | #include 8 | 9 | class MeanBenchmark : public BenchmarkBase 10 | { 11 | protected: 12 | cle::Clesperanto cle; 13 | cle::Image gpuInput; 14 | cle::Image gpuOutput; 15 | 16 | auto 17 | Setup() -> void override 18 | { 19 | std::vector inputData(dataWidth * dataWidth); 20 | std::array dim{ { dataWidth, dataWidth, 1 } }; 21 | 22 | cle.GetDevice()->WaitForKernelToFinish(); 23 | 24 | // Initialise device memory and push from host 25 | gpuInput = cle.Push(inputData, dim); 26 | gpuOutput = cle.Create(dim); 27 | } 28 | 29 | auto 30 | Iteration() -> void override 31 | { 32 | cle.MeanBox(gpuInput, gpuOutput, 4, 4); 33 | } 34 | 35 | auto 36 | Teardown() -> void override 37 | {} 38 | 39 | public: 40 | size_t dataWidth = 0; 41 | 42 | MeanBenchmark() 43 | : cle(cle::Clesperanto()) 44 | {} 45 | 46 | ~MeanBenchmark() = default; 47 | }; 48 | 49 | auto 50 | main(int argc, char ** argv) -> int 51 | { 52 | MeanBenchmark d; 53 | d.dataWidth = 1 << 10; 54 | 55 | d.iterationWarmupCount = 18; 56 | 57 | if (argc >= 2) 58 | { 59 | d.dataWidth = std::stoi(argv[1]); 60 | std::cout << "using " << d.dataWidth * d.dataWidth * sizeof(float) << " bytes memory" << std::endl; 61 | } 62 | 63 | d.Run(); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /benchmark/benchmark_push_pull.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "clesperanto.hpp" 6 | 7 | #include 8 | 9 | class PushPullBenchmark : public BenchmarkBase 10 | { 11 | protected: 12 | cle::Clesperanto cle; 13 | std::vector inputData; 14 | std::array dim; 15 | auto 16 | Setup() -> void override 17 | { 18 | inputData = std::vector(dataWidth * dataWidth * dataWidth); 19 | dim = std::array{ { dataWidth, dataWidth, dataWidth } }; 20 | 21 | cle.GetDevice()->WaitForKernelToFinish(); 22 | } 23 | 24 | auto 25 | Iteration() -> void override 26 | { 27 | auto gpuInput = cle.Push(inputData, dim); 28 | auto output = cle.Pull(gpuInput); 29 | } 30 | 31 | auto 32 | Teardown() -> void override 33 | {} 34 | 35 | public: 36 | size_t dataWidth = 0; 37 | 38 | PushPullBenchmark() 39 | : cle(cle::Clesperanto()) 40 | {} 41 | 42 | ~PushPullBenchmark() = default; 43 | }; 44 | 45 | auto 46 | main(int argc, char ** argv) -> int 47 | { 48 | PushPullBenchmark d; 49 | d.dataWidth = 1 << 10; 50 | 51 | d.iterationWarmupCount = 5; 52 | 53 | if (argc >= 2) 54 | { 55 | d.dataWidth = std::stoi(argv[1]); 56 | std::cout << "using " << d.dataWidth * d.dataWidth * d.dataWidth * sizeof(float) << " bytes memory" << std::endl; 57 | } 58 | 59 | d.Run(); 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /clic/clic.hpp.in: -------------------------------------------------------------------------------- 1 | #ifndef __CLIC_HPP 2 | #define __CLIC_HPP 3 | 4 | #define USE_OPENCL @CLE_OPENCL@ 5 | #define USE_CUDA @CLE_CUDA@ 6 | 7 | 8 | #if USE_OPENCL 9 | # ifndef CL_TARGET_OPENCL_VERSION 10 | # define CL_TARGET_OPENCL_VERSION 120 11 | # endif 12 | # ifdef __APPLE__ 13 | # include 14 | # else 15 | # include 16 | # endif 17 | #endif 18 | 19 | #if USE_CUDA 20 | # include 21 | # include 22 | # include 23 | # include 24 | #endif 25 | 26 | #if USE_OPENCL 27 | const constexpr size_t GPU_MEM_PTR_SIZE = sizeof(cl_mem); 28 | #else 29 | const constexpr size_t GPU_MEM_PTR_SIZE = sizeof(void *); 30 | #endif 31 | 32 | #endif // __CLIC_HPP 33 | -------------------------------------------------------------------------------- /clic/include/cle.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __INCLUDE_CLE_HPP 2 | #define __INCLUDE_CLE_HPP 3 | 4 | #include "array.hpp" 5 | #include "backend.hpp" 6 | #include "clic.hpp" 7 | #include "device.hpp" 8 | 9 | #include "fft.hpp" 10 | 11 | #include "tier1.hpp" 12 | #include "tier2.hpp" 13 | #include "tier3.hpp" 14 | #include "tier4.hpp" 15 | #include "tier5.hpp" 16 | #include "tier6.hpp" 17 | #include "tier7.hpp" 18 | #include "tier8.hpp" 19 | 20 | #endif // __INCLUDE_CLE_HPP 21 | -------------------------------------------------------------------------------- /clic/src/tier1/absolute.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_absolute.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | absolute_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst); 15 | const KernelInfo kernel = { "absolute", kernel::absolute }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { src->width(), src->height(), src->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/add_image_and_scalar.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_add_image_and_scalar.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | add_image_and_scalar_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, float scalar) 13 | -> Array::Pointer 14 | { 15 | tier0::create_like(src, dst); 16 | const KernelInfo kernel = { "add_image_and_scalar", kernel::add_image_and_scalar }; 17 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | // average_distance_of_n_far_off_distances_func 24 | // average_distance_of_n_far_off_distances_func 25 | // average_distance_of_n_shortest_distances_func 26 | // average_distance_of_n_shortest_distances_func 27 | // average_distance_of_n_nearest_distances_func 28 | // average_distance_of_touching_neighbors_func 29 | 30 | } // namespace cle::tier1 31 | -------------------------------------------------------------------------------- /clic/src/tier1/add_images_weighted.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_add_images_weighted.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | add_images_weighted_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst, 16 | float factor1, 17 | float factor2) -> Array::Pointer 18 | { 19 | tier0::create_like(src0, dst, dType::FLOAT); 20 | const KernelInfo kernel = { "add_images_weighted", kernel::add_images_weighted }; 21 | const ParameterList params = { 22 | { "src0", src0 }, { "src1", src1 }, { "dst", dst }, { "scalar0", factor1 }, { "scalar1", factor2 } 23 | }; 24 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 25 | execute(device, kernel, params, range); 26 | return dst; 27 | } 28 | 29 | } // namespace cle::tier1 30 | -------------------------------------------------------------------------------- /clic/src/tier1/binary_and.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_binary_and.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | binary_and_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst, dType::BINARY); 18 | const KernelInfo kernel = { "binary_and", kernel::binary_and }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/binary_edge_detection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_binary_edge_detection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | binary_edge_detection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 13 | -> Array::Pointer 14 | { 15 | tier0::create_like(src, dst, dType::BINARY); 16 | const KernelInfo kernel = { "binary_edge_detection", kernel::binary_edge_detection }; 17 | const ParameterList params = { { "src", src }, { "dst", dst } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/binary_infsup.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_inferior_superior_2d.h" 7 | #include "cle_inferior_superior_3d.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | binary_infsup_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 14 | { 15 | cle::Array::Pointer in = nullptr; 16 | if (src->dtype() != dType::BINARY) 17 | { 18 | std::cerr << "Warning: Source image of binary_infsup expected to be binary, " << src->dtype() << " given." 19 | << std::endl; 20 | tier0::create_like(src, in, dType::BINARY); 21 | tier1::copy_func(device, src, in); 22 | } 23 | else 24 | { 25 | in = src; 26 | } 27 | tier0::create_like(src, dst, dType::BINARY); 28 | const KernelInfo kernel = in->depth() > 1 ? KernelInfo{ "inferior_superior", kernel::inferior_superior_3d } 29 | : KernelInfo{ "inferior_superior", kernel::inferior_superior_2d }; 30 | const ParameterList params = { { "src", in }, { "dst", dst } }; 31 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 32 | execute(device, kernel, params, range); 33 | return dst; 34 | } 35 | 36 | } // namespace cle::tier1 37 | -------------------------------------------------------------------------------- /clic/src/tier1/binary_not.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_binary_not.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | binary_not_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::BINARY); 15 | const KernelInfo kernel = { "binary_not", kernel::binary_not }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/binary_or.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_binary_or.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | binary_or_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst, dType::BINARY); 18 | const KernelInfo kernel = { "binary_or", kernel::binary_or }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/binary_subtract.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_binary_subtract.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | binary_subtract_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst, dType::BINARY); 18 | const KernelInfo kernel = { "binary_subtract", kernel::binary_subtract }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/binary_supinf.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_superior_inferior_2d.h" 7 | #include "cle_superior_inferior_3d.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | binary_supinf_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 14 | { 15 | cle::Array::Pointer in = nullptr; 16 | if (src->dtype() != dType::BINARY) 17 | { 18 | std::cerr << "Warning: Source image of binary_supinf expected to be binary, " << src->dtype() << " given." 19 | << std::endl; 20 | tier0::create_like(src, in, dType::BINARY); 21 | tier1::copy_func(device, src, in); 22 | } 23 | else 24 | { 25 | in = src; 26 | } 27 | tier0::create_like(src, dst, dType::BINARY); 28 | const KernelInfo kernel = in->depth() > 1 ? KernelInfo{ "superior_inferior", kernel::superior_inferior_3d } 29 | : KernelInfo{ "superior_inferior", kernel::superior_inferior_2d }; 30 | const ParameterList params = { { "src", in }, { "dst", dst } }; 31 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 32 | execute(device, kernel, params, range); 33 | return dst; 34 | } 35 | 36 | } // namespace cle::tier1 37 | -------------------------------------------------------------------------------- /clic/src/tier1/binary_xor.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_binary_xor.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | binary_xor_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst, dType::BINARY); 18 | const KernelInfo kernel = { "binary_xor", kernel::binary_xor }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/block_enumerate.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_block_enumerate.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | block_enumerate_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst, 16 | int blocksize) -> Array::Pointer 17 | { 18 | tier0::create_like(src0, dst, dType::FLOAT); 19 | const KernelInfo kernel = { "block_enumerate", kernel::block_enumerate }; 20 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst }, { "index", blocksize } }; 21 | const RangeArray range = { src1->width(), src1->height(), src1->depth() }; 22 | execute(device, kernel, params, range); 23 | return dst; 24 | } 25 | 26 | } // namespace cle::tier1 27 | -------------------------------------------------------------------------------- /clic/src/tier1/circular_shift.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_circular_shift.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | circular_shift_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | const int shift_x, 16 | const int shift_y, 17 | const int shift_z) -> Array::Pointer 18 | { 19 | tier0::create_like(src, dst); 20 | const KernelInfo kernel = { "circular_shift", kernel::circular_shift }; 21 | const ParameterList params = { 22 | { "src", src }, { "dst", dst }, { "index_x", shift_x }, { "index_y", shift_y }, { "index_z", shift_z } 23 | }; 24 | const RangeArray range = { src->width(), src->height(), src->depth() }; 25 | execute(device, kernel, params, range); 26 | return dst; 27 | } 28 | 29 | } // namespace cle::tier1 30 | -------------------------------------------------------------------------------- /clic/src/tier1/convolve.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_convolve.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | convolve_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst, dType::FLOAT); 18 | const KernelInfo kernel = { "convolve", kernel::convolve }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/copy.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_copy.h" 7 | #include "cle_copy_horizontal_slice_from.h" 8 | #include "cle_copy_horizontal_slice_to.h" 9 | #include "cle_copy_slice_from.h" 10 | #include "cle_copy_slice_to.h" 11 | #include "cle_copy_vertical_slice_from.h" 12 | #include "cle_copy_vertical_slice_to.h" 13 | 14 | namespace cle::tier1 15 | { 16 | 17 | auto 18 | copy_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 19 | { 20 | tier0::create_like(src, dst); 21 | const KernelInfo kernel = { "copy", kernel::copy }; 22 | const ParameterList params = { { "src", src }, { "dst", dst } }; 23 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 24 | execute(device, kernel, params, range); 25 | return dst; 26 | } 27 | 28 | } // namespace cle::tier1 29 | -------------------------------------------------------------------------------- /clic/src/tier1/crop.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_crop.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | crop_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | int start_x, 16 | int start_y, 17 | int start_z, 18 | int width, 19 | int height, 20 | int depth) -> Array::Pointer 21 | { 22 | tier0::create_dst(src, dst, width, height, depth); 23 | const KernelInfo kernel = { "crop", kernel::crop }; 24 | const ParameterList params = { 25 | { "src", src }, { "dst", dst }, { "index0", start_x }, { "index1", start_y }, { "index2", start_z } 26 | }; 27 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 28 | execute(device, kernel, params, range); 29 | return dst; 30 | } 31 | 32 | } // namespace cle::tier1 33 | -------------------------------------------------------------------------------- /clic/src/tier1/cubic_root.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_cubic_root.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | cubic_root_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | const KernelInfo kernel = { "cubic_root", kernel::cubic_root }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/detect_label_edges.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_detect_label_edges.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | detect_label_edges_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 13 | -> Array::Pointer 14 | { 15 | tier0::create_like(src, dst, dType::BINARY); 16 | const KernelInfo kernel = { "detect_label_edges", kernel::detect_label_edges }; 17 | const ParameterList params = { { "src", src }, { "dst", dst } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/divide_images.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_divide_images.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | divide_images_func(const Device::Pointer & device, 13 | const Array::Pointer & dividend, 14 | const Array::Pointer & divisor, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(dividend, dst); 18 | const KernelInfo kernel = { "divide_images", kernel::divide_images }; 19 | const ParameterList params = { { "src0", dividend }, { "src1", divisor }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/divide_scalar_by_image.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_divide_scalar_by_image.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | divide_scalar_by_image_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | float scalar) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst); 18 | const KernelInfo kernel = { "divide_scalar_by_image", kernel::divide_scalar_by_image }; 19 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | // draw_box_func 26 | // draw_sphere_func 27 | // draw_line_func 28 | // downsample_slice_by_slice_half_median_func 29 | 30 | } // namespace cle::tier1 31 | -------------------------------------------------------------------------------- /clic/src/tier1/equal.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_equal.h" 7 | #include "cle_equal_constant.h" 8 | #include "cle_greater_or_equal.h" 9 | #include "cle_greater_or_equal_constant.h" 10 | #include "cle_not_equal.h" 11 | #include "cle_not_equal_constant.h" 12 | #include "cle_set_where_x_equals_y.h" 13 | #include "cle_smaller_or_equal.h" 14 | #include "cle_smaller_or_equal_constant.h" 15 | 16 | namespace cle::tier1 17 | { 18 | 19 | auto 20 | equal_func(const Device::Pointer & device, const Array::Pointer & src0, const Array::Pointer & src1, Array::Pointer dst) 21 | -> Array::Pointer 22 | { 23 | tier0::create_like(src0, dst, dType::BINARY); 24 | const KernelInfo kernel = { "equal", kernel::equal }; 25 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 26 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 27 | execute(device, kernel, params, range); 28 | return dst; 29 | } 30 | 31 | } // namespace cle::tier1 32 | -------------------------------------------------------------------------------- /clic/src/tier1/equal_constant.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_equal_constant.h" 7 | #include "cle_greater_or_equal_constant.h" 8 | #include "cle_not_equal_constant.h" 9 | #include "cle_smaller_or_equal_constant.h" 10 | 11 | namespace cle::tier1 12 | { 13 | 14 | auto 15 | equal_constant_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, float scalar) 16 | -> Array::Pointer 17 | { 18 | tier0::create_like(src, dst, dType::BINARY); 19 | const KernelInfo kernel = { "equal_constant", kernel::equal_constant }; 20 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 21 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 22 | execute(device, kernel, params, range); 23 | return dst; 24 | } 25 | 26 | } // namespace cle::tier1 27 | -------------------------------------------------------------------------------- /clic/src/tier1/exponential.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_exponential.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | exponential_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | const KernelInfo kernel = { "exponential", kernel::exponential }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/flip.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_flip.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | flip_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | bool flip_x, 16 | bool flip_y, 17 | bool flip_z) -> Array::Pointer 18 | { 19 | tier0::create_like(src, dst); 20 | const KernelInfo kernel = { "flip", kernel::flip }; 21 | const ParameterList params = { 22 | { "src", src }, { "dst", dst }, { "index0", int(flip_x) }, { "index1", int(flip_y) }, { "index2", int(flip_z) } 23 | }; 24 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 25 | execute(device, kernel, params, range); 26 | return dst; 27 | } 28 | 29 | } // namespace cle::tier1 30 | -------------------------------------------------------------------------------- /clic/src/tier1/gaussian_blur.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_gaussian_blur_separable.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | gaussian_blur_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | float sigma_x, 16 | float sigma_y, 17 | float sigma_z) -> Array::Pointer 18 | { 19 | tier0::create_like(src, dst, dType::FLOAT); 20 | Array::Pointer temp = src; 21 | if (temp->dtype() != dType::FLOAT) 22 | { 23 | temp = Array::create(dst); 24 | tier1::copy_func(device, src, temp); 25 | } 26 | const KernelInfo kernel = { "gaussian_blur_separable", kernel::gaussian_blur_separable }; 27 | execute_separable(device, 28 | kernel, 29 | temp, 30 | dst, 31 | { sigma_x, sigma_y, sigma_z }, 32 | { sigma2kernelsize(sigma_x), sigma2kernelsize(sigma_y), sigma2kernelsize(sigma_z) }); 33 | return dst; 34 | } 35 | 36 | // generate_angle_matrix_func 37 | // generate_binary_overlap_matrix_func 38 | 39 | } // namespace cle::tier1 40 | -------------------------------------------------------------------------------- /clic/src/tier1/generate_distance_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_generate_distance_matrix.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | generate_distance_matrix_func(const Device::Pointer & device, 13 | const Array::Pointer & coordinate_list1, 14 | const Array::Pointer & coordinate_list2, 15 | Array::Pointer distance_matrix_destination) -> Array::Pointer 16 | { 17 | tier0::create_dst(coordinate_list1, 18 | distance_matrix_destination, 19 | coordinate_list1->width() + 1, 20 | coordinate_list1->width() + 1, 21 | 1, 22 | dType::FLOAT); 23 | distance_matrix_destination->fill(0); 24 | const KernelInfo kernel = { "generate_distance_matrix", kernel::generate_distance_matrix }; 25 | const ParameterList params = { { "src0", coordinate_list1 }, 26 | { "src1", coordinate_list2 }, 27 | { "dst", distance_matrix_destination } }; 28 | const RangeArray range = { distance_matrix_destination->width(), 29 | distance_matrix_destination->height(), 30 | distance_matrix_destination->depth() }; 31 | execute(device, kernel, params, range); 32 | return distance_matrix_destination; 33 | } 34 | 35 | } // namespace cle::tier1 36 | -------------------------------------------------------------------------------- /clic/src/tier1/greater.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_greater.h" 7 | #include "cle_greater_constant.h" 8 | #include "cle_greater_or_equal.h" 9 | #include "cle_greater_or_equal_constant.h" 10 | #include "cle_set_where_x_greater_than_y.h" 11 | 12 | namespace cle::tier1 13 | { 14 | 15 | auto 16 | greater_func(const Device::Pointer & device, 17 | const Array::Pointer & src0, 18 | const Array::Pointer & src1, 19 | Array::Pointer dst) -> Array::Pointer 20 | { 21 | tier0::create_like(src0, dst, dType::BINARY); 22 | const KernelInfo kernel = { "greater", kernel::greater }; 23 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 24 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 25 | execute(device, kernel, params, range); 26 | return dst; 27 | } 28 | 29 | } // namespace cle::tier1 30 | -------------------------------------------------------------------------------- /clic/src/tier1/greater_constant.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_greater_constant.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | greater_constant_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, float scalar) 13 | -> Array::Pointer 14 | { 15 | tier0::create_like(src, dst, dType::BINARY); 16 | const KernelInfo kernel = { "greater_constant", kernel::greater_constant }; 17 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/greater_or_equal.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_greater_or_equal.h" 7 | #include "cle_greater_or_equal_constant.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | greater_or_equal_func(const Device::Pointer & device, 14 | const Array::Pointer & src0, 15 | const Array::Pointer & src1, 16 | Array::Pointer dst) -> Array::Pointer 17 | { 18 | tier0::create_like(src0, dst, dType::BINARY); 19 | const KernelInfo kernel = { "greater_or_equal", kernel::greater_or_equal }; 20 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 21 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 22 | execute(device, kernel, params, range); 23 | return dst; 24 | } 25 | 26 | } // namespace cle::tier1 27 | -------------------------------------------------------------------------------- /clic/src/tier1/greater_or_equal_constant.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_greater_or_equal_constant.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | greater_or_equal_constant_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | float scalar) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst, dType::BINARY); 18 | const KernelInfo kernel = { "greater_or_equal_constant", kernel::greater_or_equal_constant }; 19 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/laplace_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_laplace_box.h" 7 | #include "cle_laplace_diamond.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | laplace_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, std::string connectivity) 14 | -> Array::Pointer 15 | { 16 | tier0::create_like(src, dst, dType::FLOAT); 17 | KernelInfo kernel = { "laplace_box", kernel::laplace_box }; 18 | if (connectivity == "sphere") 19 | { 20 | kernel = { "laplace_diamond", kernel::laplace_diamond }; 21 | } 22 | const ParameterList params = { { "src", src }, { "dst", dst } }; 23 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 24 | execute(device, kernel, params, range); 25 | return dst; 26 | } 27 | 28 | auto 29 | laplace_box_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 30 | { 31 | return laplace_func(device, src, dst, "box"); 32 | } 33 | 34 | auto 35 | laplace_diamond_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 36 | { 37 | return laplace_func(device, src, dst, "sphere"); 38 | } 39 | 40 | } // namespace cle::tier1 41 | -------------------------------------------------------------------------------- /clic/src/tier1/local_cross_correlation.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_local_cross_correlation.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | local_cross_correlation_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | const Array::Pointer & kernel, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst, dType::FLOAT); 18 | const KernelInfo oclkernel = { "local_cross_correlation", kernel::local_cross_correlation }; 19 | const ParameterList params = { { "src0", src }, { "src1", kernel }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, oclkernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/logarithm.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_logarithm.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | logarithm_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | const KernelInfo kernel = { "logarithm", kernel::logarithm }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/mask.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_mask.h" 7 | #include "cle_mask_label.h" 8 | #include "cle_minimum_of_masked_pixels_reduction.h" 9 | 10 | namespace cle::tier1 11 | { 12 | 13 | auto 14 | mask_func(const Device::Pointer & device, const Array::Pointer & src, const Array::Pointer & mask, Array::Pointer dst) 15 | -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst); 18 | const KernelInfo kernel = { "mask", kernel::mask }; 19 | const ParameterList params = { { "src0", src }, { "src1", mask }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/mask_label.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_mask_label.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | mask_label_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst, 16 | float label) -> Array::Pointer 17 | { 18 | tier0::create_like(src0, dst); 19 | const KernelInfo kernel = { "mask_label", kernel::mask_label }; 20 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst }, { "scalar", label } }; 21 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 22 | execute(device, kernel, params, range); 23 | return dst; 24 | } 25 | 26 | } // namespace cle::tier1 27 | -------------------------------------------------------------------------------- /clic/src/tier1/maximum_image_and_scalar.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_maximum_image_and_scalar.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | maximum_image_and_scalar_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | float scalar) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst); 18 | const KernelInfo kernel = { "maximum_image_and_scalar", kernel::maximum_image_and_scalar }; 19 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/maximum_images.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_maximum_images.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | maximum_images_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst); 18 | const KernelInfo kernel = { "maximum_images", kernel::maximum_images }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/maximum_x_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_maximum_x_projection.h" 7 | #include "cle_x_position_of_maximum_x_projection.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | maximum_x_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 14 | -> Array::Pointer 15 | { 16 | tier0::create_zy(src, dst); 17 | const KernelInfo kernel = { "maximum_x_projection", kernel::maximum_x_projection }; 18 | const ParameterList params = { { "src", src }, { "dst", dst } }; 19 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 20 | execute(device, kernel, params, range); 21 | return dst; 22 | } 23 | 24 | } // namespace cle::tier1 25 | -------------------------------------------------------------------------------- /clic/src/tier1/maximum_y_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_maximum_y_projection.h" 7 | #include "cle_y_position_of_maximum_y_projection.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | maximum_y_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 14 | -> Array::Pointer 15 | { 16 | tier0::create_xz(src, dst); 17 | const KernelInfo kernel = { "maximum_y_projection", kernel::maximum_y_projection }; 18 | const ParameterList params = { { "src", src }, { "dst", dst } }; 19 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 20 | execute(device, kernel, params, range); 21 | return dst; 22 | } 23 | 24 | } // namespace cle::tier1 25 | -------------------------------------------------------------------------------- /clic/src/tier1/maximum_z_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_maximum_z_projection.h" 7 | #include "cle_z_position_of_maximum_z_projection.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | maximum_z_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 14 | -> Array::Pointer 15 | { 16 | tier0::create_xy(src, dst); 17 | const KernelInfo kernel = { "maximum_z_projection", kernel::maximum_z_projection }; 18 | const ParameterList params = { { "src", src }, { "dst", dst } }; 19 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 20 | execute(device, kernel, params, range); 21 | return dst; 22 | } 23 | 24 | } // namespace cle::tier1 25 | -------------------------------------------------------------------------------- /clic/src/tier1/mean_x_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_mean_x_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | mean_x_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_zy(src, dst); 15 | const KernelInfo kernel = { "mean_x_projection", kernel::mean_x_projection }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/mean_y_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_mean_y_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | mean_y_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_xz(src, dst); 15 | const KernelInfo kernel = { "mean_y_projection", kernel::mean_y_projection }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/mean_z_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_mean_z_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | mean_z_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_xy(src, dst); 15 | const KernelInfo kernel = { "mean_z_projection", kernel::mean_z_projection }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/minimum_image_and_scalar.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_minimum_image_and_scalar.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | minimum_image_and_scalar_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | float scalar) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst); 18 | const KernelInfo kernel = { "minimum_image_and_scalar", kernel::minimum_image_and_scalar }; 19 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/minimum_images.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_minimum_images.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | minimum_images_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst); 18 | const KernelInfo kernel = { "minimum_images", kernel::minimum_images }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/minimum_of_masked_pixels_reduction.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_minimum_of_masked_pixels_reduction.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | minimum_of_masked_pixels_reduction_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | const Array::Pointer & mask, 15 | Array::Pointer reduced_src, 16 | Array::Pointer reduced_mask) -> Array::Pointer 17 | { 18 | tier0::create_xy(src, reduced_src); 19 | tier0::create_xy(mask, reduced_mask); 20 | const KernelInfo kernel = { "minimum_of_masked_pixels_reduction", kernel::minimum_of_masked_pixels_reduction }; 21 | const ParameterList params = { 22 | { "src", src }, { "mask", mask }, { "dst_src", reduced_src }, { "dst_mask", reduced_mask } 23 | }; 24 | const RangeArray range = { reduced_src->width(), reduced_src->height(), reduced_src->depth() }; 25 | execute(device, kernel, params, range); 26 | return reduced_src; 27 | } 28 | 29 | } // namespace cle::tier1 30 | -------------------------------------------------------------------------------- /clic/src/tier1/minimum_x_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_minimum_x_projection.h" 7 | #include "cle_x_position_of_minimum_x_projection.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | minimum_x_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 14 | -> Array::Pointer 15 | { 16 | tier0::create_zy(src, dst); 17 | const KernelInfo kernel = { "minimum_x_projection", kernel::minimum_x_projection }; 18 | const ParameterList params = { { "src", src }, { "dst", dst } }; 19 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 20 | execute(device, kernel, params, range); 21 | return dst; 22 | } 23 | 24 | } // namespace cle::tier1 25 | -------------------------------------------------------------------------------- /clic/src/tier1/minimum_y_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_minimum_y_projection.h" 7 | #include "cle_y_position_of_minimum_y_projection.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | minimum_y_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 14 | -> Array::Pointer 15 | { 16 | tier0::create_xz(src, dst); 17 | const KernelInfo kernel = { "minimum_y_projection", kernel::minimum_y_projection }; 18 | const ParameterList params = { { "src", src }, { "dst", dst } }; 19 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 20 | execute(device, kernel, params, range); 21 | return dst; 22 | } 23 | 24 | } // namespace cle::tier1 25 | -------------------------------------------------------------------------------- /clic/src/tier1/minimum_z_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_minimum_z_projection.h" 7 | #include "cle_z_position_of_minimum_z_projection.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | minimum_z_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 14 | -> Array::Pointer 15 | { 16 | tier0::create_xy(src, dst); 17 | const KernelInfo kernel = { "minimum_z_projection", kernel::minimum_z_projection }; 18 | const ParameterList params = { { "src", src }, { "dst", dst } }; 19 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 20 | execute(device, kernel, params, range); 21 | return dst; 22 | } 23 | 24 | } // namespace cle::tier1 25 | -------------------------------------------------------------------------------- /clic/src/tier1/modulo_images.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_modulo_images.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | modulo_images_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst); 18 | const KernelInfo kernel = { "modulo_images", kernel::modulo_images }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/multiply_image_and_position.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_multiply_image_and_position.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | multiply_image_and_position_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | int dimension) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst, dType::FLOAT); 18 | const KernelInfo kernel = { "multiply_image_and_position", kernel::multiply_image_and_position }; 19 | const ParameterList params = { { "src", src }, { "dst", dst }, { "index", dimension } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/multiply_image_and_scalar.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_multiply_image_and_scalar.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | multiply_image_and_scalar_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | float scalar) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst); 18 | const KernelInfo kernel = { "multiply_image_and_scalar", kernel::multiply_image_and_scalar }; 19 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/multiply_images.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_multiply_images.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | multiply_images_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst); 18 | const KernelInfo kernel = { "multiply_images", kernel::multiply_images }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | // n_closest_points_func 26 | 27 | } // namespace cle::tier1 28 | -------------------------------------------------------------------------------- /clic/src/tier1/multiply_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_multiply_matrix.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | multiply_matrix_func(const Device::Pointer & device, 13 | const Array::Pointer & matrix1, 14 | const Array::Pointer & matrix2, 15 | Array::Pointer matrix_destination) -> Array::Pointer 16 | { 17 | tier0::create_dst(matrix1, matrix_destination, matrix2->width(), matrix1->height(), matrix1->depth(), dType::FLOAT); 18 | const KernelInfo kernel = { "multiply_matrix", kernel::multiply_matrix }; 19 | const ParameterList params = { { "src0", matrix1 }, { "src1", matrix2 }, { "dst", matrix_destination } }; 20 | const RangeArray range = { matrix_destination->width(), matrix_destination->height(), matrix_destination->depth() }; 21 | execute(device, kernel, params, range); 22 | return matrix_destination; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/nan_to_num.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_nan_to_num.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | nan_to_num_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | float nan, 16 | float posinf, 17 | float neginf) -> Array::Pointer 18 | { 19 | tier0::create_like(src, dst); 20 | const KernelInfo kernel = { "nan_to_num", kernel::nan_to_num }; 21 | const ParameterList params = { 22 | { "src", src }, { "dst", dst }, { "nan", nan }, { "pinf", posinf }, { "ninf", neginf } 23 | }; 24 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 25 | execute(device, kernel, params, range); 26 | return dst; 27 | } 28 | 29 | } // namespace cle::tier1 30 | -------------------------------------------------------------------------------- /clic/src/tier1/not_equal.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_not_equal.h" 7 | #include "cle_not_equal_constant.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | not_equal_func(const Device::Pointer & device, 14 | const Array::Pointer & src0, 15 | const Array::Pointer & src1, 16 | Array::Pointer dst) -> Array::Pointer 17 | { 18 | tier0::create_like(src0, dst, dType::BINARY); 19 | const KernelInfo kernel = { "not_equal", kernel::not_equal }; 20 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 21 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 22 | execute(device, kernel, params, range); 23 | return dst; 24 | } 25 | 26 | } // namespace cle::tier1 27 | -------------------------------------------------------------------------------- /clic/src/tier1/not_equal_constant.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_not_equal_constant.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | not_equal_constant_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, float scalar) 13 | -> Array::Pointer 14 | { 15 | tier0::create_like(src, dst, dType::BINARY); 16 | const KernelInfo kernel = { "not_equal_constant", kernel::not_equal_constant }; 17 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/paste.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_paste.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | paste_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | int destination_x, 16 | int destination_y, 17 | int destination_z) -> Array::Pointer 18 | { 19 | tier0::create_like(src, dst); 20 | const KernelInfo kernel = { "paste", kernel::paste }; 21 | const ParameterList params = { { "src", src }, 22 | { "dst", dst }, 23 | { "scalar0", destination_x }, 24 | { "scalar1", destination_y }, 25 | { "scalar2", destination_z } }; 26 | const RangeArray range = { src->width(), src->height(), src->depth() }; 27 | execute(device, kernel, params, range); 28 | return dst; 29 | } 30 | 31 | } // namespace cle::tier1 32 | -------------------------------------------------------------------------------- /clic/src/tier1/power.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_power.h" 7 | #include "cle_power_images.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | power_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, float scalar) 14 | -> Array::Pointer 15 | { 16 | tier0::create_like(src, dst, dType::FLOAT); 17 | const KernelInfo kernel = { "power", kernel::power }; 18 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 19 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 20 | execute(device, kernel, params, range); 21 | return dst; 22 | } 23 | 24 | } // namespace cle::tier1 25 | -------------------------------------------------------------------------------- /clic/src/tier1/power_images.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_power_images.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | power_images_func(const Device::Pointer & device, 13 | const Array::Pointer & src0, 14 | const Array::Pointer & src1, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_like(src0, dst, dType::FLOAT); 18 | const KernelInfo kernel = { "power_images", kernel::power_images }; 19 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/read_values_from_positions.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_read_values_from_positions.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | read_values_from_positions_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | const Array::Pointer & list, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | // TODO: check list shape 18 | // if (list->height() < src->dim()) 19 | // { 20 | // throw std::runtime_error("The list height is expected to be " + std::to_string(src->dim()) + ", but it is " + 21 | // std::to_string(list->width())); 22 | // } 23 | tier0::create_vector(src, dst, list->width()); 24 | const KernelInfo kernel = { "read_values_from_positions", kernel::read_values_from_positions }; 25 | const ParameterList params = { { "src0", src }, { "src1", list }, { "dst", dst } }; 26 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 27 | execute(device, kernel, params, range); 28 | return dst; 29 | } 30 | 31 | } // namespace cle::tier1 32 | -------------------------------------------------------------------------------- /clic/src/tier1/reciprocal.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_reciprocal.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | reciprocal_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | const KernelInfo kernel = { "reciprocal", kernel::reciprocal }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/set.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set.h" 7 | #include "cle_set_column.h" 8 | #include "cle_set_image_borders.h" 9 | #include "cle_set_nonzero_pixels_to_pixelindex.h" 10 | #include "cle_set_plane.h" 11 | #include "cle_set_ramp_x.h" 12 | #include "cle_set_ramp_y.h" 13 | #include "cle_set_ramp_z.h" 14 | #include "cle_set_row.h" 15 | #include "cle_set_where_x_equals_y.h" 16 | #include "cle_set_where_x_greater_than_y.h" 17 | #include "cle_set_where_x_smaller_than_y.h" 18 | 19 | namespace cle::tier1 20 | { 21 | 22 | auto 23 | set_func(const Device::Pointer & device, const Array::Pointer & src, float scalar) -> Array::Pointer 24 | { 25 | const KernelInfo kernel = { "set", kernel::set }; 26 | const ParameterList params = { { "dst", src }, { "scalar", scalar } }; 27 | const RangeArray range = { src->width(), src->height(), src->depth() }; 28 | execute(device, kernel, params, range); 29 | return src; 30 | } 31 | 32 | } // namespace cle::tier1 33 | -------------------------------------------------------------------------------- /clic/src/tier1/set_column.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_column.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | set_column_func(const Device::Pointer & device, const Array::Pointer & src, int column_index, float value) 13 | -> Array::Pointer 14 | { 15 | const KernelInfo kernel = { "set_column", kernel::set_column }; 16 | const ParameterList params = { { "dst", src }, { "index", column_index }, { "scalar", value } }; 17 | const RangeArray range = { src->width(), src->height(), src->depth() }; 18 | execute(device, kernel, params, range); 19 | return src; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/set_image_borders.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_image_borders.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | set_image_borders_func(const Device::Pointer & device, const Array::Pointer & src, float value) -> Array::Pointer 13 | { 14 | const KernelInfo kernel = { "set_image_borders", kernel::set_image_borders }; 15 | const ParameterList params = { { "src", src }, { "scalar", value } }; 16 | const RangeArray range = { src->width(), src->height(), src->depth() }; 17 | execute(device, kernel, params, range); 18 | return src; 19 | } 20 | 21 | } // namespace cle::tier1 22 | -------------------------------------------------------------------------------- /clic/src/tier1/set_nonzero_pixels_to_pixelindex.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_nonzero_pixels_to_pixelindex.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | set_nonzero_pixels_to_pixelindex_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | int offset) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst, dType::INDEX); 18 | const KernelInfo kernel = { "set_nonzero_pixels_to_pixelindex", kernel::set_nonzero_pixels_to_pixelindex }; 19 | const ParameterList params = { { "src", src }, { "dst", dst }, { "offset", offset } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/set_plane.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_plane.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | set_plane_func(const Device::Pointer & device, const Array::Pointer & src, int plane_index, float value) 13 | -> Array::Pointer 14 | { 15 | const KernelInfo kernel = { "set_plane", kernel::set_plane }; 16 | const ParameterList params = { { "dst", src }, { "index", plane_index }, { "scalar", value } }; 17 | const RangeArray range = { src->width(), src->height(), src->depth() }; 18 | execute(device, kernel, params, range); 19 | return src; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/set_ramp.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_ramp_x.h" 7 | #include "cle_set_ramp_y.h" 8 | #include "cle_set_ramp_z.h" 9 | 10 | namespace cle::tier1 11 | { 12 | 13 | auto 14 | set_ramp_x_func(const Device::Pointer & device, const Array::Pointer & src) -> Array::Pointer 15 | { 16 | const KernelInfo kernel = { "set_ramp_x", kernel::set_ramp_x }; 17 | const ParameterList params = { { "dst", src } }; 18 | const RangeArray range = { src->width(), src->height(), src->depth() }; 19 | execute(device, kernel, params, range); 20 | return src; 21 | } 22 | 23 | auto 24 | set_ramp_y_func(const Device::Pointer & device, const Array::Pointer & src) -> Array::Pointer 25 | { 26 | const KernelInfo kernel = { "set_ramp_y", kernel::set_ramp_y }; 27 | const ParameterList params = { { "dst", src } }; 28 | const RangeArray range = { src->width(), src->height(), src->depth() }; 29 | execute(device, kernel, params, range); 30 | return src; 31 | } 32 | 33 | auto 34 | set_ramp_z_func(const Device::Pointer & device, const Array::Pointer & src) -> Array::Pointer 35 | { 36 | const KernelInfo kernel = { "set_ramp_z", kernel::set_ramp_z }; 37 | const ParameterList params = { { "dst", src } }; 38 | const RangeArray range = { src->width(), src->height(), src->depth() }; 39 | execute(device, kernel, params, range); 40 | return src; 41 | } 42 | 43 | } // namespace cle::tier1 44 | -------------------------------------------------------------------------------- /clic/src/tier1/set_row.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_row.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | set_row_func(const Device::Pointer & device, const Array::Pointer & src, int row_index, float value) -> Array::Pointer 13 | { 14 | const KernelInfo kernel = { "set_row", kernel::set_row }; 15 | const ParameterList params = { { "dst", src }, { "index", row_index }, { "scalar", value } }; 16 | const RangeArray range = { src->width(), src->height(), src->depth() }; 17 | execute(device, kernel, params, range); 18 | return src; 19 | } 20 | 21 | } // namespace cle::tier1 22 | -------------------------------------------------------------------------------- /clic/src/tier1/set_where_x_equals_y.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_where_x_equals_y.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | set_where_x_equals_y_func(const Device::Pointer & device, const Array::Pointer & src, float value) -> Array::Pointer 13 | { 14 | const KernelInfo kernel = { "set_where_x_equals_y", kernel::set_where_x_equals_y }; 15 | const ParameterList params = { { "dst", src }, { "scalar", value } }; 16 | const RangeArray range = { src->width(), src->height(), src->depth() }; 17 | execute(device, kernel, params, range); 18 | return src; 19 | } 20 | 21 | } // namespace cle::tier1 22 | -------------------------------------------------------------------------------- /clic/src/tier1/set_where_x_greater_than_y.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_where_x_greater_than_y.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | set_where_x_greater_than_y_func(const Device::Pointer & device, const Array::Pointer & src, float value) 13 | -> Array::Pointer 14 | { 15 | const KernelInfo kernel = { "set_where_x_greater_than_y", kernel::set_where_x_greater_than_y }; 16 | const ParameterList params = { { "dst", src }, { "scalar", value } }; 17 | const RangeArray range = { src->width(), src->height(), src->depth() }; 18 | execute(device, kernel, params, range); 19 | return src; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/set_where_x_smaller_than_y.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_where_x_smaller_than_y.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | set_where_x_smaller_than_y_func(const Device::Pointer & device, const Array::Pointer & src, float value) 13 | -> Array::Pointer 14 | { 15 | const KernelInfo kernel = { "set_where_x_smaller_than_y", kernel::set_where_x_smaller_than_y }; 16 | const ParameterList params = { { "dst", src }, { "scalar", value } }; 17 | const RangeArray range = { src->width(), src->height(), src->depth() }; 18 | execute(device, kernel, params, range); 19 | return src; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/sign.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_sign.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | sign_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst); 15 | dst->fill(0); 16 | const KernelInfo kernel = { "pixel_sign", kernel::sign }; 17 | const ParameterList params = { { "src", src }, { "dst", dst } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/smaller.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_set_where_x_smaller_than_y.h" 7 | #include "cle_smaller.h" 8 | #include "cle_smaller_constant.h" 9 | #include "cle_smaller_or_equal.h" 10 | #include "cle_smaller_or_equal_constant.h" 11 | 12 | namespace cle::tier1 13 | { 14 | 15 | auto 16 | smaller_func(const Device::Pointer & device, 17 | const Array::Pointer & src0, 18 | const Array::Pointer & src1, 19 | Array::Pointer dst) -> Array::Pointer 20 | { 21 | tier0::create_like(src0, dst, dType::BINARY); 22 | const KernelInfo kernel = { "smaller", kernel::smaller }; 23 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 24 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 25 | execute(device, kernel, params, range); 26 | return dst; 27 | } 28 | 29 | } // namespace cle::tier1 30 | -------------------------------------------------------------------------------- /clic/src/tier1/smaller_constant.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_smaller_constant.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | smaller_constant_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, float scalar) 13 | -> Array::Pointer 14 | { 15 | tier0::create_like(src, dst, dType::BINARY); 16 | const KernelInfo kernel = { "smaller_constant", kernel::smaller_constant }; 17 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/smaller_or_equal.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_smaller_or_equal.h" 7 | #include "cle_smaller_or_equal_constant.h" 8 | 9 | namespace cle::tier1 10 | { 11 | 12 | auto 13 | smaller_or_equal_func(const Device::Pointer & device, 14 | const Array::Pointer & src0, 15 | const Array::Pointer & src1, 16 | Array::Pointer dst) -> Array::Pointer 17 | { 18 | tier0::create_like(src0, dst, dType::BINARY); 19 | const KernelInfo kernel = { "smaller_or_equal", kernel::smaller_or_equal }; 20 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 21 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 22 | execute(device, kernel, params, range); 23 | return dst; 24 | } 25 | 26 | } // namespace cle::tier1 27 | -------------------------------------------------------------------------------- /clic/src/tier1/smaller_or_equal_constant.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_smaller_or_equal_constant.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | smaller_or_equal_constant_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | float scalar) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst, dType::BINARY); 18 | const KernelInfo kernel = { "smaller_or_equal_constant", kernel::smaller_or_equal_constant }; 19 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/sobel.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_sobel.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | sobel_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | const KernelInfo kernel = { "sobel", kernel::sobel }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/square_root.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_square_root.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | square_root_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | const KernelInfo kernel = { "square_root", kernel::square_root }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/std_z_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_std_z_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | std_z_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_xy(src, dst, dType::FLOAT); 15 | const KernelInfo kernel = { "std_z_projection", kernel::std_z_projection }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/subtract_image_from_scalar.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_subtract_image_from_scalar.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | subtract_image_from_scalar_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | Array::Pointer dst, 15 | float scalar) -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst); 18 | const KernelInfo kernel = { "subtract_image_from_scalar", kernel::subtract_image_from_scalar }; 19 | const ParameterList params = { { "src", src }, { "dst", dst }, { "scalar", scalar } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier1/sum_reduction_x.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_sum_reduction_x.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | sum_reduction_x_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int blocksize) 13 | -> Array::Pointer 14 | { 15 | // WARNING: function is not tested for 2D and 3D data. exepecting 1D only for now. 16 | if (dst == nullptr) 17 | { 18 | size_t dst_width = src->width(); 19 | size_t dst_height = src->height(); 20 | size_t dst_depth = src->depth(); 21 | auto dim = shape_to_dimension(dst_width, dst_height, dst_depth); 22 | switch (dim) 23 | { 24 | case 1: 25 | dst_width = static_cast(src->width() / blocksize); 26 | break; 27 | case 2: 28 | dst_height = static_cast(src->height() / blocksize); 29 | break; 30 | case 3: 31 | dst_depth = static_cast(src->depth() / blocksize); 32 | break; 33 | } 34 | dst = Array::create(dst_width, dst_height, dst_depth, 1, src->dtype(), src->mtype(), src->device()); 35 | } 36 | const KernelInfo kernel = { "sum_reduction_x", kernel::sum_reduction_x }; 37 | const ParameterList params = { { "src", src }, { "dst", dst }, { "index", blocksize } }; 38 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 39 | execute(device, kernel, params, range); 40 | return dst; 41 | } 42 | 43 | } // namespace cle::tier1 44 | -------------------------------------------------------------------------------- /clic/src/tier1/transpose_xy.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_transpose_xy.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | transpose_xy_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | if (dst == nullptr) 15 | { 16 | auto dim = shape_to_dimension(src->height(), src->width(), src->depth()); 17 | dst = Array::create(src->height(), src->width(), src->depth(), dim, src->dtype(), src->mtype(), src->device()); 18 | } 19 | const KernelInfo kernel = { "transpose_xy", kernel::transpose_xy }; 20 | const ParameterList params = { { "src", src }, { "dst", dst } }; 21 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 22 | execute(device, kernel, params, range); 23 | return dst; 24 | } 25 | 26 | } // namespace cle::tier1 27 | -------------------------------------------------------------------------------- /clic/src/tier1/transpose_xz.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_transpose_xz.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | transpose_xz_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | if (dst == nullptr) 15 | { 16 | auto dim = shape_to_dimension(src->depth(), src->height(), src->width()); 17 | dst = Array::create(src->depth(), src->height(), src->width(), dim, src->dtype(), src->mtype(), src->device()); 18 | } 19 | const KernelInfo kernel = { "transpose_xz", kernel::transpose_xz }; 20 | const ParameterList params = { { "src", src }, { "dst", dst } }; 21 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 22 | execute(device, kernel, params, range); 23 | return dst; 24 | } 25 | 26 | } // namespace cle::tier1 27 | -------------------------------------------------------------------------------- /clic/src/tier1/transpose_yz.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_transpose_yz.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | transpose_yz_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | if (dst == nullptr) 15 | { 16 | auto dim = shape_to_dimension(src->width(), src->depth(), src->height()); 17 | dst = Array::create(src->width(), src->depth(), src->height(), 3, src->dtype(), src->mtype(), src->device()); 18 | } 19 | const KernelInfo kernel = { "transpose_yz", kernel::transpose_yz }; 20 | const ParameterList params = { { "src", src }, { "dst", dst } }; 21 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 22 | execute(device, kernel, params, range); 23 | return dst; 24 | } 25 | 26 | } // namespace cle::tier1 27 | -------------------------------------------------------------------------------- /clic/src/tier1/undefined_to_zero.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_undefined_to_zero.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | undefined_to_zero_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst); 15 | const KernelInfo kernel = { "undefined_to_zero", kernel::undefined_to_zero }; 16 | const ParameterList params = { { "src", src }, { "dst", dst } }; 17 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 18 | execute(device, kernel, params, range); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier1 23 | -------------------------------------------------------------------------------- /clic/src/tier1/x_position_of_maximum_x_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_x_position_of_maximum_x_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | x_position_of_maximum_x_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 13 | -> Array::Pointer 14 | { 15 | tier0::create_zy(src, dst, dType::INDEX); 16 | const KernelInfo kernel = { "x_position_of_maximum_x_projection", kernel::x_position_of_maximum_x_projection }; 17 | const ParameterList params = { { "src", src }, { "dst", dst } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/x_position_of_minimum_x_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_x_position_of_minimum_x_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | x_position_of_minimum_x_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 13 | -> Array::Pointer 14 | { 15 | tier0::create_zy(src, dst, dType::INDEX); 16 | const KernelInfo kernel = { "x_position_of_minimum_x_projection", kernel::x_position_of_minimum_x_projection }; 17 | const ParameterList params = { { "src", src }, { "dst", dst } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/y_position_of_maximum_y_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_y_position_of_maximum_y_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | y_position_of_maximum_y_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 13 | -> Array::Pointer 14 | { 15 | tier0::create_xz(src, dst, dType::INDEX); 16 | const KernelInfo kernel = { "y_position_of_maximum_y_projection", kernel::y_position_of_maximum_y_projection }; 17 | const ParameterList params = { { "src", src }, { "dst", dst } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/y_position_of_minimum_y_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_y_position_of_minimum_y_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | y_position_of_minimum_y_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 13 | -> Array::Pointer 14 | { 15 | tier0::create_xz(src, dst, dType::INDEX); 16 | const KernelInfo kernel = { "y_position_of_minimum_y_projection", kernel::y_position_of_minimum_y_projection }; 17 | const ParameterList params = { { "src", src }, { "dst", dst } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/z_position_of_maximum_z_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_z_position_of_maximum_z_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | z_position_of_maximum_z_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 13 | -> Array::Pointer 14 | { 15 | tier0::create_xy(src, dst, dType::INDEX); 16 | const KernelInfo kernel = { "z_position_of_maximum_z_projection", kernel::z_position_of_maximum_z_projection }; 17 | const ParameterList params = { { "src", src }, { "dst", dst } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/z_position_of_minimum_z_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_z_position_of_minimum_z_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | z_position_of_minimum_z_projection_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 13 | -> Array::Pointer 14 | { 15 | tier0::create_xy(src, dst, dType::INDEX); 16 | const KernelInfo kernel = { "z_position_of_minimum_z_projection", kernel::z_position_of_minimum_z_projection }; 17 | const ParameterList params = { { "src", src }, { "dst", dst } }; 18 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 19 | execute(device, kernel, params, range); 20 | return dst; 21 | } 22 | 23 | } // namespace cle::tier1 24 | -------------------------------------------------------------------------------- /clic/src/tier1/z_position_projection_func.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | 4 | #include "utils.hpp" 5 | 6 | #include "cle_z_position_projection.h" 7 | 8 | namespace cle::tier1 9 | { 10 | 11 | auto 12 | z_position_projection_func(const Device::Pointer & device, 13 | const Array::Pointer & src, 14 | const Array::Pointer & position, 15 | Array::Pointer dst) -> Array::Pointer 16 | { 17 | tier0::create_xy(src, dst); 18 | const KernelInfo kernel = { "z_position_projection", kernel::z_position_projection }; 19 | const ParameterList params = { { "src", src }, { "position", position }, { "dst", dst } }; 20 | const RangeArray range = { dst->width(), dst->height(), dst->depth() }; 21 | execute(device, kernel, params, range); 22 | return dst; 23 | } 24 | 25 | } // namespace cle::tier1 26 | -------------------------------------------------------------------------------- /clic/src/tier2/absolute_difference.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | absolute_difference_func(const Device::Pointer & device, 12 | const Array::Pointer & src0, 13 | const Array::Pointer & src1, 14 | Array::Pointer dst) -> Array::Pointer 15 | { 16 | tier0::create_like(src0, dst); 17 | auto tmp = tier1::add_images_weighted_func(device, src0, src1, nullptr, 1, -1); 18 | return tier1::absolute_func(device, tmp, dst); 19 | } 20 | 21 | } // namespace cle::tier2 22 | -------------------------------------------------------------------------------- /clic/src/tier2/add_images.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | add_images_func(const Device::Pointer & device, 12 | const Array::Pointer & src0, 13 | const Array::Pointer & src1, 14 | Array::Pointer dst) -> Array::Pointer 15 | { 16 | return tier1::add_images_weighted_func(device, src0, src1, dst, 1, 1); 17 | } 18 | 19 | } // namespace cle::tier2 20 | -------------------------------------------------------------------------------- /clic/src/tier2/clip.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | clip_func(const Device::Pointer & device, 12 | const Array::Pointer & src, 13 | Array::Pointer dst, 14 | float min_intensity, 15 | float max_intensity) -> Array::Pointer 16 | { 17 | auto temp = tier1::maximum_image_and_scalar_func(device, src, nullptr, min_intensity); 18 | return tier1::minimum_image_and_scalar_func(device, temp, dst, max_intensity); 19 | } 20 | 21 | } // namespace cle::tier2 22 | -------------------------------------------------------------------------------- /clic/src/tier2/concatenate_along_x.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | concatenate_along_x_func(const Device::Pointer & device, 12 | const Array::Pointer & src0, 13 | const Array::Pointer & src1, 14 | Array::Pointer dst) -> Array::Pointer 15 | { 16 | tier0::create_dst(src0, dst, src0->width() + src1->width(), src0->height(), src0->depth(), src0->dtype()); 17 | tier1::paste_func(device, src0, dst, 0, 0, 0); 18 | tier1::paste_func(device, src1, dst, src0->width(), 0, 0); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier2 23 | -------------------------------------------------------------------------------- /clic/src/tier2/concatenate_along_y.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | concatenate_along_y_func(const Device::Pointer & device, 12 | const Array::Pointer & src0, 13 | const Array::Pointer & src1, 14 | Array::Pointer dst) -> Array::Pointer 15 | { 16 | tier0::create_dst(src0, dst, src0->width(), src0->height() + src1->height(), src0->depth(), src0->dtype()); 17 | tier1::paste_func(device, src0, dst, 0, 0, 0); 18 | tier1::paste_func(device, src1, dst, 0, src0->height(), 0); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier2 23 | -------------------------------------------------------------------------------- /clic/src/tier2/concatenate_along_z.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | concatenate_along_z_func(const Device::Pointer & device, 12 | const Array::Pointer & src0, 13 | const Array::Pointer & src1, 14 | Array::Pointer dst) -> Array::Pointer 15 | { 16 | tier0::create_dst(src0, dst, src0->width(), src0->height(), src0->depth() + src1->depth(), src0->dtype()); 17 | tier1::paste_func(device, src0, dst, 0, 0, 0); 18 | tier1::paste_func(device, src1, dst, 0, 0, src0->depth()); 19 | return dst; 20 | } 21 | 22 | } // namespace cle::tier2 23 | -------------------------------------------------------------------------------- /clic/src/tier2/count_touching_neighbors.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | count_touching_neighbors_func(const Device::Pointer & device, 12 | const Array::Pointer & touch_matrix, 13 | Array::Pointer touching_neighbors_count_destination, 14 | bool ignore_background) -> Array::Pointer 15 | { 16 | tier0::create_vector(touch_matrix, touching_neighbors_count_destination, touch_matrix->width(), dType::UINT32); 17 | auto bin_matrix = tier1::greater_constant_func(device, touch_matrix, nullptr, 0); 18 | if (ignore_background) 19 | { 20 | tier1::set_row_func(device, bin_matrix, 0, 0); 21 | tier1::set_column_func(device, bin_matrix, 0, 0); 22 | tier1::set_where_x_equals_y_func(device, bin_matrix, 0); 23 | } 24 | return tier1::sum_y_projection_func(device, bin_matrix, touching_neighbors_count_destination); 25 | } 26 | 27 | } // namespace cle::tier2 28 | -------------------------------------------------------------------------------- /clic/src/tier2/crop_border.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | crop_border_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int border_size) 12 | -> Array::Pointer 13 | { 14 | std::array region = { static_cast(src->width()) - 2 * border_size, 15 | static_cast(src->height()) - 2 * border_size, 16 | static_cast(src->depth()) - 2 * border_size }; 17 | std::transform(region.begin(), region.end(), region.begin(), [](int i) { return std::max(i, 0); }); 18 | return tier1::crop_func(device, src, dst, border_size, border_size, border_size, region[0], region[1], region[2]); 19 | } 20 | 21 | // @StRigaud TODO: auto distance_matrix_to_mesh_func; 22 | 23 | } // namespace cle::tier2 24 | -------------------------------------------------------------------------------- /clic/src/tier2/degrees_to_radians.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | degrees_to_radians_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 12 | -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | return tier1::multiply_image_and_scalar_func(device, src, dst, static_cast(M_PI) / 180.0); 16 | } 17 | 18 | } // namespace cle::tier2 19 | -------------------------------------------------------------------------------- /clic/src/tier2/difference_of_gaussian.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | difference_of_gaussian_func(const Device::Pointer & device, 12 | const Array::Pointer & src, 13 | Array::Pointer dst, 14 | float sigma1_x, 15 | float sigma1_y, 16 | float sigma1_z, 17 | float sigma2_x, 18 | float sigma2_y, 19 | float sigma2_z) -> Array::Pointer 20 | { 21 | tier0::create_like(src, dst, dType::FLOAT); 22 | auto gauss1 = tier1::gaussian_blur_func(device, src, nullptr, sigma1_x, sigma1_y, sigma1_z); 23 | auto gauss2 = tier1::gaussian_blur_func(device, src, nullptr, sigma2_x, sigma2_y, sigma2_z); 24 | return tier1::add_images_weighted_func(device, gauss1, gauss2, dst, 1, -1); 25 | } 26 | 27 | } // namespace cle::tier2 28 | -------------------------------------------------------------------------------- /clic/src/tier2/divide_by_gaussian_background.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | divide_by_gaussian_background_func(const Device::Pointer & device, 12 | const Array::Pointer & src, 13 | Array::Pointer dst, 14 | float sigma_x, 15 | float sigma_y, 16 | float sigma_z) -> Array::Pointer 17 | { 18 | auto temp = tier1::gaussian_blur_func(device, src, nullptr, sigma_x, sigma_y, sigma_z); 19 | return tier1::divide_images_func(device, src, temp, dst); 20 | } 21 | 22 | } // namespace cle::tier2 23 | -------------------------------------------------------------------------------- /clic/src/tier2/extend_labeling_via_voronoi.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | extend_labeling_via_voronoi_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 12 | -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::LABEL); 15 | auto flip = Array::create(dst); 16 | auto flop = Array::create(dst); 17 | tier1::copy_func(device, src, flip); 18 | 19 | auto flag = Array::create(1, 1, 1, 1, dType::INT32, mType::BUFFER, device); 20 | flag->fill(0); 21 | int flag_value = 1; 22 | int iteration_count = 0; 23 | while (flag_value > 0) 24 | { 25 | if (iteration_count % 2 == 0) 26 | { 27 | tier1::onlyzero_overwrite_maximum_func(device, flip, flag, flop, "box"); 28 | } 29 | else 30 | { 31 | tier1::onlyzero_overwrite_maximum_func(device, flop, flag, flip, "sphere"); 32 | } 33 | flag->readTo(&flag_value); 34 | flag->fill(0); 35 | iteration_count++; 36 | } 37 | if (iteration_count % 2 == 0) 38 | { 39 | flip->copyTo(dst); 40 | } 41 | else 42 | { 43 | flop->copyTo(dst); 44 | } 45 | return dst; 46 | } 47 | 48 | } // namespace cle::tier2 49 | -------------------------------------------------------------------------------- /clic/src/tier2/extended_depth_of_focus_variance_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | extended_depth_of_focus_variance_projection_func(const Device::Pointer & device, 12 | const Array::Pointer & src, 13 | Array::Pointer dst, 14 | float radius_x, 15 | float radius_y, 16 | float sigma) -> Array::Pointer 17 | { 18 | auto variance = tier1::variance_filter_func(device, src, nullptr, radius_x, radius_y, 0, "sphere"); 19 | auto temp = tier1::gaussian_blur_func(device, variance, nullptr, sigma, sigma, 0); 20 | auto altitude = tier1::z_position_of_maximum_z_projection_func(device, temp, nullptr); 21 | return tier1::z_position_projection_func(device, src, altitude, dst); 22 | } 23 | 24 | } // namespace cle::tier2 25 | -------------------------------------------------------------------------------- /clic/src/tier2/invert.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | invert_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 12 | { 13 | return tier1::multiply_image_and_scalar_func(device, src, dst, -1); 14 | } 15 | 16 | } // namespace cle::tier2 17 | -------------------------------------------------------------------------------- /clic/src/tier2/label_spots.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | #include "cle_label_spots_in_x.h" 8 | 9 | namespace cle::tier2 10 | { 11 | 12 | auto 13 | label_spots_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 14 | { 15 | tier0::create_like(src, dst, dType::LABEL); 16 | dst->fill(0); 17 | 18 | auto spot_count_in_x = tier1::sum_x_projection_func(device, src, nullptr); 19 | auto spot_count_in_xy = tier1::sum_y_projection_func(device, spot_count_in_x, nullptr); 20 | 21 | const KernelInfo kernel = { "label_spots_in_x", kernel::label_spots_in_x }; 22 | const ParameterList params = { 23 | { "src", src }, { "dst", dst }, { "countX", spot_count_in_x }, { "countXY", spot_count_in_xy } 24 | }; 25 | const RangeArray range = { 1, dst->height(), dst->depth() }; 26 | execute(device, kernel, params, range); 27 | return dst; 28 | } 29 | 30 | } // namespace cle::tier2 31 | -------------------------------------------------------------------------------- /clic/src/tier2/large_hessian_eigenvalue.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | large_hessian_eigenvalue_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 12 | -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | tier1::hessian_eigenvalues_func(device, src, nullptr, nullptr, dst); 16 | return dst; 17 | } 18 | 19 | } // namespace cle::tier2 20 | -------------------------------------------------------------------------------- /clic/src/tier2/maximum_of_all_pixels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | maximum_of_all_pixels_func(const Device::Pointer & device, const Array::Pointer & src) -> float 12 | { 13 | Array::Pointer dst = nullptr; 14 | Array::Pointer tmp = src; 15 | tier0::create_one(src, dst, dType::FLOAT); 16 | 17 | auto project_if_needed = [&](auto projection_func, int dimension) { 18 | if (dimension > 1) 19 | { 20 | tmp = projection_func(device, tmp, nullptr); 21 | } 22 | }; 23 | 24 | project_if_needed(tier1::maximum_z_projection_func, tmp->depth()); 25 | project_if_needed(tier1::maximum_y_projection_func, tmp->height()); 26 | tier1::maximum_x_projection_func(device, tmp, dst); 27 | 28 | float res; 29 | dst->readTo(&res); 30 | return res; 31 | } 32 | 33 | } // namespace cle::tier2 34 | -------------------------------------------------------------------------------- /clic/src/tier2/minimum_of_all_pixels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | minimum_of_all_pixels_func(const Device::Pointer & device, const Array::Pointer & src) -> float 12 | { 13 | Array::Pointer dst = nullptr; 14 | Array::Pointer tmp = src; 15 | tier0::create_one(src, dst, dType::FLOAT); 16 | 17 | auto project_if_needed = [&](auto projection_func, int dimension) { 18 | if (dimension > 1) 19 | { 20 | tmp = projection_func(device, tmp, nullptr); 21 | } 22 | }; 23 | 24 | project_if_needed(tier1::minimum_z_projection_func, tmp->depth()); 25 | project_if_needed(tier1::minimum_y_projection_func, tmp->height()); 26 | tier1::minimum_x_projection_func(device, tmp, dst); 27 | 28 | float res; 29 | dst->readTo(&res); 30 | return res; 31 | } 32 | 33 | } // namespace cle::tier2 34 | -------------------------------------------------------------------------------- /clic/src/tier2/radians_to_degrees.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | radians_to_degrees_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 12 | -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | return tier1::multiply_image_and_scalar_func(device, src, dst, 180.0 / static_cast(M_PI)); 16 | } 17 | 18 | } // namespace cle::tier2 19 | -------------------------------------------------------------------------------- /clic/src/tier2/reduce_labels_to_label_edges.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | reduce_labels_to_label_edges_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 12 | -> Array::Pointer 13 | { 14 | auto binary = tier1::detect_label_edges_func(device, src, nullptr); 15 | return tier1::mask_func(device, src, binary, dst); 16 | } 17 | 18 | } // namespace cle::tier2 19 | -------------------------------------------------------------------------------- /clic/src/tier2/small_hessian_eigenvalue.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | small_hessian_eigenvalue_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 12 | -> Array::Pointer 13 | { 14 | tier0::create_like(src, dst, dType::FLOAT); 15 | tier1::hessian_eigenvalues_func(device, src, dst, nullptr, nullptr); 16 | return dst; 17 | } 18 | 19 | } // namespace cle::tier2 20 | -------------------------------------------------------------------------------- /clic/src/tier2/square.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | square_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) -> Array::Pointer 12 | { 13 | return tier1::power_func(device, src, dst, 2); 14 | } 15 | 16 | } // namespace cle::tier2 17 | -------------------------------------------------------------------------------- /clic/src/tier2/squared_difference.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | squared_difference_func(const Device::Pointer & device, 12 | const Array::Pointer & src0, 13 | const Array::Pointer & src1, 14 | Array::Pointer dst) -> Array::Pointer 15 | { 16 | tier0::create_like(src0, dst, dType::FLOAT); 17 | auto tmp = tier1::add_images_weighted_func(device, src0, src1, nullptr, 1, -1); 18 | return tier1::power_func(device, tmp, dst, 2); 19 | } 20 | 21 | } // namespace cle::tier2 22 | -------------------------------------------------------------------------------- /clic/src/tier2/stack_operations.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | sub_stack_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int start_z, int end_z) 12 | -> Array::Pointer 13 | { 14 | auto nb_slice = end_z - start_z + 1; 15 | nb_slice = nb_slice < 1 ? 1 : nb_slice; 16 | return tier1::crop_func(device, src, dst, 0, 0, start_z, 0, 0, nb_slice); 17 | } 18 | 19 | auto 20 | reduce_stack_func(const Device::Pointer & device, 21 | const Array::Pointer & src, 22 | Array::Pointer dst, 23 | int reduction_factor, 24 | int offset) -> Array::Pointer 25 | { 26 | reduction_factor = reduction_factor < 1 ? 1 : reduction_factor; 27 | auto num_slice = static_cast(src->depth() / reduction_factor); 28 | 29 | tier0::create_dst(src, dst, src->width(), src->height(), num_slice, src->dtype()); 30 | auto temp_slice = Array::create(src->width(), src->height(), 1, 2, src->dtype(), src->mtype(), device); 31 | for (auto z = 0; z < num_slice; z++) 32 | { 33 | tier1::copy_slice_func(device, src, temp_slice, z * reduction_factor + offset); 34 | tier1::copy_slice_func(device, temp_slice, dst, z); 35 | } 36 | return dst; 37 | } 38 | 39 | } // namespace cle::tier2 40 | -------------------------------------------------------------------------------- /clic/src/tier2/subtract_gaussian_background.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | subtract_gaussian_background_func(const Device::Pointer & device, 12 | const Array::Pointer & src, 13 | Array::Pointer dst, 14 | float sigma_x, 15 | float sigma_y, 16 | float sigma_z) -> Array::Pointer 17 | { 18 | auto temp = tier1::gaussian_blur_func(device, src, nullptr, sigma_x, sigma_y, sigma_z); 19 | return tier1::add_images_weighted_func(device, src, temp, dst, 1, -1); 20 | } 21 | 22 | } // namespace cle::tier2 23 | -------------------------------------------------------------------------------- /clic/src/tier2/subtract_images.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | subtract_images_func(const Device::Pointer & device, 12 | const Array::Pointer & src0, 13 | const Array::Pointer & src1, 14 | Array::Pointer dst) -> Array::Pointer 15 | { 16 | return tier1::add_images_weighted_func(device, src0, src1, dst, 1, -1); 17 | } 18 | 19 | } // namespace cle::tier2 20 | -------------------------------------------------------------------------------- /clic/src/tier2/sum_of_all_pixels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | 5 | #include "utils.hpp" 6 | 7 | namespace cle::tier2 8 | { 9 | 10 | auto 11 | sum_of_all_pixels_func(const Device::Pointer & device, const Array::Pointer & src) -> float 12 | { 13 | Array::Pointer dst = nullptr; 14 | Array::Pointer tmp = src; 15 | tier0::create_one(src, dst, dType::FLOAT); 16 | 17 | auto project_if_needed = [&](auto projection_func, int dimension) { 18 | if (dimension > 1) 19 | { 20 | tmp = projection_func(device, tmp, nullptr); 21 | } 22 | }; 23 | 24 | project_if_needed(tier1::sum_z_projection_func, tmp->depth()); 25 | project_if_needed(tier1::sum_y_projection_func, tmp->height()); 26 | tier1::sum_x_projection_func(device, tmp, dst); 27 | 28 | float res; 29 | dst->readTo(&res); 30 | return res; 31 | } 32 | 33 | } // namespace cle::tier2 34 | -------------------------------------------------------------------------------- /clic/src/tier3/bounding_box.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | namespace cle::tier3 9 | { 10 | 11 | auto 12 | bounding_box_func(const Device::Pointer & device, const Array::Pointer & src) -> std::vector 13 | { 14 | float min_x = 0, min_y = 0, min_z = 0, max_x = 0, max_y = 0, max_z = 0; 15 | auto temp = tier1::multiply_image_and_position_func(device, src, nullptr, 0); 16 | max_x = tier2::maximum_of_all_pixels_func(device, temp); 17 | min_x = tier2::minimum_of_masked_pixels_func(device, temp, src); 18 | temp = tier1::multiply_image_and_position_func(device, src, nullptr, 1); 19 | max_y = tier2::maximum_of_all_pixels_func(device, temp); 20 | min_y = tier2::minimum_of_masked_pixels_func(device, temp, src); 21 | if (src->depth() > 1) 22 | { 23 | temp = tier1::multiply_image_and_position_func(device, src, nullptr, 2); 24 | max_z = tier2::maximum_of_all_pixels_func(device, temp); 25 | min_z = tier2::minimum_of_masked_pixels_func(device, temp, src); 26 | } 27 | return std::vector{ min_x, min_y, min_z, max_x, max_y, max_z }; 28 | } 29 | 30 | } // namespace cle::tier3 31 | -------------------------------------------------------------------------------- /clic/src/tier3/center_of_mass.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | namespace cle::tier3 9 | { 10 | 11 | auto 12 | center_of_mass_func(const Device::Pointer & device, const Array::Pointer & src) -> std::vector 13 | { 14 | auto sum = tier2::sum_of_all_pixels_func(device, src); 15 | auto temp = tier1::multiply_image_and_position_func(device, src, nullptr, 0); 16 | auto sum_x = tier2::sum_of_all_pixels_func(device, temp); 17 | temp = tier1::multiply_image_and_position_func(device, src, nullptr, 1); 18 | auto sum_y = tier2::sum_of_all_pixels_func(device, temp); 19 | temp = tier1::multiply_image_and_position_func(device, src, nullptr, 2); 20 | auto sum_z = tier2::sum_of_all_pixels_func(device, temp); 21 | return std::vector{ sum_x / sum, sum_y / sum, sum_z / sum }; 22 | } 23 | 24 | } // namespace cle::tier3 25 | -------------------------------------------------------------------------------- /clic/src/tier3/clahe.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | #include "cle_clahe.h" 9 | 10 | namespace cle::tier3 11 | { 12 | 13 | auto 14 | clahe_func(const Device::Pointer & device, 15 | const Array::Pointer & src, 16 | Array::Pointer dst, 17 | int tile_size, 18 | float clip_limit, 19 | float minimum_intensity, 20 | float maximum_intensity) -> Array::Pointer 21 | { 22 | tier0::create_like(src, dst); 23 | 24 | if (std::isnan(minimum_intensity) || std::isnan(maximum_intensity)) 25 | { 26 | minimum_intensity = tier2::minimum_of_all_pixels_func(device, src); 27 | maximum_intensity = tier2::maximum_of_all_pixels_func(device, src); 28 | } 29 | clip_limit = clip_limit * 255; // top 1% of the histogram for an 8-bit image 30 | 31 | const KernelInfo kernel = { "clahe", kernel::clahe }; 32 | const ParameterList params = { { "src", src }, 33 | { "dst", dst }, 34 | { "tileSize", tile_size }, 35 | { "clipLimit", clip_limit }, 36 | { "minIntensity", minimum_intensity }, 37 | { "maxIntensity", maximum_intensity } }; 38 | const RangeArray range = { src->width(), src->height(), src->depth() }; 39 | execute(device, kernel, params, range); 40 | return dst; 41 | } 42 | 43 | } // namespace cle::tier3 44 | -------------------------------------------------------------------------------- /clic/src/tier3/flag_existing_labels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | #include "cle_flag_existing_labels.h" 9 | 10 | namespace cle::tier3 11 | { 12 | 13 | auto 14 | flag_existing_labels_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 15 | -> Array::Pointer 16 | { 17 | auto max = tier2::maximum_of_all_pixels_func(device, src); 18 | tier0::create_vector(src, dst, max + 1, dType::LABEL); 19 | dst->fill(0); 20 | const KernelInfo kernel = { "flag_existing_labels", kernel::flag_existing_labels }; 21 | const ParameterList params = { { "src", src }, { "dst", dst } }; 22 | const RangeArray range = { src->width(), src->height(), src->depth() }; 23 | execute(device, kernel, params, range); 24 | return dst; 25 | } 26 | 27 | } // namespace cle::tier3 28 | -------------------------------------------------------------------------------- /clic/src/tier3/gamma_correction.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | namespace cle::tier3 9 | { 10 | 11 | auto 12 | gamma_correction_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, float gamma) 13 | -> Array::Pointer 14 | { 15 | auto max_intensity = tier2::maximum_of_all_pixels_func(device, src); 16 | auto temp1 = tier1::multiply_image_and_scalar_func(device, src, nullptr, 1.0 / max_intensity); 17 | auto temp2 = tier1::power_func(device, temp1, nullptr, gamma); 18 | return tier1::multiply_image_and_scalar_func(device, temp2, dst, max_intensity); 19 | } 20 | 21 | } // namespace cle::tier3 22 | -------------------------------------------------------------------------------- /clic/src/tier3/generate_binary_overlap_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | #include "cle_generate_binary_overlap_matrix.h" 9 | 10 | namespace cle::tier3 11 | { 12 | 13 | auto 14 | generate_binary_overlap_matrix_func(const Device::Pointer & device, 15 | const Array::Pointer & src0, 16 | const Array::Pointer & src1, 17 | Array::Pointer dst) -> Array::Pointer 18 | { 19 | if (dst == nullptr) 20 | { 21 | auto max_label_0 = tier2::maximum_of_all_pixels_func(device, src0) + 1; 22 | auto max_label_1 = tier2::maximum_of_all_pixels_func(device, src1) + 1; 23 | tier0::create_dst(src0, dst, max_label_0, max_label_1, 1, dType::INDEX); 24 | } 25 | dst->fill(0); 26 | const KernelInfo kernel = { "generate_binary_overlap_matrix", kernel::generate_binary_overlap_matrix }; 27 | const ParameterList params = { { "src0", src0 }, { "src1", src1 }, { "dst", dst } }; 28 | const RangeArray range = { src0->width(), src0->height(), src0->depth() }; 29 | execute(device, kernel, params, range); 30 | return dst; 31 | } 32 | 33 | } // namespace cle::tier3 34 | -------------------------------------------------------------------------------- /clic/src/tier3/generate_touch_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | #include "cle_generate_touch_matrix.h" 9 | 10 | namespace cle::tier3 11 | { 12 | 13 | auto 14 | generate_touch_matrix_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 15 | -> Array::Pointer 16 | { 17 | if (dst == nullptr) 18 | { 19 | auto max_label = tier2::maximum_of_all_pixels_func(device, src) + 1; 20 | tier0::create_dst(src, dst, max_label, max_label, 1, dType::INDEX); 21 | } 22 | dst->fill(0); 23 | const KernelInfo kernel = { "generate_touch_matrix", kernel::generate_touch_matrix }; 24 | const ParameterList params = { { "src", src }, { "dst", dst } }; 25 | const RangeArray range = { src->width(), src->height(), src->depth() }; 26 | execute(device, kernel, params, range); 27 | return dst; 28 | } 29 | 30 | } // namespace cle::tier3 31 | -------------------------------------------------------------------------------- /clic/src/tier3/jaccard_index.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | namespace cle::tier3 9 | { 10 | 11 | auto 12 | jaccard_index_func(const Device::Pointer & device, const Array::Pointer & src0, const Array::Pointer & src1) -> float 13 | { 14 | auto intersection_ = tier1::binary_and_func(device, src0, src1, nullptr); 15 | auto union_ = tier1::binary_or_func(device, src0, src1, nullptr); 16 | return tier2::sum_of_all_pixels_func(device, intersection_) / tier2::sum_of_all_pixels_func(device, union_); 17 | } 18 | 19 | } // namespace cle::tier3 20 | -------------------------------------------------------------------------------- /clic/src/tier3/labelled_spots_to_pointlist.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | #include "cle_labelled_spots_to_point_list.h" 9 | 10 | namespace cle::tier3 11 | { 12 | 13 | auto 14 | labelled_spots_to_pointlist_func(const Device::Pointer & device, const Array::Pointer & label, Array::Pointer pointlist) 15 | -> Array::Pointer 16 | { 17 | auto max_label = tier2::maximum_of_all_pixels_func(device, label); 18 | auto dim = shape_to_dimension(label->width(), label->height(), label->depth()); 19 | tier0::create_dst(label, pointlist, max_label, dim, 1, dType::LABEL); 20 | pointlist->fill(0); 21 | 22 | const KernelInfo kernel = { "labelled_spots_to_point_list", kernel::labelled_spots_to_point_list }; 23 | const ParameterList params = { { "src", label }, { "dst", pointlist } }; 24 | const RangeArray range = { label->width(), label->height(), label->depth() }; 25 | execute(device, kernel, params, range); 26 | return pointlist; 27 | } 28 | 29 | } // namespace cle::tier3 30 | -------------------------------------------------------------------------------- /clic/src/tier3/mean_of_all_pixels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | 6 | #include "utils.hpp" 7 | 8 | namespace cle::tier3 9 | { 10 | 11 | auto 12 | mean_of_all_pixels_func(const Device::Pointer & device, const Array::Pointer & src) -> float 13 | { 14 | auto temp = tier2::sum_of_all_pixels_func(device, src); 15 | return temp / src->size(); 16 | } 17 | 18 | } // namespace cle::tier3 19 | -------------------------------------------------------------------------------- /clic/src/tier4/label_bounding_box.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | 7 | #include "utils.hpp" 8 | 9 | namespace cle::tier4 10 | { 11 | 12 | auto 13 | label_bounding_box_func(const Device::Pointer & device, const Array::Pointer & src, int label_id) -> std::vector 14 | { 15 | auto binary = tier1::equal_constant_func(device, src, nullptr, label_id); 16 | return tier3::bounding_box_func(device, binary); 17 | } 18 | 19 | } // namespace cle::tier4 20 | -------------------------------------------------------------------------------- /clic/src/tier4/mean_squared_error.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | 7 | #include "utils.hpp" 8 | 9 | namespace cle::tier4 10 | { 11 | 12 | auto 13 | mean_squared_error_func(const Device::Pointer & device, const Array::Pointer & src0, const Array::Pointer & src1) 14 | -> float 15 | { 16 | auto temp = tier2::squared_difference_func(device, src0, src1, nullptr); 17 | return tier3::mean_of_all_pixels_func(device, temp); 18 | } 19 | 20 | } // namespace cle::tier4 21 | -------------------------------------------------------------------------------- /clic/src/tier4/relabel_sequential.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | 7 | #include "utils.hpp" 8 | 9 | namespace cle::tier4 10 | { 11 | 12 | auto 13 | relabel_sequential_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int blocksize) 14 | -> Array::Pointer 15 | { 16 | tier0::create_like(src, dst); 17 | auto max_label = static_cast(tier2::maximum_of_all_pixels_func(device, src)); 18 | auto flagged = Array::create(int(max_label + 1), 1, 1, 1, src->dtype(), src->mtype(), src->device()); 19 | flagged->fill(0); 20 | tier3::flag_existing_labels_func(device, src, flagged); 21 | tier1::set_column_func(device, flagged, 0, 0); 22 | auto block_sums = 23 | Array::create(((max_label + 1) / blocksize) + 1, 1, 1, 1, flagged->dtype(), flagged->mtype(), flagged->device()); 24 | tier1::sum_reduction_x_func(device, flagged, block_sums, blocksize); 25 | auto new_indices = Array::create(max_label + 1, 1, 1, 1, flagged->dtype(), flagged->mtype(), flagged->device()); 26 | tier1::block_enumerate_func(device, flagged, block_sums, new_indices, blocksize); 27 | tier1::replace_values_func(device, src, new_indices, dst); 28 | return dst; 29 | } 30 | 31 | } // namespace cle::tier4 32 | -------------------------------------------------------------------------------- /clic/src/tier4/spots_to_pointlist.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | 7 | #include "utils.hpp" 8 | 9 | namespace cle::tier4 10 | { 11 | 12 | auto 13 | spots_to_pointlist_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 14 | -> Array::Pointer 15 | { 16 | auto labeled_spots = tier2::label_spots_func(device, src, nullptr); 17 | return tier3::labelled_spots_to_pointlist_func(device, labeled_spots, dst); 18 | } 19 | 20 | } // namespace cle::tier4 21 | -------------------------------------------------------------------------------- /clic/src/tier5/array_equal.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | 8 | #include "utils.hpp" 9 | 10 | namespace cle::tier5 11 | { 12 | 13 | auto 14 | array_equal_func(const Device::Pointer & device, const Array::Pointer & src0, const Array::Pointer & src1) -> bool 15 | { 16 | // check if size is equal 17 | if (src0->size() != src1->size()) 18 | { 19 | return false; 20 | } 21 | // check if width, height, depth is equal 22 | if (src0->width() != src1->width() || src0->height() != src1->height() || src0->depth() != src1->depth()) 23 | { 24 | return false; 25 | } 26 | // check if empty 27 | if (src0->size() == 0 && src1->size() == 0) 28 | { 29 | return true; 30 | } 31 | auto mse = tier4::mean_squared_error_func(device, src0, src1); 32 | return mse == 0; 33 | } 34 | 35 | } // namespace cle::tier5 36 | -------------------------------------------------------------------------------- /clic/src/tier5/combine_labels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | 8 | #include "utils.hpp" 9 | 10 | namespace cle::tier5 11 | { 12 | 13 | auto 14 | combine_labels_func(const Device::Pointer & device, 15 | const Array::Pointer & src0, 16 | const Array::Pointer & src1, 17 | Array::Pointer dst) -> Array::Pointer 18 | { 19 | tier0::create_like(src0, dst, dType::LABEL); 20 | auto max_label = tier2::maximum_of_all_pixels_func(device, src0); 21 | auto temp1 = tier1::add_image_and_scalar_func(device, src1, nullptr, max_label); 22 | auto temp2 = tier1::greater_constant_func(device, src1, nullptr, 0); 23 | temp1 = tier1::mask_func(device, temp1, temp2, nullptr); 24 | temp2 = tier1::maximum_images_func(device, src0, temp1, nullptr); 25 | return tier4::relabel_sequential_func(device, temp2, dst, 4096); 26 | } 27 | 28 | } // namespace cle::tier5 29 | -------------------------------------------------------------------------------- /clic/src/tier5/reduce_labels_to_centroids.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | 8 | #include "utils.hpp" 9 | 10 | namespace cle::tier5 11 | { 12 | 13 | auto 14 | reduce_labels_to_centroids_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst) 15 | -> Array::Pointer 16 | { 17 | tier0::create_like(src, dst, dType::LABEL); 18 | dst->fill(0); 19 | 20 | auto pos = tier4::centroids_of_labels_func(device, src, nullptr, true); 21 | auto label_pos = Array::create(pos->width(), 4, 1, 2, dType::FLOAT, mType::BUFFER, device); 22 | tier1::set_ramp_x_func(device, label_pos); 23 | pos->copyTo(label_pos, { pos->width(), 3, 1 }, { 0, 0, 0 }, { 0, 0, 0 }); 24 | 25 | tier1::set_column_func(device, label_pos, 0, -1); 26 | tier1::nan_to_num_func(device, label_pos, label_pos, -1, -1, -1); 27 | return tier1::write_values_to_positions_func(device, label_pos, dst); 28 | } 29 | 30 | } // namespace cle::tier5 31 | -------------------------------------------------------------------------------- /clic/src/tier6/dilate_labels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | 9 | #include "utils.hpp" 10 | 11 | namespace cle::tier6 12 | { 13 | 14 | auto 15 | dilate_labels_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int radius) 16 | -> Array::Pointer 17 | { 18 | tier0::create_like(src, dst, dType::LABEL); 19 | if (radius <= 0) 20 | { 21 | return tier1::copy_func(device, src, dst); 22 | } 23 | 24 | auto flip = tier1::copy_func(device, src, nullptr); 25 | auto flop = Array::create(flip); 26 | auto flag = Array::create(1, 1, 1, 1, dType::FLOAT, mType::BUFFER, device); 27 | flag->fill(0); 28 | 29 | int iter_count = 0; 30 | float flag_value = 1; 31 | while (flag_value > 0 && iter_count < radius) 32 | { 33 | auto active = (iter_count % 2 == 0) ? flip : flop; 34 | auto passive = (iter_count % 2 == 0) ? flop : flip; 35 | tier1::onlyzero_overwrite_maximum_func(device, active, flag, passive, (iter_count % 2 == 0) ? "box" : "sphere"); 36 | flag->readTo(&flag_value); 37 | if (flag_value > 0) 38 | { 39 | flag->fill(0); 40 | } 41 | iter_count++; 42 | } 43 | 44 | return tier1::copy_func(device, (iter_count % 2 == 0) ? flip : flop, dst); 45 | } 46 | 47 | } // namespace cle::tier6 48 | -------------------------------------------------------------------------------- /clic/src/tier6/gauss_otsu_labeling.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | 9 | #include "utils.hpp" 10 | 11 | namespace cle::tier6 12 | { 13 | 14 | auto 15 | gauss_otsu_labeling_func(const Device::Pointer & device, 16 | const Array::Pointer & src, 17 | Array::Pointer dst, 18 | float outline_sigma) -> Array::Pointer 19 | { 20 | tier0::create_like(src, dst, dType::LABEL); 21 | auto temp = tier1::gaussian_blur_func(device, src, nullptr, outline_sigma, outline_sigma, outline_sigma); 22 | auto binary = tier4::threshold_otsu_func(device, temp, nullptr); 23 | tier5::connected_component_labeling_func(device, binary, dst, "box"); 24 | return dst; 25 | } 26 | 27 | } // namespace cle::tier6 28 | -------------------------------------------------------------------------------- /clic/src/tier6/voronoi_labeling.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | 9 | #include "utils.hpp" 10 | 11 | namespace cle::tier6 12 | { 13 | 14 | auto 15 | voronoi_labeling_func(const Device::Pointer & device, const Array::Pointer & input_binary, Array::Pointer output_labels) 16 | -> Array::Pointer 17 | { 18 | tier0::create_like(input_binary, output_labels, dType::LABEL); 19 | auto flip = tier5::connected_component_labeling_func(device, input_binary, nullptr, "box"); 20 | return tier2::extend_labeling_via_voronoi_func(device, flip, output_labels); 21 | } 22 | 23 | } // namespace cle::tier6 24 | -------------------------------------------------------------------------------- /clic/src/tier7/closing_labels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | 10 | #include "utils.hpp" 11 | 12 | namespace cle::tier7 13 | { 14 | 15 | auto 16 | closing_labels_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int radius) 17 | -> Array::Pointer 18 | { 19 | tier0::create_like(src, dst, dType::LABEL); 20 | if (radius == 0) 21 | { 22 | return tier1::copy_func(device, src, dst); 23 | } 24 | auto temp = tier6::dilate_labels_func(device, src, nullptr, radius); 25 | auto flip = tier1::greater_constant_func(device, temp, nullptr, 0); 26 | auto flop = Array::create(flip); 27 | for (size_t i = 0; i < radius; i++) 28 | { 29 | tier1::binary_erode_func(device, (i % 2 == 0) ? flip : flop, flop, 1, 1, 1, (i % 2 == 0) ? "sphere" : "box"); 30 | } 31 | return tier1::multiply_images_func(device, (radius % 2 == 0) ? flip : flop, temp, dst); 32 | } 33 | 34 | } // namespace cle::tier7 35 | -------------------------------------------------------------------------------- /clic/src/tier7/erode_connected_labels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | 10 | #include "utils.hpp" 11 | 12 | namespace cle::tier7 13 | { 14 | 15 | auto 16 | erode_connected_labels_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int radius) 17 | -> Array::Pointer 18 | { 19 | tier0::create_like(src, dst, dType::LABEL); 20 | if (radius < 1) 21 | { 22 | return tier1::copy_func(device, src, dst); 23 | } 24 | auto temp = tier1::greater_constant_func(device, src, nullptr, 0); 25 | auto eroded = tier6::erode_labels_func(device, temp, nullptr, radius, false); 26 | temp = tier1::multiply_images_func(device, src, eroded, nullptr); 27 | return tier4::relabel_sequential_func(device, temp, dst, 4096); 28 | } 29 | 30 | } // namespace cle::tier7 31 | -------------------------------------------------------------------------------- /clic/src/tier7/eroded_otsu_labeling.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | 10 | #include "utils.hpp" 11 | 12 | namespace cle::tier7 13 | { 14 | 15 | auto 16 | eroded_otsu_labeling_func(const Device::Pointer & device, 17 | const Array::Pointer & src, 18 | Array::Pointer dst, 19 | int number_of_erosions, 20 | float outline_sigma) -> Array::Pointer 21 | { 22 | tier0::create_like(src, dst, dType::LABEL); 23 | auto blurred = tier1::gaussian_blur_func(device, src, nullptr, outline_sigma, outline_sigma, outline_sigma); 24 | auto binary = tier4::threshold_otsu_func(device, blurred, nullptr); 25 | Array::Pointer eroded1 = nullptr; 26 | Array::Pointer eroded2 = nullptr; 27 | tier0::create_like(binary, eroded1); 28 | tier0::create_like(binary, eroded2); 29 | binary->copyTo(eroded1); 30 | for (int i = 0; i < number_of_erosions; i++) 31 | { 32 | tier1::binary_erode_func(device, eroded1, eroded2, 1, 1, 1, "box"); 33 | std::swap(eroded1, eroded2); 34 | } 35 | return tier6::masked_voronoi_labeling_func(device, eroded1, binary, dst); 36 | } 37 | 38 | } // namespace cle::tier7 39 | -------------------------------------------------------------------------------- /clic/src/tier7/opening_labels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | 10 | #include "utils.hpp" 11 | 12 | namespace cle::tier7 13 | { 14 | 15 | auto 16 | opening_labels_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int radius) 17 | -> Array::Pointer 18 | { 19 | tier0::create_like(src, dst, dType::LABEL); 20 | auto temp = tier6::erode_labels_func(device, src, nullptr, radius, false); 21 | return tier6::dilate_labels_func(device, temp, dst, radius); 22 | } 23 | 24 | } // namespace cle::tier7 25 | -------------------------------------------------------------------------------- /clic/src/tier7/rotate.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | 10 | #include "transform.hpp" 11 | #include "utils.hpp" 12 | 13 | namespace cle::tier7 14 | { 15 | 16 | auto 17 | rotate_func(const Device::Pointer & device, 18 | const Array::Pointer & src, 19 | Array::Pointer dst, 20 | float angle_x, 21 | float angle_y, 22 | float angle_z, 23 | bool centered, 24 | bool interpolate, 25 | bool resize) -> Array::Pointer 26 | { 27 | auto transform = AffineTransform(); 28 | if (centered) 29 | { 30 | transform.center({ src->width(), src->height(), src->depth() }, false); 31 | } 32 | if (angle_x != 0) 33 | { 34 | transform.rotate(0, angle_x); 35 | } 36 | if (angle_y != 0) 37 | { 38 | transform.rotate(1, angle_y); 39 | } 40 | if (angle_z != 0) 41 | { 42 | transform.rotate(2, angle_z); 43 | } 44 | if (centered) 45 | { 46 | transform.center({ src->width(), src->height(), src->depth() }, true); 47 | } 48 | return cle::apply_affine_transform(src, dst, transform, interpolate, resize); 49 | } 50 | 51 | } // namespace cle::tier7 52 | -------------------------------------------------------------------------------- /clic/src/tier7/scale.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | 10 | #include "transform.hpp" 11 | #include "utils.hpp" 12 | 13 | namespace cle::tier7 14 | { 15 | 16 | auto 17 | scale_func(const Device::Pointer & device, 18 | const Array::Pointer & src, 19 | Array::Pointer dst, 20 | float factor_x, 21 | float factor_y, 22 | float factor_z, 23 | bool centered, 24 | bool interpolate, 25 | bool resize) -> Array::Pointer 26 | { 27 | auto transform = AffineTransform(); 28 | if (centered && !resize) 29 | { 30 | transform.center({ src->width(), src->height(), src->depth() }, false); 31 | } 32 | transform.scale(factor_x, factor_y, factor_z); 33 | if (centered && !resize) 34 | { 35 | transform.center({ src->width(), src->height(), src->depth() }, true); 36 | } 37 | return cle::apply_affine_transform(src, dst, transform, interpolate, resize); 38 | } 39 | 40 | } // namespace cle::tier7 41 | -------------------------------------------------------------------------------- /clic/src/tier7/translate.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | 10 | #include "transform.hpp" 11 | #include "utils.hpp" 12 | 13 | namespace cle::tier7 14 | { 15 | 16 | auto 17 | translate_func(const Device::Pointer & device, 18 | const Array::Pointer & src, 19 | Array::Pointer dst, 20 | float translate_x, 21 | float translate_y, 22 | float translate_z, 23 | bool interpolate) -> Array::Pointer 24 | { 25 | auto transform = AffineTransform(); 26 | transform.translate(translate_x, translate_y, translate_z); 27 | return cle::apply_affine_transform(src, dst, transform, interpolate, false); 28 | } 29 | 30 | } // namespace cle::tier7 31 | -------------------------------------------------------------------------------- /clic/src/tier7/voronoi_otsu_labeling.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | 10 | #include "utils.hpp" 11 | 12 | namespace cle::tier7 13 | { 14 | 15 | auto 16 | voronoi_otsu_labeling_func(const Device::Pointer & device, 17 | const Array::Pointer & src, 18 | Array::Pointer dst, 19 | float spot_sigma, 20 | float outline_sigma) -> Array::Pointer 21 | { 22 | tier0::create_like(src, dst, dType::LABEL); 23 | 24 | auto temp = tier1::gaussian_blur_func(device, src, nullptr, spot_sigma, spot_sigma, spot_sigma); 25 | auto spot = tier2::detect_maxima_func(device, temp, nullptr, 0, 0, 0, "box"); 26 | 27 | temp = tier1::gaussian_blur_func(device, src, nullptr, outline_sigma, outline_sigma, outline_sigma); 28 | auto segmentation = tier4::threshold_otsu_func(device, temp, nullptr); 29 | 30 | auto binary = tier1::binary_and_func(device, spot, segmentation, nullptr); 31 | temp = tier6::masked_voronoi_labeling_func(device, binary, segmentation, nullptr); 32 | return tier1::mask_func(device, temp, segmentation, dst); 33 | } 34 | 35 | } // namespace cle::tier7 36 | -------------------------------------------------------------------------------- /clic/src/tier8/smooth_connected_labels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | #include "tier8.hpp" 10 | 11 | #include "utils.hpp" 12 | 13 | namespace cle::tier8 14 | { 15 | 16 | auto 17 | smooth_connected_labels_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int radius) 18 | -> Array::Pointer 19 | { 20 | tier0::create_like(src, dst, dType::LABEL); 21 | if (radius < 1) 22 | { 23 | return tier1::copy_func(device, src, dst); 24 | } 25 | auto binary = tier7::erode_connected_labels_func(device, src, nullptr, radius); 26 | return tier6::dilate_labels_func(device, binary, dst, radius); 27 | } 28 | 29 | } // namespace cle::tier8 30 | -------------------------------------------------------------------------------- /clic/src/tier8/smooth_labels.cpp: -------------------------------------------------------------------------------- 1 | #include "tier0.hpp" 2 | #include "tier1.hpp" 3 | #include "tier2.hpp" 4 | #include "tier3.hpp" 5 | #include "tier4.hpp" 6 | #include "tier5.hpp" 7 | #include "tier6.hpp" 8 | #include "tier7.hpp" 9 | #include "tier8.hpp" 10 | 11 | #include "utils.hpp" 12 | 13 | namespace cle::tier8 14 | { 15 | 16 | auto 17 | smooth_labels_func(const Device::Pointer & device, const Array::Pointer & src, Array::Pointer dst, int radius) 18 | -> Array::Pointer 19 | { 20 | tier0::create_like(src, dst, dType::LABEL); 21 | if (radius < 1) 22 | { 23 | return tier1::copy_func(device, src, dst); 24 | } 25 | auto binary = tier1::greater_constant_func(device, src, nullptr, 0); 26 | auto opened = tier7::opening_labels_func(device, src, nullptr, radius); 27 | auto extended = tier2::extend_labeling_via_voronoi_func(device, opened, nullptr); 28 | return tier1::multiply_images_func(device, binary, extended, dst); 29 | } 30 | 31 | } // namespace cle::tier8 32 | -------------------------------------------------------------------------------- /clic/thirdparty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(FetchContent) 2 | 3 | 4 | 5 | ## Fetch OpenCL kernel sources 6 | FetchContent_Declare(cleKernels 7 | GIT_REPOSITORY https://github.com/clEsperanto/clij-opencl-kernels.git 8 | GIT_TAG ${kernel_version_tag} 9 | GIT_SHALLOW ON 10 | ) 11 | 12 | ## Fetch Eigen library sources 13 | FetchContent_Declare(eigen 14 | GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git 15 | GIT_TAG ${eigen_lib_version_tag} 16 | GIT_SHALLOW ON 17 | ) 18 | 19 | # # Fetch clFFT library sources 20 | # FetchContent_Declare(clFFT 21 | # GIT_REPOSITORY https://github.com/clEsperanto/clFFT # https://github.com/clMathLibraries/clFFT.git 22 | # GIT_TAG clic-build #master 23 | # GIT_SHALLOW ON 24 | # SOURCE_SUBDIR src # clFFT CMakeLists.txt is in src/ instead of root 25 | # ) 26 | 27 | FetchContent_MakeAvailable(cleKernels eigen ) # clFFT 28 | 29 | 30 | 31 | 32 | # Fetch vkFFT library sources 33 | set(VKFFT_BACKEND 3 CACHE STRING "VkFFT backend to use (1, 2, 3)") 34 | set(VKFFT_MAX_FFT_DIMENSIONS 4 CACHE STRING "VkFFT maximum dimension supported") 35 | FetchContent_Declare(VkFFT 36 | GIT_REPOSITORY https://github.com/DTolm/VkFFT 37 | GIT_TAG v1.3.4 #master 38 | GIT_SHALLOW ON 39 | ) 40 | # FetchContent_MakeAvailable(VkFFT) 41 | 42 | if(NOT VkFFT_POPULATED) 43 | FetchContent_Populate(VkFFT) 44 | endif() 45 | add_library(VkFFT INTERFACE) 46 | target_compile_definitions(VkFFT INTERFACE -DVKFFT_BACKEND=${VKFFT_BACKEND} -DVKFFT_MAX_FFT_DIMENSIONS=${VKFFT_MAX_FFT_DIMENSIONS}) 47 | -------------------------------------------------------------------------------- /cmake/CLIcConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | if(NOT TARGET ${PROJECT_NAME}::${PROJECT_NAME}) 4 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") 5 | endif() 6 | 7 | set(@PROJECT_NAME_UPPERCASE@_LIBRARIES @PROJECT_NAME@::@PROJECT_NAME@) 8 | 9 | # find GPU Framework (OpenCL, CUDA) 10 | find_package(OpenCL) 11 | find_package(clFFT) 12 | # find_package(CUDA) 13 | # find_package(CUDAToolkit) 14 | if (NOT OpenCL_FOUND AND NOT CUDAToolkit_FOUND AND NOT CUDA_FOUND) 15 | message(FATAL_ERROR "No GPU framework found (OpenCL, CUDA). Please install one of them in order to compile the librairy.") 16 | endif() 17 | 18 | check_required_components("@PROJECT_NAME@") 19 | -------------------------------------------------------------------------------- /cmake/CMakeBackends.cmake: -------------------------------------------------------------------------------- 1 | message(STATUS "Searching for backend dependencies") 2 | 3 | set(CLE_OPENCL false) 4 | set(CLE_CUDA false) 5 | 6 | if (OpenCL_LIBRARIES AND OpenCL_INCLUDE_DIRS) 7 | set(OpenCL_FOUND true) 8 | else() 9 | find_package(OpenCL) 10 | endif() 11 | if (OpenCL_FOUND) 12 | message(STATUS "OpenCL library : ${OpenCL_LIBRARIES}") 13 | message(STATUS "OpenCL includes : ${OpenCL_INCLUDE_DIRS}") 14 | set(CLE_OPENCL true) 15 | endif() 16 | 17 | # if(CUDAToolkit_LIBRARY_DIR AND CUDAToolkit_INCLUDE_DIRS) 18 | # set(CUDAToolkit_FOUND true) 19 | # else() 20 | # find_package(CUDAToolkit) 21 | # endif() 22 | # if (CUDAToolkit_FOUND) 23 | # set(CLE_CUDA true) 24 | # message(STATUS "CUDAToolkit library : ${CUDAToolkit_LIBRARY_DIR}") 25 | # message(STATUS "CUDAToolkit includes : ${CUDAToolkit_INCLUDE_DIRS}") 26 | # endif() 27 | 28 | if (NOT OpenCL_FOUND AND NOT CUDAToolkit_FOUND) 29 | message(FATAL_ERROR "No GPU framework found (OpenCL, CUDA). Please provide one of these GPU frameworks in order to compile the library.") 30 | endif() 31 | 32 | # add the variables to the compile definitions for the source code 33 | add_compile_definitions( 34 | $<$:CLE_CUDA> 35 | $<$:CLE_OPENCL> 36 | ) 37 | -------------------------------------------------------------------------------- /cmake/CMakeDoxygen.cmake: -------------------------------------------------------------------------------- 1 | find_package(Doxygen) 2 | 3 | set(SOURCE_FOLDER ${CMAKE_SOURCE_DIR}/clic/) 4 | configure_file(Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) 5 | 6 | if(DOXYGEN_FOUND) 7 | set(DOXYGEN_INPUT "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile") # Path to the generated Doxyfile 8 | # Add a custom target to run Doxygen when building the documentation 9 | add_custom_target( 10 | documentation 11 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT} 12 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 13 | COMMENT "Generating Doxygen documentation" 14 | VERBATIM 15 | ) 16 | # Add the 'documentation' target as a dependency for 'all' (build all by default) 17 | add_dependencies(${LIBRARY_NAME} documentation) 18 | else() 19 | message(STATUS "Doxygen not found, documentation target will not be available.") 20 | endif() 21 | -------------------------------------------------------------------------------- /docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.20) 2 | 3 | project(clic-docs) 4 | 5 | # Find Doxygen and Sphinx executables to build the documentation 6 | find_package(Doxygen) 7 | find_program(SPHINX 8 | NAMES sphinx-build 9 | DOC "Path to sphinx-build executable" 10 | ) 11 | 12 | # If Doxygen or Sphinx are not found, the documentation target will not be available 13 | if (NOT DOXYGEN_FOUND) 14 | message(STATUS "Doxygen not found, documentation target will not be available.") 15 | return() 16 | endif() 17 | if (NOT SPHINX) 18 | message(STATUS "Sphinx not found, documentation target will not be available.") 19 | return() 20 | endif() 21 | 22 | # Add a custom target to run Doxygen when building the documentation 23 | add_custom_target( 24 | doxygen 25 | COMMAND doxygen ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile 26 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 27 | COMMENT "Generating Doxygen documentation" 28 | VERBATIM 29 | ) 30 | 31 | # Add a custom target to run Sphinx when building the documentation 32 | add_custom_target( 33 | documentation 34 | COMMAND make html 35 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 36 | COMMENT "Generating Sphinx documentation" 37 | VERBATIM 38 | DEPENDS doxygen 39 | ) 40 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Redirecting to master branch 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/source/_templates/versions.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | Version: {{ current_version }} 4 | 5 | 6 |
7 | {% if versions|length >= 1 %} 8 |
9 |
{{ _('Versions') }}
10 | {% for the_version, url in versions %} 11 |
{{ the_version }}
12 | {% endfor %} 13 |
14 | {% endif %} 15 | {% if languages|length >= 1 %} 16 |
17 |
{{ _('Languages') }}
18 | {% for the_language, url in languages %} 19 |
{{ the_language }}
20 | {% endfor %} 21 |
22 | {% endif %} 23 |
24 | 25 |
26 |
27 | -------------------------------------------------------------------------------- /docs/source/api/array.rst: -------------------------------------------------------------------------------- 1 | Array Class 2 | =========== 3 | 4 | The ``Array`` class is the primary data structure class of the library. 5 | It stores the pointer to the memory space in the ``Device``, along with the necessary information to access and manipulate it. 6 | The class is intended to be used through smart pointers defined as ``Array::Pointer`` and should not be accessed directly. 7 | Hence, the creation of an ``Array`` object is done through ``Array::create()`` function. 8 | 9 | The class provides a set of methods that describe the array, such as its ``size``, ``width``, ``dtype``, among others. 10 | It also provides methods to write/read data to and from the host, and to perform operations on the array, such as ``fill`` and ``copy``. 11 | 12 | This object is the main input and output of the library functions. 13 | 14 | .. doxygenclass:: cle::Array 15 | :members: 16 | -------------------------------------------------------------------------------- /docs/source/api/device.rst: -------------------------------------------------------------------------------- 1 | Device Class 2 | ============ 3 | 4 | A ``Device`` is a processing unit that can execute OpenCL kernels. 5 | It is mainly a GPU, but it can also be a CPU or a simulation of a device (e.g. `pocl`, `oclgrind`). 6 | It is a good practice to consider a device as a mini computer with its own memory with which you can communicate through the OpenCL API. 7 | This class holds a set of information allowing the identification of a specific hardware for future communication with it during execution. 8 | 9 | 10 | The class has no processing functions; it is mainly used to store necessary information required to identify the hardware. 11 | The detection and the communication is managed by ``Backend`` class. 12 | 13 | Users should not need to interact with the ``Device`` class extensively, except during the initialization of the library or when using multiple devices for computation. 14 | 15 | .. doxygenclass:: cle::Device 16 | :members: 17 | -------------------------------------------------------------------------------- /docs/source/api/tiers.rst: -------------------------------------------------------------------------------- 1 | 2 | Operation tier list 3 | =================== 4 | 5 | The tiers hold the different operations that are available in CLIc. 6 | These operations are grouped by their complexity, following the rules that a function in tier N implement a function from tier N-1. 7 | 8 | tier1 9 | ----- 10 | 11 | .. doxygennamespace:: cle::tier1 12 | :members: 13 | 14 | tier2 15 | ----- 16 | 17 | .. doxygennamespace:: cle::tier2 18 | :members: 19 | 20 | tier3 21 | ----- 22 | 23 | .. doxygennamespace:: cle::tier3 24 | :members: 25 | 26 | tier4 27 | ----- 28 | 29 | .. doxygennamespace:: cle::tier4 30 | :members: 31 | 32 | tier5 33 | ----- 34 | 35 | .. doxygennamespace:: cle::tier5 36 | :members: 37 | 38 | tier6 39 | ----- 40 | 41 | .. doxygennamespace:: cle::tier6 42 | :members: 43 | 44 | tier7 45 | ----- 46 | 47 | .. doxygennamespace:: cle::tier7 48 | :members: 49 | 50 | tier8 51 | ----- 52 | 53 | .. doxygennamespace:: cle::tier8 54 | :members: 55 | -------------------------------------------------------------------------------- /docs/source/doc/contributing.rst: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | clEsperanto is an open-source project, and we welcome contributions of all kinds. There are many ways to help, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or writing code which can be incorporated into clEsperanto itself. 5 | Do not hesitate to ask questions on the `forum `__ or to open an `issue `__ on GitHub. 6 | 7 | Versioning 8 | ---------- 9 | 10 | The versioning of this project is based on the `Semantic Versioning Specification `__. 11 | 12 | Semantic Versions are in the format: ``MAJOR.MINOR.PATCH``. 13 | 14 | - :bug and typo fix: increase the patch version 15 | - :new functionality in a non-breaking way: increase the minor version (and reset patch to 0) 16 | - :breaking changes: increase the major version (and reset the patch and minor version to 0). 17 | 18 | The project version is managed directly in the github release page. 19 | 20 | .. note:: 21 | 22 | We are currently in a alpha stage, ``MAJOR`` is kept to 0 until we reach a stable version. 23 | -------------------------------------------------------------------------------- /docs/source/doc/tests.rst: -------------------------------------------------------------------------------- 1 | Running tests 2 | ============= 3 | 4 | Simply building the library does not necessarily guarantee its correct functionality. Tests provided with the library must be run to ensure that the library is working as expected. 5 | 6 | It's essential to set the option ``-D BUILD_TESTS=ON`` during configuration (it should be set by default if you followed the instructions in the `Compilation `__ section). 7 | This step is highly recommended during development to verify the library's functionality after each modification. 8 | 9 | To run all the tests, you can use the following command in the build directory: 10 | 11 | .. code-block:: bash 12 | 13 | ctest --test-dir ./build -C Debug -V 14 | 15 | The ``--test-dir`` flag specifies the directory where the build is located. The ``-C`` flag specifies the configuration to use. 16 | The ``-V`` flag indicates that the tests should be run in verbose mode. 17 | 18 | .. warning:: 19 | 20 | If built traditionally, the root directory of the build should be ``./build/{config_type_build}/``, where ``{config_type_build}`` depends on the system and configuration used, e.g., ``./build/linux-ninja-multi/`` for Ubuntu systems. 21 | 22 | .. note:: 23 | 24 | It is also possible to run a particular test using the ``ctest`` command: ``ctest --test-dir ./build -C Debug -R {test_name}``. 25 | 26 | If using VSCode or any other IDE, it is also possible to run the tests directly from it. Please refer to the respective software documentation for instructions on how to run the tests with CMake and the IDE. 27 | -------------------------------------------------------------------------------- /docs/source/images/logo_d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clEsperanto/CLIc/5203ef4e0d2b0c2cb8a7a6adf0aad146f20b4892/docs/source/images/logo_d.png -------------------------------------------------------------------------------- /docs/source/images/logo_d_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clEsperanto/CLIc/5203ef4e0d2b0c2cb8a7a6adf0aad146f20b4892/docs/source/images/logo_d_small.png -------------------------------------------------------------------------------- /docs/source/images/logo_w.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clEsperanto/CLIc/5203ef4e0d2b0c2cb8a7a6adf0aad146f20b4892/docs/source/images/logo_w.png -------------------------------------------------------------------------------- /docs/source/versions.yaml: -------------------------------------------------------------------------------- 1 | "0.16.0": 2 | tag: '0.16.0' 3 | languages: 4 | - "en" 5 | "0.15.1": 6 | tag: '0.15.1' 7 | languages: 8 | - "en" 9 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include(FetchContent) 3 | FetchContent_Declare( 4 | googletest 5 | GIT_REPOSITORY https://github.com/google/googletest.git 6 | GIT_TAG v1.14.0 7 | ) 8 | FetchContent_MakeAvailable(googletest) 9 | 10 | add_subdirectory(core) 11 | add_subdirectory(tier1) 12 | add_subdirectory(tier2) 13 | add_subdirectory(tier3) 14 | add_subdirectory(tier4) 15 | add_subdirectory(tier5) 16 | add_subdirectory(tier6) 17 | add_subdirectory(tier7) 18 | add_subdirectory(tier8) 19 | -------------------------------------------------------------------------------- /tests/core/test_backends.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "cle.hpp" 3 | 4 | #include 5 | 6 | class TestBackends : public ::testing::TestWithParam 7 | {}; 8 | 9 | TEST_P(TestBackends, manager) 10 | { 11 | auto backend_list = cle::BackendManager::getInstance().getBackendsList(); 12 | EXPECT_FALSE(backend_list.empty()); 13 | 14 | auto ocl_flag = cle::BackendManager::getInstance().openCLEnabled(); 15 | auto cuda_flag = cle::BackendManager::getInstance().cudaEnabled(); 16 | EXPECT_TRUE(ocl_flag || cuda_flag); 17 | 18 | std::string param = GetParam(); 19 | cle::BackendManager::getInstance().setBackend(param); 20 | 21 | auto backend_type = cle::BackendManager::getInstance().getBackend().getType(); 22 | EXPECT_TRUE(backend_type == cle::Backend::Type::CUDA || backend_type == cle::Backend::Type::OPENCL); 23 | } 24 | 25 | std::vector 26 | getParameters() 27 | { 28 | std::vector parameters; 29 | #if USE_OPENCL 30 | parameters.push_back("opencl"); 31 | #endif 32 | #if USE_CUDA 33 | parameters.push_back("cuda"); 34 | #endif 35 | return parameters; 36 | } 37 | 38 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestBackends, ::testing::ValuesIn(getParameters())); 39 | -------------------------------------------------------------------------------- /tests/tier1/test_absolute.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestAbsolute : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input; 11 | std::array valid; 12 | 13 | virtual void 14 | SetUp() 15 | { 16 | std::fill(input.begin(), input.end(), static_cast(-7)); 17 | std::fill(valid.begin(), valid.end(), static_cast(7)); 18 | } 19 | }; 20 | 21 | TEST_P(TestAbsolute, execute) 22 | { 23 | std::string param = GetParam(); 24 | cle::BackendManager::getInstance().setBackend(param); 25 | 26 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 27 | device->setWaitToFinish(true); 28 | 29 | auto gpu_input = cle::Array::create(10, 5, 3, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 30 | gpu_input->writeFrom(input.data()); 31 | auto gpu_output = cle::tier1::absolute_func(device, gpu_input, nullptr); 32 | 33 | gpu_output->readTo(output.data()); 34 | for (int i = 0; i < output.size(); i++) 35 | { 36 | EXPECT_EQ(output[i], valid[i]); 37 | } 38 | } 39 | 40 | std::vector 41 | getParameters() 42 | { 43 | std::vector parameters; 44 | #if USE_OPENCL 45 | parameters.push_back("opencl"); 46 | #endif 47 | #if USE_CUDA 48 | parameters.push_back("cuda"); 49 | #endif 50 | return parameters; 51 | } 52 | 53 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestAbsolute, ::testing::ValuesIn(getParameters())); 54 | -------------------------------------------------------------------------------- /tests/tier1/test_circular_shift.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestCircularShift : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array input = { 10 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 11 | }; 12 | std::array valid = { 7, 8, 5, 6, 11, 12, 9, 10, 3, 4, 1, 2 }; 13 | std::array output; 14 | }; 15 | 16 | TEST_P(TestCircularShift, execute) 17 | { 18 | std::string param = GetParam(); 19 | cle::BackendManager::getInstance().setBackend(param); 20 | 21 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 22 | device->setWaitToFinish(true); 23 | 24 | auto gpu_input = cle::Array::create(4, 3, 1, 2, cle::dType::FLOAT, cle::mType::BUFFER, device); 25 | gpu_input->writeFrom(input.data()); 26 | auto gpu_output = cle::tier1::circular_shift_func(device, gpu_input, nullptr, 2, 2, 0); 27 | 28 | gpu_output->readTo(output.data()); 29 | for (int i = 0; i < output.size(); i++) 30 | { 31 | EXPECT_EQ(output[i], valid[i]); 32 | } 33 | } 34 | 35 | std::vector 36 | getParameters() 37 | { 38 | std::vector parameters; 39 | #if USE_OPENCL 40 | parameters.push_back("opencl"); 41 | #endif 42 | #if USE_CUDA 43 | parameters.push_back("cuda"); 44 | #endif 45 | return parameters; 46 | } 47 | 48 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestCircularShift, ::testing::ValuesIn(getParameters())); 49 | -------------------------------------------------------------------------------- /tests/tier1/test_copy.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestCopy : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input; 11 | std::array valid; 12 | 13 | virtual void 14 | SetUp() 15 | { 16 | std::fill(input.begin(), input.end(), static_cast(10)); 17 | std::fill(valid.begin(), valid.end(), static_cast(10)); 18 | } 19 | }; 20 | 21 | TEST_P(TestCopy, execute) 22 | { 23 | std::string param = GetParam(); 24 | cle::BackendManager::getInstance().setBackend(param); 25 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 26 | device->setWaitToFinish(true); 27 | 28 | auto gpu_input = cle::Array::create(10, 5, 3, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 29 | gpu_input->writeFrom(input.data()); 30 | 31 | auto gpu_output = cle::tier1::copy_func(device, gpu_input, nullptr); 32 | 33 | gpu_output->readTo(output.data()); 34 | for (int i = 0; i < output.size(); i++) 35 | { 36 | EXPECT_EQ(output[i], valid[i]); 37 | } 38 | } 39 | 40 | std::vector 41 | getParameters() 42 | { 43 | std::vector parameters; 44 | #if USE_OPENCL 45 | parameters.push_back("opencl"); 46 | #endif 47 | #if USE_CUDA 48 | parameters.push_back("cuda"); 49 | #endif 50 | return parameters; 51 | } 52 | 53 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestCopy, ::testing::ValuesIn(getParameters())); 54 | -------------------------------------------------------------------------------- /tests/tier1/test_crop.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class testCrop : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input; 11 | std::array valid; 12 | 13 | virtual void 14 | SetUp() 15 | { 16 | std::fill(input.begin(), input.end(), static_cast(10)); 17 | std::fill(valid.begin(), valid.end(), static_cast(10)); 18 | } 19 | }; 20 | 21 | TEST_P(testCrop, execute) 22 | { 23 | std::string param = GetParam(); 24 | cle::BackendManager::getInstance().setBackend(param); 25 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 26 | device->setWaitToFinish(true); 27 | 28 | auto gpu_input = cle::Array::create(10, 5, 3, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 29 | gpu_input->writeFrom(input.data()); 30 | 31 | auto gpu_output = cle::tier1::crop_func(device, gpu_input, nullptr, 0, 0, 1, 5, 5, 1); 32 | 33 | gpu_output->readTo(output.data()); 34 | for (int i = 0; i < output.size(); i++) 35 | { 36 | EXPECT_EQ(output[i], valid[i]); 37 | } 38 | } 39 | 40 | std::vector 41 | getParameters() 42 | { 43 | std::vector parameters; 44 | #if USE_OPENCL 45 | parameters.push_back("opencl"); 46 | #endif 47 | #if USE_CUDA 48 | parameters.push_back("cuda"); 49 | #endif 50 | return parameters; 51 | } 52 | 53 | INSTANTIATE_TEST_SUITE_P(InstantiationName, testCrop, ::testing::ValuesIn(getParameters())); 54 | -------------------------------------------------------------------------------- /tests/tier1/test_detect_label_edge.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestDetectLabelEdge : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 3, 2, 0, 3, 3, 3, 0, 0 }; 11 | std::array valid = { 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0 }; 12 | }; 13 | 14 | TEST_P(TestDetectLabelEdge, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(5, 5, 1, 3, cle::dType::UINT8, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | 24 | auto gpu_output = cle::tier1::detect_label_edges_func(device, gpu_input, nullptr); 25 | 26 | gpu_output->readTo(output.data()); 27 | for (int i = 0; i < output.size(); i++) 28 | { 29 | EXPECT_EQ(output[i], valid[i]); 30 | } 31 | } 32 | 33 | std::vector 34 | getParameters() 35 | { 36 | std::vector parameters; 37 | #if USE_OPENCL 38 | parameters.push_back("opencl"); 39 | #endif 40 | #if USE_CUDA 41 | parameters.push_back("cuda"); 42 | #endif 43 | return parameters; 44 | } 45 | 46 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestDetectLabelEdge, ::testing::ValuesIn(getParameters())); 47 | -------------------------------------------------------------------------------- /tests/tier1/test_flip.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class testFlip : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 1, 2, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0 }; 11 | std::array valid = { 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 2, 1, 0, 0, 0, 3, 1, 0, 0, 0, 0, 0, 0 }; 12 | }; 13 | 14 | TEST_P(testFlip, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(5, 5, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | 24 | auto gpu_output = cle::tier1::flip_func(device, gpu_input, nullptr, true, false, false); 25 | 26 | gpu_output->readTo(output.data()); 27 | for (int i = 0; i < output.size(); i++) 28 | { 29 | EXPECT_EQ(output[i], valid[i]); 30 | } 31 | } 32 | 33 | std::vector 34 | getParameters() 35 | { 36 | std::vector parameters; 37 | #if USE_OPENCL 38 | parameters.push_back("opencl"); 39 | #endif 40 | #if USE_CUDA 41 | parameters.push_back("cuda"); 42 | #endif 43 | return parameters; 44 | } 45 | 46 | INSTANTIATE_TEST_SUITE_P(InstantiationName, testFlip, ::testing::ValuesIn(getParameters())); 47 | -------------------------------------------------------------------------------- /tests/tier1/test_gradient_x.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestGradientX : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 0, 0, 0, 0, 1, 0, 0, 0, 0 }; 11 | std::array valid = { 0, 0, 0, -1, 0, 1, 0, 0, 0 }; 12 | }; 13 | 14 | TEST_P(TestGradientX, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(9, 1, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | 24 | auto gpu_output = cle::tier1::gradient_x_func(device, gpu_input, nullptr); 25 | 26 | gpu_output->readTo(output.data()); 27 | for (int i = 0; i < output.size(); i++) 28 | { 29 | EXPECT_EQ(output[i], valid[i]); 30 | } 31 | } 32 | 33 | std::vector 34 | getParameters() 35 | { 36 | std::vector parameters; 37 | #if USE_OPENCL 38 | parameters.push_back("opencl"); 39 | #endif 40 | #if USE_CUDA 41 | parameters.push_back("cuda"); 42 | #endif 43 | return parameters; 44 | } 45 | 46 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestGradientX, ::testing::ValuesIn(getParameters())); 47 | -------------------------------------------------------------------------------- /tests/tier1/test_gradient_y.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestGradientY : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 0, 0, 0, 0, 1, 0, 0, 0, 0 }; 11 | std::array valid = { 0, -1, 0, 0, 0, 0, 0, 1, 0 }; 12 | }; 13 | 14 | TEST_P(TestGradientY, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(3, 3, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | 24 | auto gpu_output = cle::tier1::gradient_y_func(device, gpu_input, nullptr); 25 | 26 | gpu_output->readTo(output.data()); 27 | for (int i = 0; i < output.size(); i++) 28 | { 29 | EXPECT_EQ(output[i], valid[i]); 30 | } 31 | } 32 | 33 | std::vector 34 | getParameters() 35 | { 36 | std::vector parameters; 37 | #if USE_OPENCL 38 | parameters.push_back("opencl"); 39 | #endif 40 | #if USE_CUDA 41 | parameters.push_back("cuda"); 42 | #endif 43 | return parameters; 44 | } 45 | 46 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestGradientY, ::testing::ValuesIn(getParameters())); 47 | -------------------------------------------------------------------------------- /tests/tier1/test_gradient_z.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestGradientZ : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 11 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 12 | }; 13 | std::array valid = { 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; 15 | }; 16 | 17 | TEST_P(TestGradientZ, execute) 18 | { 19 | std::string param = GetParam(); 20 | cle::BackendManager::getInstance().setBackend(param); 21 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 22 | device->setWaitToFinish(true); 23 | 24 | auto gpu_input = cle::Array::create(3, 3, 3, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 25 | gpu_input->writeFrom(input.data()); 26 | 27 | auto gpu_output = cle::tier1::gradient_z_func(device, gpu_input, nullptr); 28 | 29 | gpu_output->readTo(output.data()); 30 | for (int i = 0; i < output.size(); i++) 31 | { 32 | EXPECT_EQ(output[i], valid[i]); 33 | } 34 | } 35 | 36 | std::vector 37 | getParameters() 38 | { 39 | std::vector parameters; 40 | #if USE_OPENCL 41 | parameters.push_back("opencl"); 42 | #endif 43 | #if USE_CUDA 44 | parameters.push_back("cuda"); 45 | #endif 46 | return parameters; 47 | } 48 | 49 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestGradientZ, ::testing::ValuesIn(getParameters())); 50 | -------------------------------------------------------------------------------- /tests/tier1/test_set.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestSet : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input; 11 | std::array valid; 12 | 13 | virtual void 14 | SetUp() 15 | { 16 | std::fill(input.begin(), input.end(), static_cast(5.0F)); 17 | std::fill(valid.begin(), valid.end(), static_cast(10.0F)); 18 | } 19 | }; 20 | 21 | TEST_P(TestSet, execute) 22 | { 23 | std::string param = GetParam(); 24 | cle::BackendManager::getInstance().setBackend(param); 25 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 26 | device->setWaitToFinish(true); 27 | 28 | auto gpu_input = cle::Array::create(10, 5, 3, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 29 | gpu_input->writeFrom(input.data()); 30 | 31 | auto gpu_output = cle::tier1::set_func(device, gpu_input, 10); 32 | 33 | gpu_output->readTo(output.data()); 34 | for (int i = 0; i < output.size(); i++) 35 | { 36 | EXPECT_EQ(output[i], valid[i]); 37 | } 38 | } 39 | 40 | std::vector 41 | getParameters() 42 | { 43 | std::vector parameters; 44 | #if USE_OPENCL 45 | parameters.push_back("opencl"); 46 | #endif 47 | #if USE_CUDA 48 | parameters.push_back("cuda"); 49 | #endif 50 | return parameters; 51 | } 52 | 53 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestSet, ::testing::ValuesIn(getParameters())); 54 | -------------------------------------------------------------------------------- /tests/tier1/test_set_image_border.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestPaste : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; 11 | std::array valid = { 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 4, 3, 3, 3, 4, 4, 3, 3, 3, 4, 4, 4, 4, 4, 4 }; 12 | }; 13 | 14 | TEST_P(TestPaste, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(5, 5, 1, 3, cle::dType::INT16, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | 24 | cle::tier1::set_image_borders_func(device, gpu_input, 4); 25 | 26 | gpu_input->readTo(output.data()); 27 | for (int i = 0; i < output.size(); i++) 28 | { 29 | EXPECT_EQ(output[i], valid[i]); 30 | } 31 | } 32 | 33 | std::vector 34 | getParameters() 35 | { 36 | std::vector parameters; 37 | #if USE_OPENCL 38 | parameters.push_back("opencl"); 39 | #endif 40 | #if USE_CUDA 41 | parameters.push_back("cuda"); 42 | #endif 43 | return parameters; 44 | } 45 | 46 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestPaste, ::testing::ValuesIn(getParameters())); 47 | -------------------------------------------------------------------------------- /tests/tier1/test_sum_reduction_x.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestSumReductionX : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0 }; 11 | std::array valid = { 2.0, 2.0, 1.0 }; 12 | }; 13 | 14 | TEST_P(TestSumReductionX, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(12, 1, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | 24 | auto gpu_output = cle::tier1::sum_reduction_x_func(device, gpu_input, nullptr, 4); 25 | 26 | gpu_output->readTo(output.data()); 27 | for (int i = 0; i < output.size(); i++) 28 | { 29 | EXPECT_EQ(output[i], valid[i]); 30 | } 31 | } 32 | 33 | std::vector 34 | getParameters() 35 | { 36 | std::vector parameters; 37 | #if USE_OPENCL 38 | parameters.push_back("opencl"); 39 | #endif 40 | #if USE_CUDA 41 | parameters.push_back("cuda"); 42 | #endif 43 | return parameters; 44 | } 45 | 46 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestSumReductionX, ::testing::ValuesIn(getParameters())); 47 | -------------------------------------------------------------------------------- /tests/tier1/test_sum_x_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestSumProjectionX : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input; 11 | std::array valid; 12 | 13 | virtual void 14 | SetUp() 15 | { 16 | std::fill(input.begin(), input.end(), static_cast(1)); 17 | std::fill(valid.begin(), valid.end(), static_cast(10)); 18 | } 19 | }; 20 | 21 | TEST_P(TestSumProjectionX, execute) 22 | { 23 | std::string param = GetParam(); 24 | cle::BackendManager::getInstance().setBackend(param); 25 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 26 | device->setWaitToFinish(true); 27 | 28 | auto gpu_input = cle::Array::create(10, 5, 3, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 29 | gpu_input->writeFrom(input.data()); 30 | 31 | auto gpu_output = cle::tier1::sum_x_projection_func(device, gpu_input, nullptr); 32 | 33 | gpu_output->readTo(output.data()); 34 | for (int i = 0; i < output.size(); i++) 35 | { 36 | EXPECT_EQ(output[i], valid[i]); 37 | } 38 | } 39 | 40 | std::vector 41 | getParameters() 42 | { 43 | std::vector parameters; 44 | #if USE_OPENCL 45 | parameters.push_back("opencl"); 46 | #endif 47 | #if USE_CUDA 48 | parameters.push_back("cuda"); 49 | #endif 50 | return parameters; 51 | } 52 | 53 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestSumProjectionX, ::testing::ValuesIn(getParameters())); 54 | -------------------------------------------------------------------------------- /tests/tier1/test_sum_y_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestSumProjectionY : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input; 11 | std::array valid; 12 | 13 | virtual void 14 | SetUp() 15 | { 16 | std::fill(input.begin(), input.end(), static_cast(1)); 17 | std::fill(valid.begin(), valid.end(), static_cast(5)); 18 | } 19 | }; 20 | 21 | TEST_P(TestSumProjectionY, execute) 22 | { 23 | std::string param = GetParam(); 24 | cle::BackendManager::getInstance().setBackend(param); 25 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 26 | device->setWaitToFinish(true); 27 | 28 | auto gpu_input = cle::Array::create(10, 5, 3, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 29 | gpu_input->writeFrom(input.data()); 30 | 31 | auto gpu_output = cle::tier1::sum_y_projection_func(device, gpu_input, nullptr); 32 | 33 | gpu_output->readTo(output.data()); 34 | for (int i = 0; i < output.size(); i++) 35 | { 36 | EXPECT_EQ(output[i], valid[i]); 37 | } 38 | } 39 | 40 | std::vector 41 | getParameters() 42 | { 43 | std::vector parameters; 44 | #if USE_OPENCL 45 | parameters.push_back("opencl"); 46 | #endif 47 | #if USE_CUDA 48 | parameters.push_back("cuda"); 49 | #endif 50 | return parameters; 51 | } 52 | 53 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestSumProjectionY, ::testing::ValuesIn(getParameters())); 54 | -------------------------------------------------------------------------------- /tests/tier1/test_sum_z_projection.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestSumProjectionZ : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input; 11 | std::array valid; 12 | 13 | virtual void 14 | SetUp() 15 | { 16 | std::fill(input.begin(), input.end(), static_cast(1)); 17 | std::fill(valid.begin(), valid.end(), static_cast(3)); 18 | } 19 | }; 20 | 21 | TEST_P(TestSumProjectionZ, execute) 22 | { 23 | std::string param = GetParam(); 24 | cle::BackendManager::getInstance().setBackend(param); 25 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 26 | device->setWaitToFinish(true); 27 | 28 | auto gpu_input = cle::Array::create(10, 5, 3, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 29 | gpu_input->writeFrom(input.data()); 30 | 31 | auto gpu_output = cle::tier1::sum_z_projection_func(device, gpu_input, nullptr); 32 | 33 | gpu_output->readTo(output.data()); 34 | for (int i = 0; i < output.size(); i++) 35 | { 36 | EXPECT_EQ(output[i], valid[i]); 37 | } 38 | } 39 | 40 | std::vector 41 | getParameters() 42 | { 43 | std::vector parameters; 44 | #if USE_OPENCL 45 | parameters.push_back("opencl"); 46 | #endif 47 | #if USE_CUDA 48 | parameters.push_back("cuda"); 49 | #endif 50 | return parameters; 51 | } 52 | 53 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestSumProjectionZ, ::testing::ValuesIn(getParameters())); 54 | -------------------------------------------------------------------------------- /tests/tier2/test_absolute_difference.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestAbsoluteDifference : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input1 = { 1, 5, 3 }; 11 | std::array input2 = { 4, 2, 7 }; 12 | std::array valid = { 3, 3, 4 }; 13 | }; 14 | 15 | TEST_P(TestAbsoluteDifference, execute) 16 | { 17 | std::string param = GetParam(); 18 | cle::BackendManager::getInstance().setBackend(param); 19 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 20 | device->setWaitToFinish(true); 21 | 22 | auto gpu_input1 = cle::Array::create(3, 1, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 23 | auto gpu_input2 = cle::Array::create(gpu_input1); 24 | gpu_input1->writeFrom(input1.data()); 25 | gpu_input2->writeFrom(input2.data()); 26 | auto gpu_output = cle::tier2::absolute_difference_func(device, gpu_input1, gpu_input2, nullptr); 27 | 28 | gpu_output->readTo(output.data()); 29 | for (int i = 0; i < output.size(); i++) 30 | { 31 | EXPECT_EQ(output[i], valid[i]); 32 | } 33 | } 34 | 35 | std::vector 36 | getParameters() 37 | { 38 | std::vector parameters; 39 | #if USE_OPENCL 40 | parameters.push_back("opencl"); 41 | #endif 42 | #if USE_CUDA 43 | parameters.push_back("cuda"); 44 | #endif 45 | return parameters; 46 | } 47 | 48 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestAbsoluteDifference, ::testing::ValuesIn(getParameters())); 49 | -------------------------------------------------------------------------------- /tests/tier2/test_clip.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestClip : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 0, 1, 2, 3 }; 11 | }; 12 | 13 | TEST_P(TestClip, executeMinMax) 14 | { 15 | std::array valid = { 1, 1, 2, 2 }; 16 | 17 | std::string param = GetParam(); 18 | cle::BackendManager::getInstance().setBackend(param); 19 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 20 | device->setWaitToFinish(true); 21 | 22 | auto gpu_input = cle::Array::create(2, 2, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 23 | gpu_input->writeFrom(input.data()); 24 | 25 | auto gpu_output = cle::tier2::clip_func(device, gpu_input, nullptr, 1, 2); 26 | 27 | gpu_output->readTo(output.data()); 28 | for (int i = 0; i < output.size(); i++) 29 | { 30 | EXPECT_EQ(output[i], valid[i]); 31 | } 32 | } 33 | 34 | std::vector 35 | getParameters() 36 | { 37 | std::vector parameters; 38 | #if USE_OPENCL 39 | parameters.push_back("opencl"); 40 | #endif 41 | #if USE_CUDA 42 | parameters.push_back("cuda"); 43 | #endif 44 | return parameters; 45 | } 46 | 47 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestClip, ::testing::ValuesIn(getParameters())); 48 | -------------------------------------------------------------------------------- /tests/tier2/test_deg_to_rad.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestDegreeToRadiant : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 180, 0, -90 }; 11 | std::array valid = { M_PI, 0, -0.5 * M_PI }; 12 | }; 13 | 14 | TEST_P(TestDegreeToRadiant, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(3, 1, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | auto gpu_output = cle::tier2::degrees_to_radians_func(device, gpu_input, nullptr); 24 | 25 | gpu_output->readTo(output.data()); 26 | for (int i = 0; i < output.size(); i++) 27 | { 28 | EXPECT_EQ(output[i], valid[i]); 29 | } 30 | } 31 | 32 | std::vector 33 | getParameters() 34 | { 35 | std::vector parameters; 36 | #if USE_OPENCL 37 | parameters.push_back("opencl"); 38 | #endif 39 | #if USE_CUDA 40 | parameters.push_back("cuda"); 41 | #endif 42 | return parameters; 43 | } 44 | 45 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestDegreeToRadiant, ::testing::ValuesIn(getParameters())); 46 | -------------------------------------------------------------------------------- /tests/tier2/test_invert.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestInvert : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array output; 10 | std::array input = { 1, -5, 3 }; 11 | std::array valid = { -1, 5, -3 }; 12 | }; 13 | 14 | TEST_P(TestInvert, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(3, 1, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | auto gpu_output = cle::tier2::invert_func(device, gpu_input, nullptr); 24 | 25 | gpu_output->readTo(output.data()); 26 | for (int i = 0; i < output.size(); i++) 27 | { 28 | EXPECT_EQ(output[i], valid[i]); 29 | } 30 | } 31 | 32 | std::vector 33 | getParameters() 34 | { 35 | std::vector parameters; 36 | #if USE_OPENCL 37 | parameters.push_back("opencl"); 38 | #endif 39 | #if USE_CUDA 40 | parameters.push_back("cuda"); 41 | #endif 42 | return parameters; 43 | } 44 | 45 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestInvert, ::testing::ValuesIn(getParameters())); 46 | -------------------------------------------------------------------------------- /tests/tier2/test_maximum_all_pixels.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "cle.hpp" 3 | 4 | #include 5 | #include 6 | 7 | class TestMaxAllPixel : public ::testing::TestWithParam 8 | { 9 | protected: 10 | const float max = 100; 11 | const float min = 42; 12 | std::array input; 13 | 14 | virtual void 15 | SetUp() 16 | { 17 | std::fill(input.begin(), input.end(), min); 18 | const int center = (10 / 2) + (20 / 2) * 10 + (30 / 2) * 10 * 20; 19 | input[center] = max; 20 | } 21 | }; 22 | 23 | TEST_P(TestMaxAllPixel, execute) 24 | { 25 | std::string param = GetParam(); 26 | cle::BackendManager::getInstance().setBackend(param); 27 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 28 | device->setWaitToFinish(true); 29 | 30 | auto array = cle::Array::create(10, 20, 30, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 31 | array->writeFrom(input.data()); 32 | 33 | auto output = cle::tier2::maximum_of_all_pixels_func(device, array); 34 | 35 | EXPECT_EQ(output, max); 36 | } 37 | 38 | std::vector 39 | getParameters() 40 | { 41 | std::vector parameters; 42 | #if USE_OPENCL 43 | parameters.push_back("opencl"); 44 | #endif 45 | #if USE_CUDA 46 | parameters.push_back("cuda"); 47 | #endif 48 | return parameters; 49 | } 50 | 51 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestMaxAllPixel, ::testing::ValuesIn(getParameters())); 52 | -------------------------------------------------------------------------------- /tests/tier2/test_minimum_all_pixels.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "cle.hpp" 3 | 4 | #include 5 | #include 6 | 7 | class TestMinAllPixel : public ::testing::TestWithParam 8 | { 9 | protected: 10 | const float max = 100; 11 | const float min = 42; 12 | std::array input; 13 | 14 | virtual void 15 | SetUp() 16 | { 17 | std::fill(input.begin(), input.end(), max); 18 | const int center = (10 / 2) + (20 / 2) * 10 + (30 / 2) * 10 * 20; 19 | input[center] = min; 20 | } 21 | }; 22 | 23 | TEST_P(TestMinAllPixel, execute) 24 | { 25 | std::string param = GetParam(); 26 | cle::BackendManager::getInstance().setBackend(param); 27 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 28 | device->setWaitToFinish(true); 29 | 30 | auto array = cle::Array::create(10, 20, 30, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 31 | array->writeFrom(input.data()); 32 | 33 | auto output = cle::tier2::minimum_of_all_pixels_func(device, array); 34 | 35 | EXPECT_EQ(output, min); 36 | } 37 | 38 | std::vector 39 | getParameters() 40 | { 41 | std::vector parameters; 42 | #if USE_OPENCL 43 | parameters.push_back("opencl"); 44 | #endif 45 | #if USE_CUDA 46 | parameters.push_back("cuda"); 47 | #endif 48 | return parameters; 49 | } 50 | 51 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestMinAllPixel, ::testing::ValuesIn(getParameters())); 52 | -------------------------------------------------------------------------------- /tests/tier2/test_minimum_of_masked_pixels.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "cle.hpp" 3 | 4 | #include 5 | #include 6 | 7 | class TestMinMaskPixel : public ::testing::TestWithParam 8 | { 9 | protected: 10 | std::array input; 11 | std::array mask; 12 | float valid = 3; 13 | 14 | virtual void 15 | SetUp() 16 | { 17 | for (size_t i = 0; i < input.size(); i++) 18 | { 19 | input[i] = 100; 20 | mask[i] = (i % 2 == 0) ? 1 : 0; 21 | } 22 | input[2] = 3; 23 | } 24 | }; 25 | 26 | TEST_P(TestMinMaskPixel, execute) 27 | { 28 | std::string param = GetParam(); 29 | cle::BackendManager::getInstance().setBackend(param); 30 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 31 | device->setWaitToFinish(true); 32 | 33 | auto gpu_input = cle::Array::create(5, 3, 2, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 34 | auto gpu_mask = cle::Array::create(gpu_input); 35 | gpu_input->writeFrom(input.data()); 36 | gpu_mask->writeFrom(mask.data()); 37 | 38 | auto output = cle::tier2::minimum_of_masked_pixels_func(device, gpu_input, gpu_mask); 39 | 40 | EXPECT_EQ(output, valid); 41 | } 42 | 43 | std::vector 44 | getParameters() 45 | { 46 | std::vector parameters; 47 | #if USE_OPENCL 48 | parameters.push_back("opencl"); 49 | #endif 50 | #if USE_CUDA 51 | parameters.push_back("cuda"); 52 | #endif 53 | return parameters; 54 | } 55 | 56 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestMinMaskPixel, ::testing::ValuesIn(getParameters())); 57 | -------------------------------------------------------------------------------- /tests/tier2/test_sum_all_pixels.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class TestSumAllPixel : public ::testing::TestWithParam 8 | { 9 | protected: 10 | std::array input; 11 | float valid; 12 | 13 | virtual void 14 | SetUp() 15 | { 16 | std::fill(input.begin(), input.end(), 1.0f); 17 | valid = std::accumulate(input.begin(), input.end(), 0.0f); 18 | } 19 | }; 20 | 21 | TEST_P(TestSumAllPixel, execute) 22 | { 23 | std::string param = GetParam(); 24 | cle::BackendManager::getInstance().setBackend(param); 25 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 26 | device->setWaitToFinish(true); 27 | 28 | auto array = cle::Array::create(10, 20, 30, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 29 | array->writeFrom(input.data()); 30 | 31 | auto output = cle::tier2::sum_of_all_pixels_func(device, array); 32 | 33 | EXPECT_EQ(output, 10 * 20 * 30); 34 | } 35 | 36 | std::vector 37 | getParameters() 38 | { 39 | std::vector parameters; 40 | #if USE_OPENCL 41 | parameters.push_back("opencl"); 42 | #endif 43 | #if USE_CUDA 44 | parameters.push_back("cuda"); 45 | #endif 46 | return parameters; 47 | } 48 | 49 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestSumAllPixel, ::testing::ValuesIn(getParameters())); 50 | -------------------------------------------------------------------------------- /tests/tier3/test_gamma_correction.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include "cle.hpp" 5 | 6 | #include 7 | #include 8 | 9 | class TestExistingLabels : public ::testing::TestWithParam 10 | { 11 | protected: 12 | std::array input = { 13 | 0, 0, 0, 0, 0, 0, 50, 0, 5, 0, 0, 0, 100, 0, 0, 0, 30, 0, 10, 0, 0, 0, 0, 0, 0 14 | }; 15 | std::array output; 16 | }; 17 | 18 | TEST_P(TestExistingLabels, execute) 19 | { 20 | std::string param = GetParam(); 21 | cle::BackendManager::getInstance().setBackend(param); 22 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 23 | device->setWaitToFinish(true); 24 | 25 | auto gpu_input = cle::Array::create(5, 5, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 26 | gpu_input->writeFrom(input.data()); 27 | 28 | auto gpu_output = cle::tier3::gamma_correction_func(device, gpu_input, nullptr, 0.5); 29 | 30 | gpu_output->readTo(output.data()); 31 | // assert (np.abs(np.mean(a) - 11.1786) < 0.001) 32 | EXPECT_LT(std::abs(*std::min_element(output.begin(), output.end())), 0.001); 33 | EXPECT_LT(std::abs(*std::max_element(output.begin(), output.end())) - 100, 0.001); 34 | } 35 | 36 | std::vector 37 | getParameters() 38 | { 39 | std::vector parameters; 40 | #if USE_OPENCL 41 | parameters.push_back("opencl"); 42 | #endif 43 | #if USE_CUDA 44 | parameters.push_back("cuda"); 45 | #endif 46 | return parameters; 47 | } 48 | 49 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestExistingLabels, ::testing::ValuesIn(getParameters())); 50 | -------------------------------------------------------------------------------- /tests/tier3/test_generate_touch_mat.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestGenerateTouchMatrix : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array input = { 1, 1, 0, 0, 0, 1, 1, 0, 3, 0, 0, 2, 2, 3, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 4 }; 10 | std::array valid = { 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0 }; 11 | std::array output; 12 | }; 13 | 14 | TEST_P(TestGenerateTouchMatrix, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(5, 5, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | 24 | auto gpu_output = cle::tier3::generate_touch_matrix_func(device, gpu_input, nullptr); 25 | 26 | gpu_output->readTo(output.data()); 27 | for (int i = 0; i < output.size(); i++) 28 | { 29 | EXPECT_EQ(output[i], valid[i]); 30 | } 31 | } 32 | 33 | std::vector 34 | getParameters() 35 | { 36 | std::vector parameters; 37 | #if USE_OPENCL 38 | parameters.push_back("opencl"); 39 | #endif 40 | #if USE_CUDA 41 | parameters.push_back("cuda"); 42 | #endif 43 | return parameters; 44 | } 45 | 46 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestGenerateTouchMatrix, ::testing::ValuesIn(getParameters())); 47 | -------------------------------------------------------------------------------- /tests/tier3/test_label_spot_to_pointlist.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestLabelSpotToPointList : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array input = { 0, 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 4 }; 10 | std::array valid = { 1, 2, 3, 4, 1, 3, 1, 4 }; 11 | std::array output; 12 | }; 13 | 14 | TEST_P(TestLabelSpotToPointList, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(5, 5, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | 24 | auto gpu_output = cle::tier3::labelled_spots_to_pointlist_func(device, gpu_input, nullptr); 25 | 26 | gpu_output->readTo(output.data()); 27 | for (int i = 0; i < output.size(); i++) 28 | { 29 | EXPECT_EQ(output[i], valid[i]); 30 | } 31 | } 32 | 33 | std::vector 34 | getParameters() 35 | { 36 | std::vector parameters; 37 | #if USE_OPENCL 38 | parameters.push_back("opencl"); 39 | #endif 40 | #if USE_CUDA 41 | parameters.push_back("cuda"); 42 | #endif 43 | return parameters; 44 | } 45 | 46 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestLabelSpotToPointList, ::testing::ValuesIn(getParameters())); 47 | -------------------------------------------------------------------------------- /tests/tier4/test_label_bounding_box.cpp: -------------------------------------------------------------------------------- 1 | #include "cle.hpp" 2 | 3 | #include 4 | #include 5 | 6 | class TestBoundingBox : public ::testing::TestWithParam 7 | { 8 | protected: 9 | std::array input = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 10 | 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0 }; 11 | }; 12 | 13 | TEST_P(TestBoundingBox, execute2d) 14 | { 15 | 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input = cle::Array::create(7, 7, 1, 2, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | gpu_input->writeFrom(input.data()); 23 | 24 | auto output = cle::tier4::label_bounding_box_func(device, gpu_input, 2); 25 | 26 | std::vector valid = { 4, 4, 0, 5, 5, 0 }; 27 | for (int i = 0; i < output.size(); i++) 28 | { 29 | EXPECT_EQ(output[i], valid[i]); 30 | } 31 | } 32 | 33 | 34 | std::vector 35 | getParameters() 36 | { 37 | std::vector parameters; 38 | #if USE_OPENCL 39 | parameters.push_back("opencl"); 40 | #endif 41 | #if USE_CUDA 42 | parameters.push_back("cuda"); 43 | #endif 44 | return parameters; 45 | } 46 | 47 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestBoundingBox, ::testing::ValuesIn(getParameters())); 48 | -------------------------------------------------------------------------------- /tests/tier4/test_mean_square_error.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "cle.hpp" 3 | 4 | #include 5 | #include 6 | 7 | class TestMeanSquareError : public ::testing::TestWithParam 8 | { 9 | protected: 10 | const std::array input1 = { 1, 2, 3 }; 11 | const std::array input2 = { 4, 5, 7 }; 12 | }; 13 | 14 | TEST_P(TestMeanSquareError, execute) 15 | { 16 | std::string param = GetParam(); 17 | cle::BackendManager::getInstance().setBackend(param); 18 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 19 | device->setWaitToFinish(true); 20 | 21 | auto gpu_input1 = cle::Array::create(3, 1, 1, 3, cle::dType::FLOAT, cle::mType::BUFFER, device); 22 | auto gpu_input2 = cle::Array::create(gpu_input1); 23 | gpu_input1->writeFrom(input1.data()); 24 | gpu_input2->writeFrom(input2.data()); 25 | 26 | auto output = cle::tier4::mean_squared_error_func(device, gpu_input1, gpu_input2); 27 | EXPECT_NEAR(output, 11.333, 0.001); 28 | } 29 | 30 | std::vector 31 | getParameters() 32 | { 33 | std::vector parameters; 34 | #if USE_OPENCL 35 | parameters.push_back("opencl"); 36 | #endif 37 | #if USE_CUDA 38 | parameters.push_back("cuda"); 39 | #endif 40 | return parameters; 41 | } 42 | 43 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestMeanSquareError, ::testing::ValuesIn(getParameters())); 44 | -------------------------------------------------------------------------------- /tests/tier4/test_spots_to_pointlist.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "cle.hpp" 3 | 4 | #include 5 | #include 6 | 7 | class TestSpotToPointList : public ::testing::TestWithParam 8 | { 9 | protected: 10 | std::array input = { 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 }; 11 | std::array valid = { 1, 3, 2, 4, 1, 1, 3, 4 }; 12 | std::array output; 13 | }; 14 | 15 | TEST_P(TestSpotToPointList, execute) 16 | { 17 | std::string param = GetParam(); 18 | cle::BackendManager::getInstance().setBackend(param); 19 | auto device = cle::BackendManager::getInstance().getBackend().getDevice("", "gpu"); 20 | device->setWaitToFinish(true); 21 | 22 | auto gpu_input = cle::Array::create(5, 5, 1, 2, cle::dType::FLOAT, cle::mType::BUFFER, device); 23 | gpu_input->writeFrom(input.data()); 24 | 25 | auto gpu_output = cle::tier4::spots_to_pointlist_func(device, gpu_input, nullptr); 26 | 27 | gpu_output->readTo(output.data()); 28 | for (int i = 0; i < output.size(); i++) 29 | { 30 | EXPECT_EQ(output[i], valid[i]); 31 | } 32 | } 33 | 34 | std::vector 35 | getParameters() 36 | { 37 | std::vector parameters; 38 | #if USE_OPENCL 39 | parameters.push_back("opencl"); 40 | #endif 41 | #if USE_CUDA 42 | parameters.push_back("cuda"); 43 | #endif 44 | return parameters; 45 | } 46 | 47 | INSTANTIATE_TEST_SUITE_P(InstantiationName, TestSpotToPointList, ::testing::ValuesIn(getParameters())); 48 | --------------------------------------------------------------------------------