Skip to content

Commit

Permalink
Merge pull request #25 from clEsperanto/use-new-backend-gpu
Browse files Browse the repository at this point in the history
make it main
  • Loading branch information
StRigaud authored May 29, 2024
2 parents 4f150d6 + f19e63e commit 1caf008
Show file tree
Hide file tree
Showing 14 changed files with 508 additions and 352 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build-and-run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build and Run

on:
push:
branches: [ use-new-backend-gpu ]
pull_request:
branches: [ use-new-backend-gpu ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Find available GPUs
run: lspci | grep -i vga
- name: Install openCL
run: sudo apt install ocl-icd-opencl-dev
- name: Check installation
run: dpkg -L ocl-icd-opencl-dev
- name: Build with Maven
run: mvn clean install

- name: Run Java class
run: java -cp target/classes com.example.YourMainClass
18 changes: 7 additions & 11 deletions native/clesperantoj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@ 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

include(FetchContent)
option(BUILD_TESTING OFF)
option(BUILD_BENCHMARK OFF)
FetchContent_Declare(
clic_lib
GIT_REPOSITORY https://github.com/clEsperanto/CLIc_prototype.git
GIT_TAG 0.6.4
)
FetchContent_MakeAvailable(clic_lib)
## CLIc dependency
option(BUILD_TESTING OFF)
option(BUILD_BENCHMARK OFF)
option(BUILD_SHARED_LIBS ON)
set(CLIC_REPO_TAG 0.10.2) # branch name for dev
set(CLIC_REPO_URL https://github.com/clEsperanto/CLIc_prototype.git)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/clic)

file(GLOB_RECURSE WRAPPER_SOURCES_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE WRAPPER_HEADERS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp)
set(WRAPPER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_library(${LIB_PACKAGE_NAME} SHARED ${WRAPPER_SOURCES_FILES})

target_link_libraries(${LIB_PACKAGE_NAME} PUBLIC CLIc::CLIc)

target_include_directories(${LIB_PACKAGE_NAME} PUBLIC "$<BUILD_INTERFACE:${WRAPPER_DIR}>")

install(TARGETS ${LIB_PACKAGE_NAME} DESTINATION .)
Expand Down
13 changes: 13 additions & 0 deletions native/clesperantoj/clic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## fetch CLIc from repo release
include(FetchContent)

option(BUILD_SHARED_LIBS OFF)
option(BUILD_TESTING OFF)
option(BUILD_BENCHMARK OFF)

FetchContent_Declare(
CLIc
GIT_REPOSITORY ${CLIC_REPO_URL}
GIT_TAG ${CLIC_REPO_TAG}
)
FetchContent_MakeAvailable(CLIc)
7 changes: 4 additions & 3 deletions native/clesperantoj/cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ case $PLATFORM in
;;
macosx-*)
# the following line might not be necessary if make would be properly installed in the path
CMAKE=/Applications/CMake.app/Contents/bin/cmake
# CMAKE=/Applications/CMake.app/Contents/bin/cmake

$CMAKE -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="../../../lib/macosx/" ..
Expand All @@ -36,8 +36,9 @@ case $PLATFORM in
windows-x86_64)
$CMAKE -G"NMake Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="../../../lib/win64/" ..
# -DOPENCL_INCLUDE_DIR="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.2/include/" \
-DCMAKE_INSTALL_PREFIX="../../../lib/win64/" ..
# -DOpenCL_INCLUDE_DIR="C:/Program Files (x86)/OCL_SDK_Light/include" \
# -DOpenCL_LIBRARY="C:/Program Files (x86)/OCL_SDK_Light/lib/x86_64/opencl.lib" ..
# -DCLIC_INCLUDE_DIR="../../../CLIc_prototype/clic/include/core" \
# -DOCLCL_INCLUDE_DIR="../../../CLIc_prototype/thirdparty/opencl/ocl-clhpp/include" \
# -DCLFFT_LIBRARY_DIR="C:/OpenCL/clFFT-2.12.2-Windows-x64/lib64/import/" ..
Expand Down
70 changes: 40 additions & 30 deletions native/clesperantoj/include/clesperantoj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,78 @@
#include <string>
#include <vector>

#include "cleImage.hpp"
#include "cleProcessor.hpp"
#include "array.hpp"
#include "backend.hpp"
#include "device.hpp"
#include "utils.hpp"

class ProcessorJ
class BackendJ
{
friend class BufferJ;
friend class MemoryJ;
public:
static void setBackend(const std::string &backendName);
};

class DeviceJ
{
friend class BackendJ;

private:
cle::Processor proc;
ProcessorJ(const cle::Processor &proc);
std::shared_ptr<cle::Device> device_;

public:
ProcessorJ();
ProcessorJ(const std::string &name);
std::vector<std::string> getAvailableDevices();
void setDevice(const std::string &name);
std::string getDevice();
DeviceJ();

cle::Processor get() const;
std::shared_ptr<cle::Processor> getShared() const;
};
static std::vector<std::string> getAvailableDevices(const std::string &deviceType = "all");

class BufferJ
void setDevice(const std::string &deviceName = "", const std::string &deviceType = "all");
std::string getName();
std::string getInfo();

std::shared_ptr<cle::Device> get() const;
};
class ArrayJ
{
friend class MemoryJ;

private:
cle::Image buffer;
BufferJ(const cle::Image &buffer);
std::shared_ptr<cle::Array> array_;

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 write(void *data) const;
void read(void *data) const;

public:
BufferJ();
ArrayJ() = default;
ArrayJ(const std::shared_ptr<cle::Array> &array);

size_t getWidth();
size_t getHeight();
size_t getDepth();
void getShape(size_t *shape);
unsigned int getDimension();

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

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

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

class MemoryJ
{
public:
static BufferJ makeFloatBuffer(const ProcessorJ &device, const size_t &width, const size_t &height, const size_t &depth, const std::string &memory_type);
static BufferJ makeIntBuffer(const ProcessorJ &device, const size_t &width, const size_t &height, const size_t &depth, const std::string &memory_type);
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 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 void writeFloatBuffer(const BufferJ &buffer, float *data, const size_t &size);
static void writeIntBuffer(const BufferJ &buffer, int *data, const size_t &size);
static void writeFloatBuffer(const ArrayJ &array, float *data, const size_t &size);
static void writeIntBuffer(const ArrayJ &array, int *data, const size_t &size);

static void readFloatBuffer(const BufferJ &buffer, float *data, const size_t &size);
static void readIntBuffer(const BufferJ &buffer, int *data, const size_t &size);
static void readFloatBuffer(const ArrayJ &array, float *data, const size_t &size);
static void readIntBuffer(const ArrayJ &array, int *data, const size_t &size);
};

#endif // __INCLUDE_CLESPERANTOJ_HPP
6 changes: 4 additions & 2 deletions native/clesperantoj/include/kernelj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
class Tier1
{
public:
static void addImageAndScalar(const ProcessorJ &proc, const BufferJ &src, const BufferJ &dst, const float &scalar);
static void gaussianBlur(const ProcessorJ &proc, const BufferJ &src, const BufferJ &dst, const float &sigmaX, const float &sigmaY, const float &sigmaZ);
static ArrayJ absolute(const DeviceJ &dev, const ArrayJ &src, ArrayJ &dst);
static ArrayJ absolute(const DeviceJ &dev, const ArrayJ &src);
static void gaussianBlur(const DeviceJ &dev, const ArrayJ &src, const ArrayJ &dst, const float &sigmaX, const float &sigmaY, const float &sigmaZ);
static void addImageAndScalar(const DeviceJ &dev, const ArrayJ &src, const ArrayJ &dst, const float &scalar);
};

#endif // __INCLUDE_KERNELJ_HPP
Loading

0 comments on commit 1caf008

Please sign in to comment.