From 57170924e9ef0ffab21af87c52236e7a69921537 Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Tue, 21 Jan 2025 17:01:37 -0500 Subject: [PATCH 01/12] init: run a empty "hello oqd world!" capi stub --- .../third_party/oqd/example/6_llvm_ir.ll | 57 +++++++++++++++++++ .../third_party/oqd/example/oqd_run.py | 21 +++++++ runtime/lib/capi/CMakeLists.txt | 2 +- runtime/lib/capi/OQDRuntimeCAPI.cpp | 24 ++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll create mode 100644 frontend/catalyst/third_party/oqd/example/oqd_run.py create mode 100644 runtime/lib/capi/OQDRuntimeCAPI.cpp diff --git a/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll b/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll new file mode 100644 index 0000000000..9835f669a7 --- /dev/null +++ b/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll @@ -0,0 +1,57 @@ +; ModuleID = 'LLVMDialectModule' +source_filename = "LLVMDialectModule" + +@"{'shots': 1000}" = internal constant [16 x i8] c"{'shots': 1000}\00" +@oqd = internal constant [4 x i8] c"oqd\00" +@"/home/paul.wang/catalyst_new/catalyst/frontend/catalyst/utils/../../catalyst/third_party/oqd/src/build/librtd_oqd.so" = internal constant [117 x i8] c"/home/paul.wang/catalyst_new/catalyst/frontend/catalyst/utils/../../catalyst/third_party/oqd/src/build/librtd_oqd.so\00" + +declare void @__catalyst__oqd__greetings() + +declare void @__catalyst__rt__finalize() + +declare void @__catalyst__rt__initialize(ptr) + +declare void @__catalyst__rt__device_release() + +declare void @__catalyst__rt__device_init(ptr, ptr, ptr, i64) + +define void @jit_f() { + call void @f_0() + ret void +} + +define void @_catalyst_pyface_jit_f(ptr %0, ptr %1) { + call void @_catalyst_ciface_jit_f(ptr %0) + ret void +} + +define void @_catalyst_ciface_jit_f(ptr %0) { + call void @jit_f() + ret void +} + +define void @f_0() { + call void @__catalyst__rt__device_init(ptr @"/home/paul.wang/catalyst_new/catalyst/frontend/catalyst/utils/../../catalyst/third_party/oqd/src/build/librtd_oqd.so", ptr @oqd, ptr @"{'shots': 1000}", i64 1000) + call void @__catalyst__oqd__greetings() + call void @__catalyst__rt__device_release() + ret void +} + +define void @setup() { + call void @__catalyst__rt__initialize(ptr null) + ret void +} + +define void @teardown() { + call void @__catalyst__rt__finalize() + ret void +} + +; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite) +declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0 + +attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) } + +!llvm.module.flags = !{!0} + +!0 = !{i32 2, !"Debug Info Version", i32 3} diff --git a/frontend/catalyst/third_party/oqd/example/oqd_run.py b/frontend/catalyst/third_party/oqd/example/oqd_run.py new file mode 100644 index 0000000000..37a344d318 --- /dev/null +++ b/frontend/catalyst/third_party/oqd/example/oqd_run.py @@ -0,0 +1,21 @@ +import pennylane as qml +import pytest + +import catalyst +from catalyst import qjit +from catalyst.third_party.oqd import OQDDevice +from catalyst.debug import get_compilation_stage, replace_ir + +dev = OQDDevice(backend="default", shots=1000, wires=8) + +@qjit#(keep_intermediate=True) +@qml.qnode(dev) +def f(): + qml.Hadamard(wires=0) + return qml.probs() + +with open("6_llvm_ir.ll", "r") as file: + ir = file.read() +replace_ir(f, "llvm_ir", ir) + +f() diff --git a/runtime/lib/capi/CMakeLists.txt b/runtime/lib/capi/CMakeLists.txt index e05e9bffee..7162562e2d 100644 --- a/runtime/lib/capi/CMakeLists.txt +++ b/runtime/lib/capi/CMakeLists.txt @@ -2,7 +2,7 @@ # Object Lib catalyst_qir_qis_obj ################################## -add_library(catalyst_qir_qis_obj OBJECT RuntimeCAPI.cpp) +add_library(catalyst_qir_qis_obj OBJECT RuntimeCAPI.cpp OQDRuntimeCAPI.cpp) # include external MLIR runner utils FetchContent_MakeAvailable(MLIRRunnerUtils) diff --git a/runtime/lib/capi/OQDRuntimeCAPI.cpp b/runtime/lib/capi/OQDRuntimeCAPI.cpp new file mode 100644 index 0000000000..068460a767 --- /dev/null +++ b/runtime/lib/capi/OQDRuntimeCAPI.cpp @@ -0,0 +1,24 @@ +// Copyright 2025 Xanadu Quantum Technologies Inc. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +extern "C" { + +void __catalyst__oqd__greetings() { + std::cout << "Hello OQD world!" << std::endl; +} + + +} From 04bb28f154efc17da79cf3a602b4d03d1c9fa6cc Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Thu, 23 Jan 2025 16:28:37 -0500 Subject: [PATCH 02/12] strip down to minimal runnable llvm ir --- .../third_party/oqd/example/6_llvm_ir.ll | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll b/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll index 9835f669a7..73950e4e43 100644 --- a/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll +++ b/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll @@ -1,20 +1,12 @@ ; ModuleID = 'LLVMDialectModule' source_filename = "LLVMDialectModule" -@"{'shots': 1000}" = internal constant [16 x i8] c"{'shots': 1000}\00" -@oqd = internal constant [4 x i8] c"oqd\00" -@"/home/paul.wang/catalyst_new/catalyst/frontend/catalyst/utils/../../catalyst/third_party/oqd/src/build/librtd_oqd.so" = internal constant [117 x i8] c"/home/paul.wang/catalyst_new/catalyst/frontend/catalyst/utils/../../catalyst/third_party/oqd/src/build/librtd_oqd.so\00" - declare void @__catalyst__oqd__greetings() declare void @__catalyst__rt__finalize() declare void @__catalyst__rt__initialize(ptr) -declare void @__catalyst__rt__device_release() - -declare void @__catalyst__rt__device_init(ptr, ptr, ptr, i64) - define void @jit_f() { call void @f_0() ret void @@ -31,9 +23,7 @@ define void @_catalyst_ciface_jit_f(ptr %0) { } define void @f_0() { - call void @__catalyst__rt__device_init(ptr @"/home/paul.wang/catalyst_new/catalyst/frontend/catalyst/utils/../../catalyst/third_party/oqd/src/build/librtd_oqd.so", ptr @oqd, ptr @"{'shots': 1000}", i64 1000) call void @__catalyst__oqd__greetings() - call void @__catalyst__rt__device_release() ret void } @@ -46,12 +36,3 @@ define void @teardown() { call void @__catalyst__rt__finalize() ret void } - -; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite) -declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0 - -attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) } - -!llvm.module.flags = !{!0} - -!0 = !{i32 2, !"Debug Info Version", i32 3} From 444771534981a25bdcbc3f4bc80fdb2235ed9b58 Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Fri, 24 Jan 2025 11:32:45 -0500 Subject: [PATCH 03/12] delete frontend example --- .../third_party/oqd/example/6_llvm_ir.ll | 38 ------------------- .../third_party/oqd/example/oqd_run.py | 21 ---------- 2 files changed, 59 deletions(-) delete mode 100644 frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll delete mode 100644 frontend/catalyst/third_party/oqd/example/oqd_run.py diff --git a/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll b/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll deleted file mode 100644 index 73950e4e43..0000000000 --- a/frontend/catalyst/third_party/oqd/example/6_llvm_ir.ll +++ /dev/null @@ -1,38 +0,0 @@ -; ModuleID = 'LLVMDialectModule' -source_filename = "LLVMDialectModule" - -declare void @__catalyst__oqd__greetings() - -declare void @__catalyst__rt__finalize() - -declare void @__catalyst__rt__initialize(ptr) - -define void @jit_f() { - call void @f_0() - ret void -} - -define void @_catalyst_pyface_jit_f(ptr %0, ptr %1) { - call void @_catalyst_ciface_jit_f(ptr %0) - ret void -} - -define void @_catalyst_ciface_jit_f(ptr %0) { - call void @jit_f() - ret void -} - -define void @f_0() { - call void @__catalyst__oqd__greetings() - ret void -} - -define void @setup() { - call void @__catalyst__rt__initialize(ptr null) - ret void -} - -define void @teardown() { - call void @__catalyst__rt__finalize() - ret void -} diff --git a/frontend/catalyst/third_party/oqd/example/oqd_run.py b/frontend/catalyst/third_party/oqd/example/oqd_run.py deleted file mode 100644 index 37a344d318..0000000000 --- a/frontend/catalyst/third_party/oqd/example/oqd_run.py +++ /dev/null @@ -1,21 +0,0 @@ -import pennylane as qml -import pytest - -import catalyst -from catalyst import qjit -from catalyst.third_party.oqd import OQDDevice -from catalyst.debug import get_compilation_stage, replace_ir - -dev = OQDDevice(backend="default", shots=1000, wires=8) - -@qjit#(keep_intermediate=True) -@qml.qnode(dev) -def f(): - qml.Hadamard(wires=0) - return qml.probs() - -with open("6_llvm_ir.ll", "r") as file: - ir = file.read() -replace_ir(f, "llvm_ir", ir) - -f() From 5127837ea883c1b379cadbb03bd33700ad73d781 Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Fri, 24 Jan 2025 11:34:59 -0500 Subject: [PATCH 04/12] setup build system for oqd capi --- runtime/CMakeLists.txt | 7 +++ runtime/Makefile | 7 +++ runtime/include/OQDRuntimeCAPI.h | 30 +++++++++++++ runtime/lib/CMakeLists.txt | 1 + runtime/lib/OQDcapi/CMakeLists.txt | 45 +++++++++++++++++++ .../lib/{capi => OQDcapi}/OQDRuntimeCAPI.cpp | 2 + runtime/lib/capi/CMakeLists.txt | 2 +- runtime/tests/CMakeLists.txt | 1 + runtime/tests/Test_OQD_OpenAPLGeneration.cpp | 22 +++++++++ 9 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 runtime/include/OQDRuntimeCAPI.h create mode 100644 runtime/lib/OQDcapi/CMakeLists.txt rename runtime/lib/{capi => OQDcapi}/OQDRuntimeCAPI.cpp (96%) create mode 100644 runtime/tests/Test_OQD_OpenAPLGeneration.cpp diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 1651851210..16a28ee7c0 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -14,6 +14,8 @@ option(RUNTIME_CLANG_TIDY "Enable Clang Tidy" OFF) option(ENABLE_OPENQASM "Build OpenQasm backend device" OFF) +option(ENABLE_OQD "Build OQD CAPI" OFF) + set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -76,6 +78,7 @@ if(RUNTIME_ENABLE_WARNINGS) endif() message(STATUS "ENABLE_OPENQASM is ${ENABLE_OPENQASM}.") +message(STATUS "ENABLE_OQD is ${ENABLE_OQD}.") set(devices_list) list(APPEND devices_list rtd_null_qubit) @@ -90,6 +93,10 @@ add_library(catalyst_qir_runtime INTERFACE) target_link_libraries(catalyst_qir_runtime INTERFACE ${devices_list} rt_capi) +if(ENABLE_OQD) + target_link_libraries(catalyst_qir_runtime INTERFACE rt_OQD_capi) +endif() + target_include_directories(catalyst_qir_runtime INTERFACE ${runtime_includes} ${backend_includes} diff --git a/runtime/Makefile b/runtime/Makefile index 6d2b620842..3f601de624 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -11,6 +11,7 @@ MK_DIR := $(dir $(MK_ABSPATH)) RT_BUILD_DIR?=$(MK_DIR)/build CODE_COVERAGE?=OFF BUILD_TYPE?=RelWithDebInfo +ENABLE_OQD?=ON ENABLE_OPENQASM?=ON ENABLE_ASAN?=OFF @@ -24,6 +25,11 @@ ifeq ($(ENABLE_OPENQASM), ON) TEST_TARGETS += runner_tests_openqasm endif +ifeq ($(ENABLE_OQD), ON) + BUILD_TARGETS += rt_OQD_capi + #TEST_TARGETS += runner_tests_openqasm +endif + .PHONY: help help: @echo "Please use \`make ' where is one of" @@ -47,6 +53,7 @@ configure: -DCMAKE_C_COMPILER_LAUNCHER=$(COMPILER_LAUNCHER) \ -DCMAKE_CXX_COMPILER_LAUNCHER=$(COMPILER_LAUNCHER) \ -DENABLE_OPENQASM=$(ENABLE_OPENQASM) \ + -DENABLE_OQD=$(ENABLE_OQD) \ -DENABLE_CODE_COVERAGE=$(CODE_COVERAGE) \ -DPython_EXECUTABLE=$(PYTHON) \ -DENABLE_ADDRESS_SANITIZER=$(ENABLE_ASAN) diff --git a/runtime/include/OQDRuntimeCAPI.h b/runtime/include/OQDRuntimeCAPI.h new file mode 100644 index 0000000000..73ce745557 --- /dev/null +++ b/runtime/include/OQDRuntimeCAPI.h @@ -0,0 +1,30 @@ +// Copyright 2025 Xanadu Quantum Technologies Inc. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once +#ifndef OQDRUNTIMECAPI_H +#define OQDRUNTIMECAPI_H + +#ifdef __cplusplus +extern "C" { +#endif + +// OQD Runtime Instructions +void __catalyst__oqd__greetings(); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif diff --git a/runtime/lib/CMakeLists.txt b/runtime/lib/CMakeLists.txt index 50fd0b0e75..ada8395c14 100644 --- a/runtime/lib/CMakeLists.txt +++ b/runtime/lib/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(capi) add_subdirectory(backend) add_subdirectory(registry) +add_subdirectory(OQDcapi) diff --git a/runtime/lib/OQDcapi/CMakeLists.txt b/runtime/lib/OQDcapi/CMakeLists.txt new file mode 100644 index 0000000000..41437b01ce --- /dev/null +++ b/runtime/lib/OQDcapi/CMakeLists.txt @@ -0,0 +1,45 @@ +################################## +# Object Lib catalyst_oqd_obj +################################## + +add_library(catalyst_oqd_obj OBJECT OQDRuntimeCAPI.cpp) + +# link to rt_backend +target_link_libraries(catalyst_oqd_obj ${CMAKE_DL_LIBS}) + +target_link_libraries(catalyst_oqd_obj + pthread + dl +) + +target_include_directories(catalyst_oqd_obj PUBLIC . + ${CMAKE_CURRENT_SOURCE_DIR} + ${runtime_includes} + ${PROJECT_SOURCE_DIR}/../mlir/lib/Driver # Timer.hpp +) + + +##################### +# Shared Lib rt_OQD_capi +##################### + +add_library(rt_OQD_capi SHARED) + +target_link_libraries(rt_OQD_capi ${CMAKE_DL_LIBS} catalyst_oqd_obj) +add_dependencies(rt_OQD_capi catalyst_callback_registry) + + +target_include_directories(rt_OQD_capi PUBLIC . + ${CMAKE_CURRENT_SOURCE_DIR} + ${runtime_includes} + ${capi_utils_includes} +) + +set_property(TARGET rt_OQD_capi PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET rt_OQD_capi APPEND PROPERTY BUILD_RPATH "$") + +if(NOT APPLE) + set_property(TARGET rt_OQD_capi APPEND PROPERTY BUILD_RPATH $ORIGIN) +else() + set_property(TARGET rt_OQD_capi APPEND PROPERTY BUILD_RPATH @loader_path) +endif() diff --git a/runtime/lib/capi/OQDRuntimeCAPI.cpp b/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp similarity index 96% rename from runtime/lib/capi/OQDRuntimeCAPI.cpp rename to runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp index 068460a767..8ad7867dea 100644 --- a/runtime/lib/capi/OQDRuntimeCAPI.cpp +++ b/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp @@ -14,6 +14,8 @@ #include +#include "RuntimeCAPI.h" + extern "C" { void __catalyst__oqd__greetings() { diff --git a/runtime/lib/capi/CMakeLists.txt b/runtime/lib/capi/CMakeLists.txt index 7162562e2d..e05e9bffee 100644 --- a/runtime/lib/capi/CMakeLists.txt +++ b/runtime/lib/capi/CMakeLists.txt @@ -2,7 +2,7 @@ # Object Lib catalyst_qir_qis_obj ################################## -add_library(catalyst_qir_qis_obj OBJECT RuntimeCAPI.cpp OQDRuntimeCAPI.cpp) +add_library(catalyst_qir_qis_obj OBJECT RuntimeCAPI.cpp) # include external MLIR runner utils FetchContent_MakeAvailable(MLIRRunnerUtils) diff --git a/runtime/tests/CMakeLists.txt b/runtime/tests/CMakeLists.txt index 79f992f12f..a3ff195fae 100644 --- a/runtime/tests/CMakeLists.txt +++ b/runtime/tests/CMakeLists.txt @@ -34,6 +34,7 @@ target_link_libraries(runner_tests_qir_runtime PRIVATE target_sources(runner_tests_qir_runtime PRIVATE Test_NullQubit.cpp + Test_OQD_OpenAPLGeneration.cpp ) catch_discover_tests(runner_tests_qir_runtime) diff --git a/runtime/tests/Test_OQD_OpenAPLGeneration.cpp b/runtime/tests/Test_OQD_OpenAPLGeneration.cpp new file mode 100644 index 0000000000..aca7b30bed --- /dev/null +++ b/runtime/tests/Test_OQD_OpenAPLGeneration.cpp @@ -0,0 +1,22 @@ +// Copyright 2025 Xanadu Quantum Technologies Inc. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "OQDRuntimeCAPI.h" + +#include "TestUtils.hpp" + +TEST_CASE("Test hello world", "[OQD]") +{ + __catalyst__oqd__greetings(); +} From ed42da12bb68ba30132057db0653eb30344a7eb5 Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Fri, 24 Jan 2025 11:37:47 -0500 Subject: [PATCH 05/12] typo --- runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp b/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp index 8ad7867dea..6c5335c0d4 100644 --- a/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp +++ b/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp @@ -14,7 +14,7 @@ #include -#include "RuntimeCAPI.h" +#include "OQDRuntimeCAPI.h" extern "C" { From c0090df166d751bdcb098dc14a8f870f8dca848b Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Fri, 24 Jan 2025 11:47:03 -0500 Subject: [PATCH 06/12] remove extra lines in cmake --- runtime/lib/OQDcapi/CMakeLists.txt | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/runtime/lib/OQDcapi/CMakeLists.txt b/runtime/lib/OQDcapi/CMakeLists.txt index 41437b01ce..91e922b2b7 100644 --- a/runtime/lib/OQDcapi/CMakeLists.txt +++ b/runtime/lib/OQDcapi/CMakeLists.txt @@ -7,15 +7,9 @@ add_library(catalyst_oqd_obj OBJECT OQDRuntimeCAPI.cpp) # link to rt_backend target_link_libraries(catalyst_oqd_obj ${CMAKE_DL_LIBS}) -target_link_libraries(catalyst_oqd_obj - pthread - dl -) - target_include_directories(catalyst_oqd_obj PUBLIC . ${CMAKE_CURRENT_SOURCE_DIR} ${runtime_includes} - ${PROJECT_SOURCE_DIR}/../mlir/lib/Driver # Timer.hpp ) @@ -26,8 +20,6 @@ target_include_directories(catalyst_oqd_obj PUBLIC . add_library(rt_OQD_capi SHARED) target_link_libraries(rt_OQD_capi ${CMAKE_DL_LIBS} catalyst_oqd_obj) -add_dependencies(rt_OQD_capi catalyst_callback_registry) - target_include_directories(rt_OQD_capi PUBLIC . ${CMAKE_CURRENT_SOURCE_DIR} @@ -35,9 +27,6 @@ target_include_directories(rt_OQD_capi PUBLIC . ${capi_utils_includes} ) -set_property(TARGET rt_OQD_capi PROPERTY POSITION_INDEPENDENT_CODE ON) -set_property(TARGET rt_OQD_capi APPEND PROPERTY BUILD_RPATH "$") - if(NOT APPLE) set_property(TARGET rt_OQD_capi APPEND PROPERTY BUILD_RPATH $ORIGIN) else() From 66ff0479a25e43af820a0f0d97e630ce1c11a4c0 Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Fri, 24 Jan 2025 11:48:11 -0500 Subject: [PATCH 07/12] format --- runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp | 6 +----- runtime/tests/Test_OQD_OpenAPLGeneration.cpp | 5 +---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp b/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp index 6c5335c0d4..00b22040c7 100644 --- a/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp +++ b/runtime/lib/OQDcapi/OQDRuntimeCAPI.cpp @@ -18,9 +18,5 @@ extern "C" { -void __catalyst__oqd__greetings() { - std::cout << "Hello OQD world!" << std::endl; -} - - +void __catalyst__oqd__greetings() { std::cout << "Hello OQD world!" << std::endl; } } diff --git a/runtime/tests/Test_OQD_OpenAPLGeneration.cpp b/runtime/tests/Test_OQD_OpenAPLGeneration.cpp index aca7b30bed..a37092158b 100644 --- a/runtime/tests/Test_OQD_OpenAPLGeneration.cpp +++ b/runtime/tests/Test_OQD_OpenAPLGeneration.cpp @@ -16,7 +16,4 @@ #include "TestUtils.hpp" -TEST_CASE("Test hello world", "[OQD]") -{ - __catalyst__oqd__greetings(); -} +TEST_CASE("Test hello world", "[OQD]") { __catalyst__oqd__greetings(); } From 294730a960b6f22d2ff7f070bb4c3de563e8937a Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Fri, 24 Jan 2025 14:52:14 -0500 Subject: [PATCH 08/12] add tests cmake --- runtime/Makefile | 10 +++++++++- runtime/tests/CMakeLists.txt | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/runtime/Makefile b/runtime/Makefile index 3f601de624..41935aceca 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -27,7 +27,7 @@ endif ifeq ($(ENABLE_OQD), ON) BUILD_TARGETS += rt_OQD_capi - #TEST_TARGETS += runner_tests_openqasm + TEST_TARGETS += runner_tests_oqd endif .PHONY: help @@ -76,6 +76,10 @@ ifeq ($(ENABLE_OPENQASM), ON) # Test the OpenQasm devices C++ tests $(ASAN_COMMAND) $(RT_BUILD_DIR)/tests/runner_tests_openqasm endif +ifeq ($(ENABLE_OQD), ON) + # Test the OQD CAPI tests + $(ASAN_COMMAND) $(RT_BUILD_DIR)/tests/runner_tests_oqd +endif .PHONY: coverage coverage: RT_BUILD_DIR := $(RT_BUILD_DIR)_cov @@ -90,6 +94,9 @@ coverage: test_runner ifeq ($(ENABLE_OPENQASM), ON) $(RT_BUILD_DIR)/tests/runner_tests_openqasm endif +ifeq ($(ENABLE_OQD), ON) + $(RT_BUILD_DIR)/tests/runner_tests_oqd +endif ifeq ($(PLATFORM),Linux) lcov --directory $(RT_BUILD_DIR) -b $(MK_DIR)/lib --capture --output-file $(RT_BUILD_DIR)/coverage.info lcov --remove $(RT_BUILD_DIR)/coverage.info '/usr/*' '*/_deps/*' '*/envs/*' '*/mlir/*' --output-file $(RT_BUILD_DIR)/coverage.info @@ -98,6 +105,7 @@ else xcrun llvm-profdata merge $(RT_BUILD_DIR)/tests/*.profraw -o $(RT_BUILD_DIR)/tests/rt_test_coverage.profdata xcrun llvm-cov show -instr-profile $(RT_BUILD_DIR)/tests/rt_test_coverage.profdata \ -object $(RT_BUILD_DIR)/tests/runner_tests_openqasm \ + $(RT_BUILD_DIR)/tests/runner_tests_oqd \ $(RT_BUILD_DIR)/tests/runner_tests_qir_runtime \ -format=html -output-dir=$(RT_BUILD_DIR)/coverage_html \ $(MK_DIR)/include $(MK_DIR)/lib $(MK_DIR)/tests diff --git a/runtime/tests/CMakeLists.txt b/runtime/tests/CMakeLists.txt index a3ff195fae..69e4fd8269 100644 --- a/runtime/tests/CMakeLists.txt +++ b/runtime/tests/CMakeLists.txt @@ -34,7 +34,6 @@ target_link_libraries(runner_tests_qir_runtime PRIVATE target_sources(runner_tests_qir_runtime PRIVATE Test_NullQubit.cpp - Test_OQD_OpenAPLGeneration.cpp ) catch_discover_tests(runner_tests_qir_runtime) @@ -64,3 +63,25 @@ if(ENABLE_OPENQASM) catch_discover_tests(runner_tests_openqasm) endif() + +if(ENABLE_OQD) + add_executable(runner_tests_oqd runner_main.cpp) + if(NOT APPLE) + set_property(TARGET runner_tests_oqd APPEND PROPERTY BUILD_RPATH $ORIGIN) + set_property(TARGET runner_tests_oqd APPEND PROPERTY BUILD_RPATH $ORIGIN/../lib) + else() + set_property(TARGET runner_tests_oqd APPEND PROPERTY BUILD_RPATH @loader_path) + set_property(TARGET runner_tests_oqd APPEND PROPERTY BUILD_RPATH @loader_path/../lib) + endif() + + target_link_libraries(runner_tests_oqd PRIVATE + Catch2::Catch2 + catalyst_qir_runtime + ) + + target_sources(runner_tests_oqd PRIVATE + Test_OQD_OpenAPLGeneration.cpp + ) + + catch_discover_tests(runner_tests_oqd) +endif() From 1afbcfe5231560e181e2ca90600452da72e17fbc Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Fri, 24 Jan 2025 15:07:33 -0500 Subject: [PATCH 09/12] update github action scripts --- .github/workflows/build-wheel-linux-x86_64.yaml | 2 +- .github/workflows/build-wheel-macos-arm64.yaml | 2 +- .github/workflows/build-wheel-macos-x86_64.yaml | 2 +- .github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-wheel-linux-x86_64.yaml b/.github/workflows/build-wheel-linux-x86_64.yaml index a831c9ebb3..be51180187 100644 --- a/.github/workflows/build-wheel-linux-x86_64.yaml +++ b/.github/workflows/build-wheel-linux-x86_64.yaml @@ -325,7 +325,7 @@ jobs: -DPython_EXECUTABLE=$(which python${{ matrix.python_version }}) \ -DENABLE_OPENQASM=ON - cmake --build $GITHUB_WORKSPACE/runtime-build --target rt_capi rtd_openqasm rtd_null_qubit + cmake --build $GITHUB_WORKSPACE/runtime-build --target rt_capi rtd_openqasm rtd_null_qubit rt_OQD_capi # Build OQC-Runtime - name: Build OQC-Runtime diff --git a/.github/workflows/build-wheel-macos-arm64.yaml b/.github/workflows/build-wheel-macos-arm64.yaml index 07178e767d..945bf5bc64 100644 --- a/.github/workflows/build-wheel-macos-arm64.yaml +++ b/.github/workflows/build-wheel-macos-arm64.yaml @@ -306,7 +306,7 @@ jobs: -DPython_EXECUTABLE=$(which python${{ matrix.python_version }}) \ -DENABLE_OPENQASM=ON - cmake --build $GITHUB_WORKSPACE/runtime-build --target rt_capi rtd_openqasm rtd_null_qubit + cmake --build $GITHUB_WORKSPACE/runtime-build --target rt_capi rtd_openqasm rtd_null_qubit rt_OQD_capi - name: Test Catalyst-Runtime run: | diff --git a/.github/workflows/build-wheel-macos-x86_64.yaml b/.github/workflows/build-wheel-macos-x86_64.yaml index 19a3f341f2..4a189bf7a4 100644 --- a/.github/workflows/build-wheel-macos-x86_64.yaml +++ b/.github/workflows/build-wheel-macos-x86_64.yaml @@ -282,7 +282,7 @@ jobs: -DPython_EXECUTABLE=$(which python${{ matrix.python_version }}) \ -DENABLE_OPENQASM=ON - cmake --build $GITHUB_WORKSPACE/runtime-build --target rt_capi rtd_openqasm rtd_null_qubit + cmake --build $GITHUB_WORKSPACE/runtime-build --target rt_capi rtd_openqasm rtd_null_qubit rt_OQD_capi # Build OQC-Runtime - name: Build OQC-Runtime diff --git a/.github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh b/.github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh index 9014e2af81..ec9b2d66d4 100644 --- a/.github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh +++ b/.github/workflows/scripts/linux_arm64/rh8/build_catalyst.sh @@ -43,7 +43,7 @@ cmake -S runtime -B runtime-build -G Ninja \ -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=runtime-build/lib \ -DPython_EXECUTABLE=${PYTHON} \ -DENABLE_OPENQASM=ON -cmake --build runtime-build --target rt_capi rtd_openqasm rtd_null_qubit +cmake --build runtime-build --target rt_capi rtd_openqasm rtd_null_qubit rt_OQD_capi # Build OQC export OQC_BUILD_DIR="/catalyst/oqc-build" From fb9d323f9feacd930f50a34015b319a4d158eff0 Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Fri, 24 Jan 2025 15:14:22 -0500 Subject: [PATCH 10/12] update cmake --- runtime/lib/OQDcapi/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/lib/OQDcapi/CMakeLists.txt b/runtime/lib/OQDcapi/CMakeLists.txt index 91e922b2b7..7f9f48b76b 100644 --- a/runtime/lib/OQDcapi/CMakeLists.txt +++ b/runtime/lib/OQDcapi/CMakeLists.txt @@ -12,6 +12,7 @@ target_include_directories(catalyst_oqd_obj PUBLIC . ${runtime_includes} ) +set_property(TARGET catalyst_oqd_obj PROPERTY POSITION_INDEPENDENT_CODE ON) ##################### # Shared Lib rt_OQD_capi From 76b56dd108fa870eddc2d397cacad362f29c7f3b Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Fri, 24 Jan 2025 15:26:52 -0500 Subject: [PATCH 11/12] is CI actually running the test?? --- runtime/tests/Test_OQD_OpenAPLGeneration.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/tests/Test_OQD_OpenAPLGeneration.cpp b/runtime/tests/Test_OQD_OpenAPLGeneration.cpp index a37092158b..92cb3a120f 100644 --- a/runtime/tests/Test_OQD_OpenAPLGeneration.cpp +++ b/runtime/tests/Test_OQD_OpenAPLGeneration.cpp @@ -16,4 +16,7 @@ #include "TestUtils.hpp" -TEST_CASE("Test hello world", "[OQD]") { __catalyst__oqd__greetings(); } +TEST_CASE("Test hello world", "[OQD]") { + __catalyst__oqd__greetings(); + CHECK(1 == 0); +} From 7260f8ecca273cf271f36ca4fb36cd2e41075378 Mon Sep 17 00:00:00 2001 From: Haochen Wang Date: Mon, 27 Jan 2025 11:20:05 -0500 Subject: [PATCH 12/12] remove 1==0 test --- runtime/tests/Test_OQD_OpenAPLGeneration.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/tests/Test_OQD_OpenAPLGeneration.cpp b/runtime/tests/Test_OQD_OpenAPLGeneration.cpp index 92cb3a120f..63bd7ce33e 100644 --- a/runtime/tests/Test_OQD_OpenAPLGeneration.cpp +++ b/runtime/tests/Test_OQD_OpenAPLGeneration.cpp @@ -18,5 +18,4 @@ TEST_CASE("Test hello world", "[OQD]") { __catalyst__oqd__greetings(); - CHECK(1 == 0); }