Skip to content

Commit

Permalink
Add OpenMP kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbarton committed May 22, 2024
1 parent e788167 commit 25a8085
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ jobs:
run: |
mkdir -p build
cd build
export LD_LIBRARY_PATH="$CONDA_PREFIX/lib:$LD_LIBRARY_PATH"
echo $LD_LIBRARY_PATH
find "$CONDA_PREFIX/lib"
find "$CONDA_PREFIX/include/"
cmake .. \
-DCMAKE_PREFIX_PATH=$CONDA_PREFIX \
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
Expand Down
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ endif()

find_package(argparse REQUIRED)
find_package(pugixml REQUIRED)

find_package(OpenMP)
# Configuration
# =============

Expand All @@ -135,8 +135,15 @@ function(configure_kernel kernel)
set(XEUS_CPP_PATH "$ENV{PATH}")
set(XEUS_CPP_LD_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH}")
set(XEUS_CPP_RESOURCE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/clang/${CPPINTEROP_LLVM_VERSION_MAJOR})
set(XEUS_CPP_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
set(XEUS_CPP_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include/)

if(${kernel} MATCHES "omp/$")
set(XEUS_CPP_OMP "${OpenMP_CXX_FLAGS}")
endif()

message(Configure_Kernel "${kernel}")
message(CPP_OMP_FLAG "${XEUS_CPP_OMP}")
message(CPP_INCLUDE_DIR "${XEUS_CPP_INCLUDE_DIR}")
if (WIN32)
string(REPLACE "\\" "/" kernel "${kernel}")
string(REPLACE "\\" "/" XEUS_CPP_PATH "${XEUS_CPP_PATH}")
Expand Down Expand Up @@ -167,7 +174,9 @@ message("Configure kernels: ...")
configure_kernel("/share/jupyter/kernels/xcpp11/")
configure_kernel("/share/jupyter/kernels/xcpp14/")
configure_kernel("/share/jupyter/kernels/xcpp17/")
configure_kernel("/share/jupyter/kernels/xcpp17-omp/")
configure_kernel("/share/jupyter/kernels/xcpp20/")
configure_kernel("/share/jupyter/kernels/xcpp20-omp/")

# Source files
# ============
Expand Down
4 changes: 3 additions & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ dependencies:
- jupyter_kernel_test>=0.4.3
- nbval
- pytest-rerunfailures
- doctest
- doctest
- llvm
- llvm-openmp
2 changes: 1 addition & 1 deletion share/jupyter/kernels/xcpp11/kernel.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"{connection_file}",
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
"-I", "@XEUS_CPP_INCLUDE_DIR@",
"-std=c++11"@XEUS_CPP_OMP@
"-std=c++11","@XEUS_CPP_OMP@"
],
"language": "cpp",
"metadata": {"debugger": false}
Expand Down
2 changes: 1 addition & 1 deletion share/jupyter/kernels/xcpp14/kernel.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"-std=c++14",
"-fno-exceptions",
"-O2",
"-v"@XEUS_CPP_OMP@
"-v","@XEUS_CPP_OMP@"
],
"language": "cpp",
"metadata": {"debugger": false}
Expand Down
2 changes: 1 addition & 1 deletion share/jupyter/kernels/xcpp17-omp/kernel.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"{connection_file}",
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
"-I", "@XEUS_CPP_INCLUDE_DIR@",
"-std=c++17"@XEUS_CPP_OMP@
"-std=c++17","@XEUS_CPP_OMP@"
],
"language": "cpp",
"metadata": {"debugger": false
Expand Down
2 changes: 1 addition & 1 deletion share/jupyter/kernels/xcpp17/kernel.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"{connection_file}",
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
"-I", "@XEUS_CPP_INCLUDE_DIR@",
"-std=c++17"@XEUS_CPP_OMP@
"-std=c++17","@XEUS_CPP_OMP@"
],
"language": "cpp",
"metadata": {"debugger": false
Expand Down
19 changes: 19 additions & 0 deletions share/jupyter/kernels/xcpp20-omp/kernel.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"display_name": "C++20 (xcpp+OpenMP)",
"env": {
"PATH":"@XEUS_CPP_PATH@",
"LD_LIBRARY_PATH":"@XEUS_CPP_LD_LIBRARY_PATH@",
"CPLUS_INCLUDE_PATH":"@CMAKE_CPLUS_INCLUDE_PATH@"
},
"argv": [
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
"-f",
"{connection_file}",
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
"-I", "@XEUS_CPP_INCLUDE_DIR@",
"-std=c++20","@XEUS_CPP_OMP@"
],
"language": "cpp",
"metadata": {"debugger": false
}
}
Binary file added share/jupyter/kernels/xcpp20-omp/logo-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added share/jupyter/kernels/xcpp20-omp/logo-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions share/jupyter/kernels/xcpp20-omp/logo-svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion share/jupyter/kernels/xcpp20/kernel.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"{connection_file}",
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
"-I", "@XEUS_CPP_INCLUDE_DIR@",
"-std=c++20"@XEUS_CPP_OMP@
"-std=c++20","@XEUS_CPP_OMP@"
],
"language": "cpp",
"metadata": {"debugger": false
Expand Down
27 changes: 25 additions & 2 deletions test/test_xcpp_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_continuation(self) -> None:
if platform.system() != 'Windows':
class XCppTests(jupyter_kernel_test.KernelTests):

kernel_name = 'xcpp20'
kernel_name = 'xcpp20-omp'

# language_info.name in a kernel_info_reply should match this
language_name = 'C++'
Expand Down Expand Up @@ -131,6 +131,29 @@ class XCppTests(jupyter_kernel_test.KernelTests):
'mime': 'image/png'
}
]
code_omp="""
#include <omp.h>
#include <iostream>
#include <clang/Interpreter/CppInterOp.h>
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
std::string BinaryPath = GetExecutablePath(/*Argv0=*/nullptr);
llvm::StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
Cpp::AddSearchPath(Dir.str().c_str());
#ifdef __APPLE__
std::string PathToTestSharedLib = Cpp::SearchLibrariesForSymbol("_omp_get_max_threads_", /*system_search=*/false);
#else
std::string PathToTestSharedLib = Cpp::SearchLibrariesForSymbol("omp_get_max_threads_", /*system_search=*/false);
#endif // __APPLE__
bool loaded=Cpp::LoadLibrary("PathToTestSharedLib.c_str())");
std::cerr<<loaded<<std::endl;
"""
def test_xcpp_omp(self):
self.flush_channels()
reply, output_msgs = self.execute_helper(code=self.code_omp,timeout=20)
self.assertEqual(output_msgs[0]['msg_type'], 'stream')
self.assertEqual(output_msgs[0]['content']['name'], 'stderr')
self.assertEqual(output_msgs[0]['content']['text'], '2')


class XCppTests2(jupyter_kernel_test.KernelTests):
Expand All @@ -145,4 +168,4 @@ class XCppTests2(jupyter_kernel_test.KernelTests):


if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit 25a8085

Please sign in to comment.