Loading examples/qsharp/FTQC/RefCounting/driver.cpp 0 → 100644 +38 −0 Original line number Diff line number Diff line #include <iostream> #include <vector> #include "qir-types-utils.hpp" // Include the external QSharp function. qcor_include_qsharp(QCOR__TestKernel__body, ::Array*); qcor_include_qsharp(QCOR__TestClean__body, void); // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor -qrt ftqc kernel.qs driver.cpp // Run with: // $ ./a.out int main() { // Kernel that clean-up all allocated objects. QCOR__TestClean__body(); // No leak expected. assert(!qcor::internal::AllocationTracker::get().checkLeak()); // This kernel returns an Array, // (allocated in the kernel body) auto test = QCOR__TestKernel__body(); const auto resultVec = qcor::qir::fromArray<double>(test); // Should detect a leak. assert(qcor::internal::AllocationTracker::get().checkLeak()); for (const auto &el : resultVec) { std::cout << el << "\n"; } // Release the ref-count of the returned array. // This should dealloc the Array test->release_ref(); // No leak expected. assert(!qcor::internal::AllocationTracker::get().checkLeak()); return 0; } No newline at end of file examples/qsharp/FTQC/RefCounting/kernel.qs 0 → 100644 +20 −0 Original line number Diff line number Diff line namespace QCOR { operation TestClean() : Unit { // Arrays let test1 = [1.0, 2.0]; let test2 = [1, 2, 3, 4]; // Tuples let test4 = (1.0, [2, 3, 4]); } operation TestKernel() : Double[] { // Arrays let test1 = [1.0, 2.0]; let test2 = [1, 2, 3, 4]; // Tuples let test4 = (1.0, [2, 3, 4]); // Return an array return [5.0, 6.0, 7.0]; } } No newline at end of file mlir/qir_qrt/CMakeLists.txt +14 −0 Original line number Diff line number Diff line file(GLOB SRC *.cpp) file(GLOB HEADERS qir-types.hpp qir-qrt.hpp qir-types-utils.hpp) set(LIBRARY_NAME qir-qrt) add_library(qir-qrt SHARED ${SRC}) #target_include_directories( # qir-qrt # PUBLIC . ${CMAKE_SOURCE_DIR}/runtime/qrt ${XACC_ROOT}/include/cppmicroservices4 ${XACC_ROOT}/include/xacc ${XACC_ROOT}/include/qcor ${XACC_ROOT}/include/eigen ${XACC_ROOT}/include/quantum/gate) target_link_libraries(qir-qrt PRIVATE xacc::xacc qcor qrt) if(APPLE) set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "@loader_path;${CMAKE_INSTALL_PREFIX}/lib;${XACC_ROOT}/lib") set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") else() set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib:${XACC_ROOT}/lib") set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared") endif() install (TARGETS qir-qrt DESTINATION lib) install(FILES ${HEADERS} DESTINATION include/qcor) Loading mlir/qir_qrt/qir-qrt.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -429,12 +429,12 @@ bool __quantum__rt__result_equal(Result *res, Result *comp) { Result *__quantum__rt__result_get_one() { return ResultOne; } Result *__quantum__rt__result_get_zero() { return ResultZero; } void __quantum__rt__string_update_reference_count(void *str, int64_t count) { void __quantum__rt__string_update_reference_count(void *str, int32_t count) { // TODO if (verbose) std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n"; } void __quantum__rt__result_update_reference_count(Result *, int64_t count) { void __quantum__rt__result_update_reference_count(Result *, int32_t count) { // TODO if (verbose) std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n"; } mlir/qir_qrt/qir-qrt.hpp +4 −4 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ void __quantum__qis__u3(double theta, double phi, double lambda, Qubit *q); Result *__quantum__qis__mz(Qubit *q); // Compare results. bool __quantum__rt__result_equal(Result *res, Result *comp); void __quantum__rt__result_update_reference_count(Result *, int64_t count); void __quantum__rt__result_update_reference_count(Result *, int32_t count); // Get reference Result. Result *__quantum__rt__result_get_one(); Result *__quantum__rt__result_get_zero(); Loading Loading @@ -105,8 +105,8 @@ Array *__quantum__rt__array_slice(Array *array, int32_t dim, Array *quantum__rt__array_slice(Array *array, int32_t dim, Range range); // Ref. counting void __quantum__rt__array_update_alias_count(Array *array, int64_t increment); void __quantum__rt__array_update_reference_count(Array *aux, int64_t count); void __quantum__rt__array_update_alias_count(Array *array, int32_t increment); void __quantum__rt__array_update_reference_count(Array *aux, int32_t count); // Multi-dimension Array API int32_t __quantum__rt__array_get_dim(Array *array); Loading @@ -122,7 +122,7 @@ int8_t *__quantum__rt__array_get_element_ptr(Array *array, ...); Array *__quantum__rt__array_project(Array *array, int dim, int64_t index); // String-related API void __quantum__rt__string_update_reference_count(void *str, int64_t count); void __quantum__rt__string_update_reference_count(void *str, int32_t count); // Tuples: TuplePtr __quantum__rt__tuple_create(int64_t size); Loading Loading
examples/qsharp/FTQC/RefCounting/driver.cpp 0 → 100644 +38 −0 Original line number Diff line number Diff line #include <iostream> #include <vector> #include "qir-types-utils.hpp" // Include the external QSharp function. qcor_include_qsharp(QCOR__TestKernel__body, ::Array*); qcor_include_qsharp(QCOR__TestClean__body, void); // Compile with: // Include both the qsharp source and this driver file // in the command line. // $ qcor -qrt ftqc kernel.qs driver.cpp // Run with: // $ ./a.out int main() { // Kernel that clean-up all allocated objects. QCOR__TestClean__body(); // No leak expected. assert(!qcor::internal::AllocationTracker::get().checkLeak()); // This kernel returns an Array, // (allocated in the kernel body) auto test = QCOR__TestKernel__body(); const auto resultVec = qcor::qir::fromArray<double>(test); // Should detect a leak. assert(qcor::internal::AllocationTracker::get().checkLeak()); for (const auto &el : resultVec) { std::cout << el << "\n"; } // Release the ref-count of the returned array. // This should dealloc the Array test->release_ref(); // No leak expected. assert(!qcor::internal::AllocationTracker::get().checkLeak()); return 0; } No newline at end of file
examples/qsharp/FTQC/RefCounting/kernel.qs 0 → 100644 +20 −0 Original line number Diff line number Diff line namespace QCOR { operation TestClean() : Unit { // Arrays let test1 = [1.0, 2.0]; let test2 = [1, 2, 3, 4]; // Tuples let test4 = (1.0, [2, 3, 4]); } operation TestKernel() : Double[] { // Arrays let test1 = [1.0, 2.0]; let test2 = [1, 2, 3, 4]; // Tuples let test4 = (1.0, [2, 3, 4]); // Return an array return [5.0, 6.0, 7.0]; } } No newline at end of file
mlir/qir_qrt/CMakeLists.txt +14 −0 Original line number Diff line number Diff line file(GLOB SRC *.cpp) file(GLOB HEADERS qir-types.hpp qir-qrt.hpp qir-types-utils.hpp) set(LIBRARY_NAME qir-qrt) add_library(qir-qrt SHARED ${SRC}) #target_include_directories( # qir-qrt # PUBLIC . ${CMAKE_SOURCE_DIR}/runtime/qrt ${XACC_ROOT}/include/cppmicroservices4 ${XACC_ROOT}/include/xacc ${XACC_ROOT}/include/qcor ${XACC_ROOT}/include/eigen ${XACC_ROOT}/include/quantum/gate) target_link_libraries(qir-qrt PRIVATE xacc::xacc qcor qrt) if(APPLE) set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "@loader_path;${CMAKE_INSTALL_PREFIX}/lib;${XACC_ROOT}/lib") set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") else() set_target_properties(${LIBRARY_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib:${XACC_ROOT}/lib") set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-shared") endif() install (TARGETS qir-qrt DESTINATION lib) install(FILES ${HEADERS} DESTINATION include/qcor) Loading
mlir/qir_qrt/qir-qrt.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -429,12 +429,12 @@ bool __quantum__rt__result_equal(Result *res, Result *comp) { Result *__quantum__rt__result_get_one() { return ResultOne; } Result *__quantum__rt__result_get_zero() { return ResultZero; } void __quantum__rt__string_update_reference_count(void *str, int64_t count) { void __quantum__rt__string_update_reference_count(void *str, int32_t count) { // TODO if (verbose) std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n"; } void __quantum__rt__result_update_reference_count(Result *, int64_t count) { void __quantum__rt__result_update_reference_count(Result *, int32_t count) { // TODO if (verbose) std::cout << "CALL: " << __PRETTY_FUNCTION__ << "\n"; }
mlir/qir_qrt/qir-qrt.hpp +4 −4 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ void __quantum__qis__u3(double theta, double phi, double lambda, Qubit *q); Result *__quantum__qis__mz(Qubit *q); // Compare results. bool __quantum__rt__result_equal(Result *res, Result *comp); void __quantum__rt__result_update_reference_count(Result *, int64_t count); void __quantum__rt__result_update_reference_count(Result *, int32_t count); // Get reference Result. Result *__quantum__rt__result_get_one(); Result *__quantum__rt__result_get_zero(); Loading Loading @@ -105,8 +105,8 @@ Array *__quantum__rt__array_slice(Array *array, int32_t dim, Array *quantum__rt__array_slice(Array *array, int32_t dim, Range range); // Ref. counting void __quantum__rt__array_update_alias_count(Array *array, int64_t increment); void __quantum__rt__array_update_reference_count(Array *aux, int64_t count); void __quantum__rt__array_update_alias_count(Array *array, int32_t increment); void __quantum__rt__array_update_reference_count(Array *aux, int32_t count); // Multi-dimension Array API int32_t __quantum__rt__array_get_dim(Array *array); Loading @@ -122,7 +122,7 @@ int8_t *__quantum__rt__array_get_element_ptr(Array *array, ...); Array *__quantum__rt__array_project(Array *array, int dim, int64_t index); // String-related API void __quantum__rt__string_update_reference_count(void *str, int64_t count); void __quantum__rt__string_update_reference_count(void *str, int32_t count); // Tuples: TuplePtr __quantum__rt__tuple_create(int64_t size); Loading