Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into deploy-to-scijava
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 17, 2024
2 parents f5a6a0c + f40abd4 commit be4cca8
Show file tree
Hide file tree
Showing 50 changed files with 2,027 additions and 3,506 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ clesperantoJ is a Java bidings of the C++ library [CLIc]() relying of [OpenCL]()
A certain diversity of ressources will be required to build clesperantoJ from source:
- a C++ compiler (`gcc`, `clang`, `cl`, etc.)
- the Java Development Kit (JDK)
- CMake (a C++ project manager)
- Maven (a Java project manager)
- [CMake](https://cmake.org/) (a C++ project manager)
- [Maven](https://maven.apache.org/download.cgi) (a Java project manager)
- Bash (a shell program and command language)
- OpenCL (your GPU driver properly install with their Development Kit if possible)

#### Install a C++ compiler and CMake

For __windows__, you can install [Microsoft Build tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) (or [Visual Studio Community edition](https://visualstudio.microsoft.com/vs/community/) with Windows C++ development selected). A more detail tutorial can be found [here](https://biapol.github.io/blog/robert_haase/ms_build_tools/readme.html).
For __windows__, you can install [Microsoft Build tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) (or [Visual Studio Community edition](https://visualstudio.microsoft.com/vs/community/) with "Desktop development with C++" selected). A more detail tutorial can be found [here](https://biapol.github.io/blog/robert_haase/ms_build_tools/readme.html).
For __MacOS__, you will need to install the command-line tools from xcode by running this command in a prompt: `xcode-select --install`.
For __Unix__, similarly to OSX, you will need to install the `build-essential` package by running this command in a prompt: `sudo apt install build-essential`.

Expand All @@ -47,11 +47,20 @@ You can get Bash by simply installing [git-scm](https://git-scm.com/downloads) a
### Install OpenCL

You mainly need to install your GPU driver provided by your GPU vendor, e.g. NVIDIA, AMD, Intel, etc. Please refer to their official website.
For NVIDIA, we advise to install the CUDAToolKit.
For NVIDIA, we advise to install the [CUDAToolKit](https://developer.nvidia.com/cuda-toolkit).

## PATH

To make the above installed programs work, you need to add them to your path, e.g. on Windows like this:
```
C:\programs\apache-maven-3.9.9\bin
C:\Program Files\Git\bin
C:\Program Files\CMake\bin
```

### Build clesperantoJ

In a commmand prompt, start by git clone the repository and move inside the repo
In a commmand prompt (on Windows "x64 Native Tools Command Prompt"), start by git clone the repository and move inside the repo
```
git clone https://github.com/clEsperanto/clesperantoj_prototype.git
cd clesperantoj_prototype
Expand Down
9 changes: 8 additions & 1 deletion native/clesperantoj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Require (at least) it
set(CMAKE_CXX_EXTENSIONS OFF) # Don't use e.g. GNU extension (like -std=gnu++11) for portability
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # Export all symbols for shared library windows


# Fetch CLIC_REPO_TAG from the pom.xml file
set(POM_FILE_PATH "${CMAKE_SOURCE_DIR}/../../pom.xml")
file(READ ${POM_FILE_PATH} POM_CONTENTS)
string(REGEX MATCH "<clic.version>([0-9]+\\.[0-9]+\\.[0-9]+)</clic.version>" _match ${POM_CONTENTS})
string(REGEX REPLACE ".*<clic.version>([0-9]+\\.[0-9]+\\.[0-9]+)</clic.version>.*" "\\1" CLIC_REPO_TAG ${_match})

## CLIc dependency
option(BUILD_TESTING OFF)
option(BUILD_BENCHMARK OFF)
option(BUILD_SHARED_LIBS ON)
set(CLIC_REPO_TAG 0.12.1) # branch name for dev
# set(CLIC_REPO_TAG 0.13.4)
set(CLIC_REPO_URL https://github.com/clEsperanto/CLIc_prototype.git)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/clic)

Expand Down
4 changes: 2 additions & 2 deletions native/clesperantoj/cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ case $PLATFORM in
# -DCMAKE_CUDA_HOST_COMPILER="/usr/bin/g++" \
# -DOPENCL_INCLUDE_DIR="/usr/local/cuda/include/" \
# -DCLFFT_LIBRARY_DIR="/opt/OpenCL/clFFT-2.12.2-Linux-x64/lib64/" ..
make -j
make -j$(nproc)
make install
;;
macosx-*)
Expand All @@ -30,7 +30,7 @@ case $PLATFORM in
# -DCMAKE_CXX_COMPILER="g++" \
# -DCMAKE_CUDA_HOST_COMPILER="g++" \
# -DCLFFT_LIBRARY_DIR="/Users/haase/Downloads/clfft-2.12.2-h83d4a3d_1/lib" ..
make -j
make -j$(sysctl -n hw.ncpu)
make install
;;
windows-x86_64)
Expand Down
73 changes: 43 additions & 30 deletions native/clesperantoj/include/clesperantoj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DeviceJ

public:
DeviceJ();
DeviceJ(const std::shared_ptr<cle::Device> &device);

static std::vector<std::string> getAvailableDevices(const std::string &deviceType = "all");

Expand All @@ -33,7 +34,33 @@ class DeviceJ
std::string getInfo() const;

std::shared_ptr<cle::Device> get() const;

bool operator==(const DeviceJ& other) const;
};

enum class DTypeJ
{
INT8,
UINT8,
INT16,
UINT16,
INT32,
UINT32,
FLOAT,
UNKNOWN,

INT = INT32,
INDEX = UINT32,
LABEL = UINT32,
BINARY = UINT8,
};

enum class MTypeJ
{
BUFFER,
IMAGE
};

class ArrayJ
{

Expand All @@ -43,9 +70,8 @@ class ArrayJ
friend class MemoryJ;

protected:
static ArrayJ create(size_t width, size_t height, size_t depth, size_t dimension, const cle::dType &data_type, const cle::mType &memory_type, const DeviceJ &device);
void writeFrom(void *data, std::array<size_t, 3> &region, std::array<size_t, 3> &origin) const;
void readTo(void *data, std::array<size_t, 3> &region, std::array<size_t, 3> &origin) const;
void writeFrom( void *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth) const;
void readTo( void *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth) const;

public:
ArrayJ() = default;
Expand All @@ -56,42 +82,29 @@ class ArrayJ
size_t getDepth() const;
unsigned int getDimension() const;

std::string getDataType() const;
std::string getMemoryType() const;
std::string getDevice() const;

void fillMemory(float value);
void copyDataTo(ArrayJ &dst);

std::shared_ptr<cle::Array> get() const;

static ArrayJ create( const size_t &width, const size_t &height, const size_t &depth, const size_t &dimension, const DTypeJ &data_type, const MTypeJ &memory_type, const DeviceJ &device);
DTypeJ dtype() const;
MTypeJ mtype() const;
DeviceJ device() const;
};

class MemoryJ
{
public:
static ArrayJ makeFloatBuffer(const DeviceJ &device, const size_t &width, const size_t &height, const size_t &depth, const size_t &dimension, const std::string &memory_type);
static ArrayJ makeByteBuffer(const DeviceJ &device, const size_t &width, const size_t &height, const size_t &depth, const size_t &dimension, const std::string &memory_type);
static ArrayJ makeUByteBuffer(const DeviceJ &device, const size_t &width, const size_t &height, const size_t &depth, const size_t &dimension, const std::string &memory_type);
static ArrayJ makeShortBuffer(const DeviceJ &device, const size_t &width, const size_t &height, const size_t &depth, const size_t &dimension, const std::string &memory_type);
static ArrayJ makeUShortBuffer(const DeviceJ &device, const size_t &width, const size_t &height, const size_t &depth, const size_t &dimension, const std::string &memory_type);
static ArrayJ makeIntBuffer(const DeviceJ &device, const size_t &width, const size_t &height, const size_t &depth, const size_t &dimension, const std::string &memory_type);
static ArrayJ makeUIntBuffer(const DeviceJ &device, const size_t &width, const size_t &height, const size_t &depth, const size_t &dimension, const std::string &memory_type);

static void writeFloatBuffer(const ArrayJ &array, float *data, const size_t &size);
static void writeByteBuffer(const ArrayJ &array, char *data, const size_t &size);
static void writeUByteBuffer(const ArrayJ &array, unsigned char *data, const size_t &size);
static void writeShortBuffer(const ArrayJ &array, short *data, const size_t &size);
static void writeUShortBuffer(const ArrayJ &array, unsigned short *data, const size_t &size);
static void writeIntBuffer(const ArrayJ &array, int *data, const size_t &size);
static void writeUIntBuffer(const ArrayJ &array, unsigned int *data, const size_t &size);

static void readFloatBuffer(const ArrayJ &array, float *data, const size_t &size);
static void readByteBuffer(const ArrayJ &array, char *data, const size_t &size);
static void readUByteBuffer(const ArrayJ &array, unsigned char *data, const size_t &size);
static void readShortBuffer(const ArrayJ &array, short *data, const size_t &size);
static void readUShortBuffer(const ArrayJ &array, unsigned short *data, const size_t &size);
static void readIntBuffer(const ArrayJ &array, int *data, const size_t &size);
static void readUIntBuffer(const ArrayJ &array, unsigned int *data, const size_t &size);
static void writeFromFloat(const ArrayJ &array, float *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth);
static void writeFromByte(const ArrayJ &array, char *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth);
static void writeFromShort(const ArrayJ &array, short *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth);
static void writeFromInt(const ArrayJ &array, int *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth);

static void readToFloat(const ArrayJ &array, float *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth);
static void readToByte(const ArrayJ &array, char *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth);
static void readToShort(const ArrayJ &array, short *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth);
static void readToInt(const ArrayJ &array, int *data, const size_t &origin_x, const size_t &origin_y, const size_t &origin_z, const size_t &width, const size_t &height, const size_t &depth);
};

class UtilsJ
Expand Down
27 changes: 25 additions & 2 deletions native/clesperantoj/include/kernelj.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/*
* This file is autogenerated. Do not edit manually.
*/
*/
#ifndef __INCLUDE_KERNEL_HPP
#define __INCLUDE_KERNEL_HPP

Expand Down Expand Up @@ -109,6 +109,8 @@ class Tier1
static ArrayJ read_values_from_positions(DeviceJ * device, ArrayJ * src, ArrayJ * list, ArrayJ * dst);
static ArrayJ replace_values(DeviceJ * device, ArrayJ * src0, ArrayJ * src1, ArrayJ * dst);
static ArrayJ replace_value(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float scalar0, float scalar1);
static ArrayJ replace_intensity(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float scalar0, float scalar1);
static ArrayJ replace_intensities(DeviceJ * device, ArrayJ * src0, ArrayJ * src1, ArrayJ * dst);
static ArrayJ maximum_sphere(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float radius_x, float radius_y, float radius_z);
static ArrayJ minimum_sphere(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float radius_x, float radius_y, float radius_z);
static ArrayJ multiply_matrix(DeviceJ * device, ArrayJ * src0, ArrayJ * src1, ArrayJ * dst);
Expand Down Expand Up @@ -199,6 +201,8 @@ class Tier2
static ArrayJ standard_deviation(DeviceJ * device, ArrayJ * src, ArrayJ * dst, int radius_x, int radius_y, int radius_z, std::string connectivity);
static ArrayJ subtract_gaussian_background(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float sigma_x, float sigma_y, float sigma_z);
static ArrayJ subtract_images(DeviceJ * device, ArrayJ * src0, ArrayJ * src1, ArrayJ * dst);
static ArrayJ sub_stack(DeviceJ * device, ArrayJ * src, ArrayJ * dst, int start_z, int end_z);
static ArrayJ reduce_stack(DeviceJ * device, ArrayJ * src, ArrayJ * dst, int reduction_factor, int offset);
static float sum_of_all_pixels(DeviceJ * device, ArrayJ * src);
static ArrayJ top_hat_box(DeviceJ * device, ArrayJ * src, ArrayJ * dst, int radius_x, int radius_y, int radius_z);
static ArrayJ top_hat_sphere(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float radius_x, float radius_y, float radius_z);
Expand All @@ -211,7 +215,9 @@ class Tier3
public:
static std::vector<float> bounding_box(DeviceJ * device, ArrayJ * src);
static std::vector<float> center_of_mass(DeviceJ * device, ArrayJ * src);
static ArrayJ remove_labels(DeviceJ * device, ArrayJ * src, ArrayJ * list, ArrayJ * dst);
static ArrayJ exclude_labels(DeviceJ * device, ArrayJ * src, ArrayJ * list, ArrayJ * dst);
static ArrayJ remove_labels_on_edges(DeviceJ * device, ArrayJ * src, ArrayJ * dst, bool exclude_x, bool exclude_y, bool exclude_z);
static ArrayJ exclude_labels_on_edges(DeviceJ * device, ArrayJ * src, ArrayJ * dst, bool exclude_x, bool exclude_y, bool exclude_z);
static ArrayJ flag_existing_labels(DeviceJ * device, ArrayJ * src, ArrayJ * dst);
static ArrayJ gamma_correction(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float gamma);
Expand All @@ -224,7 +230,8 @@ class Tier3
static float mean_of_all_pixels(DeviceJ * device, ArrayJ * src);
static std::vector<float> minimum_position(DeviceJ * device, ArrayJ * src);
static ArrayJ morphological_chan_vese(DeviceJ * device, ArrayJ * src, ArrayJ * dst, int num_iter, int smoothing, float lambda1, float lambda2);
static std::unordered_map<std::string, std::vector<float>> statistics_of_labelled_pixels(DeviceJ * device, ArrayJ * src, ArrayJ * intensity);
static std::unordered_map<std::string, std::vector<float>> statistics_of_labelled_pixels(DeviceJ * device, ArrayJ * label, ArrayJ * intensity);
static std::unordered_map<std::string, std::vector<float>> statistics_of_background_and_labelled_pixels(DeviceJ * device, ArrayJ * label, ArrayJ * intensity);
};


Expand All @@ -236,6 +243,14 @@ class Tier4
static ArrayJ spots_to_pointlist(DeviceJ * device, ArrayJ * src, ArrayJ * dst);
static ArrayJ relabel_sequential(DeviceJ * device, ArrayJ * src, ArrayJ * dst, int blocksize);
static ArrayJ threshold_otsu(DeviceJ * device, ArrayJ * src, ArrayJ * dst);
static ArrayJ pixel_count_map(DeviceJ * device, ArrayJ * src, ArrayJ * dst);
static ArrayJ label_pixel_count_map(DeviceJ * device, ArrayJ * src, ArrayJ * dst);
static ArrayJ centroids_of_labels(DeviceJ * device, ArrayJ * src, ArrayJ * dst, bool withBG);
static ArrayJ remove_labels_with_map_values_out_of_range(DeviceJ * device, ArrayJ * src, ArrayJ * values, ArrayJ * dst, float min_value, float max_value);
static ArrayJ remove_labels_with_map_values_within_range(DeviceJ * device, ArrayJ * src, ArrayJ * values, ArrayJ * dst, float min_value, float max_value);
static ArrayJ exclude_labels_with_map_values_out_of_range(DeviceJ * device, ArrayJ * src, ArrayJ * values, ArrayJ * dst, float min_value_range, float max_value_range);
static ArrayJ exclude_labels_with_map_values_within_range(DeviceJ * device, ArrayJ * src, ArrayJ * values, ArrayJ * dst, float min_value_range, float max_value_range);
static ArrayJ extension_ratio_map(DeviceJ * device, ArrayJ * src, ArrayJ * dst);
};


Expand All @@ -245,6 +260,10 @@ class Tier5
static bool array_equal(DeviceJ * device, ArrayJ * src0, ArrayJ * src1);
static ArrayJ combine_labels(DeviceJ * device, ArrayJ * src0, ArrayJ * src1, ArrayJ * dst);
static ArrayJ connected_components_labeling(DeviceJ * device, ArrayJ * src, ArrayJ * dst, std::string connectivity);
static ArrayJ connected_component_labeling(DeviceJ * device, ArrayJ * src, ArrayJ * dst, std::string connectivity);
static ArrayJ reduce_labels_to_centroids(DeviceJ * device, ArrayJ * src, ArrayJ * dst);
static ArrayJ filter_label_by_size(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float minimum_size, float maximum_size);
static ArrayJ exclude_labels_outside_size_range(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float minimum_size, float maximum_size);
};


Expand All @@ -256,6 +275,10 @@ class Tier6
static ArrayJ gauss_otsu_labeling(DeviceJ * device, ArrayJ * src0, ArrayJ * dst, float outline_sigma);
static ArrayJ masked_voronoi_labeling(DeviceJ * device, ArrayJ * src, ArrayJ * mask, ArrayJ * dst);
static ArrayJ voronoi_labeling(DeviceJ * device, ArrayJ * src, ArrayJ * dst);
static ArrayJ remove_small_labels(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float minimum_size);
static ArrayJ exclude_small_labels(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float maximum_size);
static ArrayJ remove_large_labels(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float maximum_size);
static ArrayJ exclude_large_labels(DeviceJ * device, ArrayJ * src, ArrayJ * dst, float minimum_size);
};


Expand Down
Loading

0 comments on commit be4cca8

Please sign in to comment.