Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a3e3cd1
[OKL] Extend allowed loop index types to include `size_t` and `ptrdif…
Aug 15, 2022
7e5fd1c
Fix dpcpp warnings (#617)
kris-rowe Aug 16, 2022
b638c7f
Merge branch 'main' into development
kris-rowe Aug 16, 2022
7c98d03
Update build.yml
kris-rowe Aug 16, 2022
5f7e4ea
Add Fortran to CI pipeline.
kris-rowe Aug 16, 2022
0ed7c16
Update build.yml
kris-rowe Aug 16, 2022
a23bd70
Update build.yml
kris-rowe Aug 16, 2022
fcc43c5
Update build.yml
kris-rowe Aug 16, 2022
a9103f0
Show compiler output for kernel if verbose is true (#619)
Aug 18, 2022
ad47457
CMake find OpenCL (#616)
kris-rowe Sep 1, 2022
eaef90e
Improve compilation output (#620)
Sep 8, 2022
50a8a9b
Make compiler_flags setting take precedence over the compiler flag en…
MalachiTimothyPhillips Sep 28, 2022
f3373b7
[CUDA][HIP][DPC++] Fix an issue with double frees when OKL has multip…
noelchalmers Oct 3, 2022
f5e4972
[Serial] Add dynamic exclusive variable sizes (#625)
noelchalmers Oct 3, 2022
d7d0909
Fix warnings with gcc-11 (#627)
noelchalmers Oct 17, 2022
b14b6cc
[OpenMP] Fix bug with cancelling hash (#626)
noelchalmers Oct 17, 2022
a3ff2ed
[API][Core] Memory Pools (#543)
noelchalmers Oct 27, 2022
cdcd1bd
[Dtypes] Add support for std::byte dtype
noelchalmers Oct 18, 2022
05c43e5
First steps for making a user-dtype registry, and make the byte dtype…
noelchalmers Oct 19, 2022
e523bbe
Add some new methods to register and deregister dtypes through templa…
noelchalmers Oct 19, 2022
9cbd0a0
Add some example of templated methods to example 05
noelchalmers Oct 19, 2022
a411058
Improve dtype tests to cover new methods
noelchalmers Oct 19, 2022
13d3d4a
Fix a byte dtype name
noelchalmers Oct 31, 2022
f63ef37
Fix a signed comparison
noelchalmers Oct 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ jobs:
CC: gcc-9
CXX: g++-9
CXXFLAGS: -Wno-maybe-uninitialized -Wno-cpp
FC: gfortran-9
GCOV: gcov-9
OCCA_COVERAGE: 1
OCCA_FORTRAN_ENABLED: 1
useCMake: true

- name: "[Ubuntu] clang-11"
Expand All @@ -49,9 +51,10 @@ jobs:
CC: icx
CXX: icpx
CXXFLAGS: -Wno-uninitialized
FC: ifx
FC: ifort
GCOV: gcov-9
OCCA_COVERAGE: 1
OCCA_FORTRAN_ENABLED: 1
useCMake: true
useoneAPI: true

Expand Down Expand Up @@ -103,7 +106,8 @@ jobs:
shell: bash
run: |
sudo apt update
sudo apt install intel-oneapi-compiler-dpcpp-cpp
sudo apt install intel-oneapi-compiler-dpcpp-cpp
sudo apt install intel-oneapi-compiler-fortran

- name: Compiler info
if: ${{ !matrix.useCMake }}
Expand All @@ -115,8 +119,12 @@ jobs:
cmake -S . -B build \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_C_COMPILER=${CC} \
-DCMAKE_CXX_COMPILER=${CXX} \
-DCMAKE_Fortran_COMPILER=${FC} \
-DENABLE_TESTS=ON \
-DENABLE_EXAMPLES=ON
-DENABLE_EXAMPLES=ON \
-DENABLE_FORTRAN=ON

- name: CMake configure
if: ${{ matrix.useCMake && matrix.useoneAPI}}
Expand All @@ -128,8 +136,12 @@ jobs:
cmake -S . -B build \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_C_COMPILER=${CC} \
-DCMAKE_CXX_COMPILER=${CXX} \
-DCMAKE_Fortran_COMPILER=${FC} \
-DENABLE_TESTS=ON \
-DENABLE_EXAMPLES=ON \
-DENABLE_FORTRAN=ON \
-DCMAKE_PREFIX_PATH="/opt/intel/oneapi/compiler/latest/linux;/opt/intel/oneapi/compiler/latest/linux/compiler"

- name: CMake build
Expand Down Expand Up @@ -165,7 +177,8 @@ jobs:
- name: Run CTests
if: ${{ matrix.useCMake && !matrix.useoneAPI }}
run: |
ctest --test-dir build --progress --output-on-failure --parallel 8 --schedule-random -E "examples_cpp_arrays-opencl|examples_cpp_for_loops-opencl|examples_cpp_generic_inline_kernel-opencl|examples_cpp_shared_memory-opencl|examples_cpp_nonblocking_streams-opencl|examples_cpp_shared_memory-dpcpp|examples_cpp_nonblocking_streams-dpcpp|examples_cpp_for_loops-dpcpp|examples_cpp_arrays-dpcpp"
ctest --test-dir build --progress --output-on-failure --parallel 8 --schedule-random -E "examples_cpp_arrays-opencl|examples_cpp_for_loops-opencl|examples_cpp_generic_inline_kernel-opencl|examples_cpp_shared_memory-opencl|examples_cpp_nonblocking_streams-opencl|examples_cpp_for_loops-dpcpp|examples_cpp_arrays-dpcpp|examples_cpp_nonblocking_streams-dpcpp"



- name: Run CTests
Expand All @@ -176,7 +189,7 @@ jobs:
run: |
source /opt/intel/oneapi/setvars.sh
export SYCL_DEVICE_FILTER=opencl.cpu
ctest --test-dir build --progress --output-on-failure --parallel 8 --schedule-random -E "examples_cpp_arrays-opencl|examples_cpp_for_loops-opencl|examples_cpp_generic_inline_kernel-opencl|examples_cpp_shared_memory-opencl|examples_cpp_nonblocking_streams-opencl|examples_cpp_shared_memory-dpcpp|examples_cpp_nonblocking_streams-dpcpp|examples_cpp_for_loops-dpcpp|examples_cpp_arrays-dpcpp"
ctest --test-dir build --progress --output-on-failure --parallel 8 --schedule-random -E "examples_cpp_arrays-opencl|examples_cpp_for_loops-opencl|examples_cpp_generic_inline_kernel-opencl|examples_cpp_shared_memory-opencl|examples_cpp_nonblocking_streams-opencl|examples_cpp_for_loops-dpcpp|examples_cpp_arrays-dpcpp|examples_cpp_nonblocking_streams-dpcpp"

- name: Upload code coverage
if: ${{ matrix.OCCA_COVERAGE }}
Expand Down
53 changes: 32 additions & 21 deletions cmake/FindOpenCLWrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,42 @@
# This Find module is also distributed alongside the occa package config file!
###############################################################################

# Look in some default places for OpenCL and set OPENCL_ROOT if not already set
if(NOT OPENCL_ROOT)
# Search in user specified path first
find_path(OPENCL_ROOT
NAMES CL/cl.h
# Try finding OpenCL. The user should set OpenCL_ROOT if needed.
find_package(OpenCL QUIET)
if(NOT OpenCL_FOUND)
# Otherwise, look for the headers and library in standard locations
find_path(OpenCL_INCLUDE_DIR
NAMES CL/cl.h OpenCL/cl.h
PATHS
ENV OPENCL_PATH
DOC "OPENCL root location"
NO_DEFAULT_PATH)
ENV CUDA_PATH
ENV CUDAToolkit_ROOT
ENV ROCM_PATH
ENV NVHPC_ROOT
ENV SYCL_ROOT
/usr/local/cuda
/opt/rocm/opencl
/opt/intel/oneapi/compiler/latest/linux
PATH_SUFFIXES
include
include/sycl
)

# Now search in default path
find_path(OPENCL_ROOT
NAMES CL/cl.h
PATHS
/usr
/opt/rocm/opencl
/usr/local/cuda
find_library(OpenCL_LIBRARY
NAMES OpenCL libOpenCL
PATHS
ENV CUDA_PATH
ENV CUDAToolkit_ROOT
ENV ROCM_PATH
ENV NVHPC_ROOT
ENV SYCL_ROOT
/usr/local/cuda
/opt/rocm/opencl
/opt/intel/oneapi/compiler/latest/linux
PATH_SUFFIXES sycl
DOC "OPENCL root location")
PATH_SUFFIXES
lib
lib64
)
endif()

# Trick CMake's default OpenCL module to look in our directory
set(ENV{AMDAPPSDKROOT} ${OPENCL_ROOT})

find_package(OpenCL)

include(FindPackageHandleStandardArgs)
Expand Down
64 changes: 62 additions & 2 deletions examples/cpp/05_custom_types/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ int main(int argc, const char **argv) {
myFloatDtype.registerType();

// Struct dtype
occa::dtype_t myFloat2Dtype;
myFloat2Dtype.registerType();
occa::dtype_t myFloat2Dtype("myFloat2", sizeof(myFloat2));
myFloat2Dtype.addField("x", occa::dtype::float_);
myFloat2Dtype.addField("y", occa::dtype::float_);
myFloat2Dtype.registerType();

// Tuple dtype
occa::dtype_t myFloat4Dtype = occa::dtype_t::tuple(occa::dtype::float_, 4);
Expand Down Expand Up @@ -108,6 +108,66 @@ int main(int argc, const char **argv) {
}
}

o_a.free();
o_b.free();
o_ab.free();

// Templated dtypes
// - occa::memory dtypes can be created and assigned via templated methods
// - dtypes registered this way are tracked internally and destroyed when deregistered
// - Registered dtype_t objects are treated as singletons and assumed
// to exist while the memory objects are still alive

// Automatic creation
// Using a type that has not been registered with OCCA will be
// automatically registered as a byte field (thus all type-checking is disabled)
o_a = occa::malloc<myFloat>(entries);

// Struct dtype
occa::dtype::registerType<myFloat2>("myFloat2",
{"x", "y"},
{occa::dtype::float_, occa::dtype::float_});

o_b = occa::malloc<myFloat2>(entries / 2);

// Tuple dtype
occa::dtype::registerType<myFloat4>("myFloat4", occa::dtype::float_, 4);

o_ab = occa::malloc<myFloat4>(entries / 4);

// Copy memory to the device
o_a.copyFrom(a);
o_b.copyFrom(b);

// Launch device kernel
addVectors(entries,
o_a.cast(occa::dtype::float_),
o_b,
o_ab);

// Copy result to the host
o_ab.copyTo(ab);

// Assert values
for (int i = 0; i < (entries / 4); ++i) {
for (int j = 0; j < 4; ++j) {
std::cout << '(' << i << ',' << j << ") : " << ab[i].values[j] << '\n';
}
}
for (int i = 0; i < entries; ++i) {
float a_i = a[i].value;
float b_i = (i % 2) ? b[i / 2].y : b[i / 2].x;
float ab_i = ab[i / 4].values[i % 4];
if (!occa::areBitwiseEqual(ab_i, a_i + b_i)) {
throw 1;
}
}

// Can deregister templated dtypes if they're no longer needed
occa::dtype::deRegisterType<myFloat>();
occa::dtype::deRegisterType<myFloat2>();
occa::dtype::deRegisterType<myFloat4>();

// Free host memory
delete [] a;
delete [] b;
Expand Down
4 changes: 4 additions & 0 deletions examples/cpp/17_memory_pool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
compile_cpp_example(memory_pool main.cpp)

add_custom_target(cpp_example_memory_pool_okl ALL COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/addVectors.okl addVectors.okl)
add_dependencies(examples_cpp_memory_pool cpp_example_memory_pool_okl)
30 changes: 30 additions & 0 deletions examples/cpp/17_memory_pool/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

PROJ_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

ifndef OCCA_DIR
include $(PROJ_DIR)/../../../scripts/build/Makefile
else
include ${OCCA_DIR}/scripts/build/Makefile
endif

#---[ COMPILATION ]-------------------------------
headers = $(wildcard $(incPath)/*.hpp) $(wildcard $(incPath)/*.tpp)
sources = $(wildcard $(srcPath)/*.cpp)

objects = $(subst $(srcPath)/,$(objPath)/,$(sources:.cpp=.o))

executables: ${PROJ_DIR}/main

${PROJ_DIR}/main: $(objects) $(headers) ${PROJ_DIR}/main.cpp
$(compiler) $(compilerFlags) -o ${PROJ_DIR}/main $(flags) $(objects) ${PROJ_DIR}/main.cpp $(paths) $(linkerFlags)
@if which install_name_tool > /dev/null 2>&1; then \
install_name_tool -add_rpath "${OCCA_DIR}/lib" ${PROJ_DIR}/main; \
fi

$(objPath)/%.o:$(srcPath)/%.cpp $(wildcard $(subst $(srcPath)/,$(incPath)/,$(<:.cpp=.hpp))) $(wildcard $(subst $(srcPath)/,$(incPath)/,$(<:.cpp=.tpp)))
$(compiler) $(compilerFlags) -o $@ $(flags) -c $(paths) $<

clean:
rm -f $(objPath)/*;
rm -f ${PROJ_DIR}/main;
#=================================================
28 changes: 28 additions & 0 deletions examples/cpp/17_memory_pool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Example: Memory Pool

A example showing the basics of using OCCA's memory pools

- Creating an OCCA memory
- Managing memory pool
- Reserving and using memory from memory pool

# Compiling the Example

```bash
make
```

## Usage

```
> ./main --help

Usage: ./main [OPTIONS]

Example using memory pools

Options:
-d, --device Device properties (default: "{mode: 'Serial'}")
-h, --help Print usage
-v, --verbose Compile kernels in verbose mode
```
8 changes: 8 additions & 0 deletions examples/cpp/17_memory_pool/addVectors.okl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@kernel void addVectors(const int entries,
const float *a,
const float *b,
float *ab) {
for (int i = 0; i < entries; ++i; @tile(4, @outer, @inner)) {
ab[i] = a[i] + b[i];
}
}
Loading