Commit 90539eb8 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Adding XACC runtime library, moving it from header only setup. Fixing bug...

Adding XACC runtime library, moving it from header only setup. Fixing bug related to multiple inclusions of XACC.hpp
parent d7333bad
......@@ -2,5 +2,5 @@ set (XACC_ROOT "@CMAKE_INSTALL_PREFIX@")
set (XACC_INCLUDE_DIRS "@CppMicroServices_INCLUDE_DIR@;@CMAKE_INSTALL_PREFIX@/include;@CMAKE_INSTALL_PREFIX@/include/xacc;@CMAKE_INSTALL_PREFIX@/include/quantum/gate;@CMAKE_INSTALL_PREFIX@/include/quantum/aqc")
set (XACC_LIBRARY_DIR "@CMAKE_INSTALL_PREFIX@/lib")
set (XACC_LIBRARY_DIRS "@CMAKE_INSTALL_PREFIX@/lib;@CppMicroServices_LIBRARY_DIR@")
set (XACC_LIBRARIES "@CMAKE_INSTALL_PREFIX@/lib/libxacc-quantum-gate.so;@CMAKE_INSTALL_PREFIX@/lib/libxacc-quantum-aqc.so;CppMicroServices")
set (XACC_LIBRARIES "@CMAKE_INSTALL_PREFIX@/lib/libxacc.so;@CMAKE_INSTALL_PREFIX@/lib/libxacc-quantum-gate.so;@CMAKE_INSTALL_PREFIX@/lib/libxacc-quantum-aqc.so;CppMicroServices")
find_package(CppMicroServices NO_MODULE REQUIRED)
\ No newline at end of file
......@@ -29,6 +29,6 @@
#
#**********************************************************************************/
add_executable(dwave-simple-example dwave-simple-example.cpp)
target_link_libraries(dwave-simple-example ${Boost_LIBRARIES} dl CppMicroServices xacc-quantum-aqc)
target_link_libraries(dwave-simple-example ${Boost_LIBRARIES} xacc dl CppMicroServices xacc-quantum-aqc)
install(TARGETS dwave-simple-example DESTINATION examples)
......@@ -30,18 +30,18 @@
#**********************************************************************************/
if (TARGET xacc-scaffold)
add_executable(teleport_scaffold_rigetti teleport_scaffold_rigetti.cpp)
target_link_libraries(teleport_scaffold_rigetti ${Boost_LIBRARIES} CppMicroServices dl)
target_link_libraries(teleport_scaffold_rigetti ${Boost_LIBRARIES} xacc CppMicroServices dl)
add_executable(qft_scaffold_rigetti qft_scaffold_rigetti.cpp)
target_link_libraries(qft_scaffold_rigetti ${Boost_LIBRARIES} CppMicroServices dl)
target_link_libraries(qft_scaffold_rigetti ${Boost_LIBRARIES} xacc CppMicroServices dl)
add_executable(h2_exp_vals_scaffold_rigetti h2_exp_vals_scaffold_rigetti.cpp)
target_link_libraries(h2_exp_vals_scaffold_rigetti ${Boost_LIBRARIES} CppMicroServices dl)
target_link_libraries(h2_exp_vals_scaffold_rigetti ${Boost_LIBRARIES} xacc CppMicroServices dl)
install(TARGETS teleport_scaffold_rigetti DESTINATION examples)
add_executable(rabi_qpu_experiment rabi_qpu_experiment.cpp)
target_link_libraries(rabi_qpu_experiment ${Boost_LIBRARIES} CppMicroServices dl)
target_link_libraries(rabi_qpu_experiment ${Boost_LIBRARIES} xacc CppMicroServices dl)
install(TARGETS rabi_qpu_experiment DESTINATION examples)
endif()
......@@ -31,13 +31,13 @@
if (TARGET xacc-scaffold)
add_executable(teleport_scaffold_simpleaccelerator teleport_scaffold_simpleaccelerator.cpp)
target_link_libraries(teleport_scaffold_simpleaccelerator ${Boost_LIBRARIES} CppMicroServices dl)
target_link_libraries(teleport_scaffold_simpleaccelerator xacc ${Boost_LIBRARIES} CppMicroServices dl)
add_executable(qft_scaffold_simpleaccelerator qft_scaffold_simpleaccelerator.cpp)
target_link_libraries(qft_scaffold_simpleaccelerator ${Boost_LIBRARIES} CppMicroServices dl)
target_link_libraries(qft_scaffold_simpleaccelerator xacc ${Boost_LIBRARIES} CppMicroServices dl)
add_executable(single_qubit_rotation single_qubit_rotation.cpp)
target_link_libraries(single_qubit_rotation ${Boost_LIBRARIES} CppMicroServices dl)
target_link_libraries(single_qubit_rotation xacc ${Boost_LIBRARIES} CppMicroServices dl)
install(TARGETS single_qubit_rotation DESTINATION examples)
install(TARGETS teleport_scaffold_simpleaccelerator DESTINATION examples)
......
......@@ -33,6 +33,10 @@ set (PACKAGE_DESCIPTION "The XACC Programming Framework")
set (LIBRARY_NAME xacc)
file (GLOB HEADERS program/*.hpp XACC.hpp ir/*.hpp program/*.hpp compiler/*.hpp accelerator/*.hpp utils/*.hpp)
file (GLOB SRC *.cpp)
add_library(${LIBRARY_NAME} SHARED ${SRC})
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} CppMicroServices)
# Get the test files
file(GLOB test_files utils/tests/*Tester.cpp)
......@@ -41,3 +45,4 @@ file(GLOB test_files utils/tests/*Tester.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}/utils" "${Boost_LIBRARIES}")
install(FILES ${HEADERS} DESTINATION include/xacc)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
/***********************************************************************************
* Copyright (c) 2017, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
#include "XACC.hpp"
namespace xacc {
bool xaccFrameworkInitialized = false;
std::shared_ptr<CLIParser> xaccCLParser = std::make_shared<CLIParser>();
/**
* This method should be called by
* clients to initialize the XACC framework.
* It should be called before using any of the
* XACC API.
*/
void Initialize(int argc, char** argv) {
auto tmpInitConsole = spdlog::stdout_logger_mt("xacc-console");
XACCInfo("[xacc] Initializing XACC Framework");
auto serviceRegistry = xacc::ServiceRegistry::instance();
// Parse any user-supplied command line options
xaccCLParser->parse(argc, argv);
// Check that we have some
auto s = serviceRegistry->getServices<Compiler>().size();
auto a = serviceRegistry->getServices<Accelerator>().size();
if (s == 0)
XACCError("There are no Compiler instances available. Exiting.");
if (a == 0)
XACCError("There are no Accelerator instances available. Exiting.");
XACCInfo(
"[xacc::compiler] XACC has " + std::to_string(s) + " Compiler"
+ ((s == 1 || s == 0) ? "" : "s") + " available.");
XACCInfo(
"[xacc::accelerator] XACC has " + std::to_string(a) + " Accelerator"
+ ((s == 0 || s == 1) ? "" : "s") + " available.");
// We're good if we make it here, so indicate that we've been
// initialized
xacc::xaccFrameworkInitialized = true;
}
void addCommandLineOption(const std::string& optionName,
const std::string& optionDescription) {
xaccCLParser->addStringOption(optionName, optionDescription);
}
std::shared_ptr<Accelerator> getAccelerator(const std::string& name) {
if (!xacc::xaccFrameworkInitialized) {
XACCError(
"XACC not initialized before use. Please execute "
"xacc::Initialize() before using API.");
}
auto acc = ServiceRegistry::instance()->getService<Accelerator>(name);
if (acc) {
acc->initialize();
return acc;
} else {
XACCError(
"Invalid Accelerator. Could not find " + name
+ " in Accelerator Registry.");
}
}
std::shared_ptr<Compiler> getCompiler(const std::string& name) {
if (!xacc::xaccFrameworkInitialized) {
XACCError(
"XACC not initialized before use. Please execute "
"xacc::Initialize() before using API.");
}
auto c = ServiceRegistry::instance()->getService<Compiler>(name);
if (c) {
return c;
} else {
XACCError(
"Invalid Compiler. Could not find " + name
+ " in Service Registry.");
}
}
std::shared_ptr<IRTransformation> getIRTransformations(
const std::string& name) {
if (!xacc::xaccFrameworkInitialized) {
XACCError(
"XACC not initialized before use. Please execute "
"xacc::Initialize() before using API.");
}
auto t = ServiceRegistry::instance()->getService<IRTransformation>(name);
if (t) {
return t;
} else {
XACCError(
"Invalid IRTransformation. Could not find " + name
+ " in Service Registry.");
}
}
/**
* This method should be called by clients to
* clean up and finalize the XACC framework. It should
* be called after using the XACC API.
*/
void Finalize() {
XACCInfo(
"\n[xacc] XACC Finalizing\n[xacc::compiler] Cleaning up Compiler Registry."
"\n[xacc::accelerator] Cleaning up Accelerator Registry.");
xacc::ServiceRegistry::instance()->destroy();
xacc::xaccFrameworkInitialized = false;
}
}
......@@ -39,13 +39,15 @@
#include "CLIParser.hpp"
#include "Program.hpp"
#include "Preprocessor.hpp"
#include "ServiceRegistry.hpp"
namespace xacc {
bool xaccFrameworkInitialized = false;
auto xaccCLParser = std::make_shared<CLIParser>();
// Boolean indicating that framework has been initialized
extern bool xaccFrameworkInitialized;
// Reference to the command line parser
extern std::shared_ptr<CLIParser> xaccCLParser;
/**
* This method should be called by
......@@ -53,66 +55,36 @@ auto xaccCLParser = std::make_shared<CLIParser>();
* It should be called before using any of the
* XACC API.
*/
void Initialize(int argc, char** argv) {
auto tmpInitConsole = spdlog::stdout_logger_mt("xacc-console");
XACCInfo("[xacc] Initializing XACC Framework");
auto serviceRegistry = xacc::ServiceRegistry::instance();
// Parse any user-supplied command line options
xaccCLParser->parse(argc, argv);
void Initialize(int argc, char** argv);
// Check that we have some
auto s = serviceRegistry->getServices<Compiler>().size();
auto a = serviceRegistry->getServices<Accelerator>().size();
if (s == 0) XACCError("There are no Compiler instances available. Exiting.");
if (a == 0) XACCError("There are no Accelerator instances available. Exiting.");
XACCInfo(
"[xacc::compiler] XACC has " + std::to_string(s) + " Compiler"
+ ((s == 1 || s == 0) ? "" : "s") + " available.");
XACCInfo(
"[xacc::accelerator] XACC has " + std::to_string(a) + " Accelerator"
+ ((s == 0 || s == 1) ? "" : "s") + " available.");
/**
* Add a valid command line option
*/
void addCommandLineOption(const std::string& optionName,
const std::string& optionDescription = "");
// We're good if we make it here, so indicate that we've been
// initialized
xacc::xaccFrameworkInitialized = true;
}
/**
* Return the Accelerator with given name
*/
std::shared_ptr<Accelerator> getAccelerator(const std::string& name);
void addCommandLineOption(const std::string& optionName, const std::string& optionDescription = "") {
xaccCLParser->addStringOption(optionName, optionDescription);
}
/**
* Return the Compiler with given name
*/
std::shared_ptr<Compiler> getCompiler(const std::string& name);
std::shared_ptr<Accelerator> getAccelerator(const std::string& name) {
if (!xacc::xaccFrameworkInitialized) {
XACCError(
"XACC not initialized before use. Please execute xacc::Initialize() before using API.");
}
auto acc = ServiceRegistry::instance()->getService<Accelerator>(name);
if (acc) {
acc->initialize();
return acc;
} else {
XACCError(
"Invalid Accelerator. Could not find " + name
+ " in Accelerator Registry.");
}
}
/*
* Return the IRTransformation with given name
*/
std::shared_ptr<IRTransformation> getIRTransformation(const std::string& name);
/**
* This method should be called by clients to
* clean up and finalize the XACC framework. It should
* be called after using the XACC API.
*/
void Finalize() {
XACCInfo(
"\n[xacc] XACC Finalizing\n[xacc::compiler] Cleaning up Compiler Registry."
"\n[xacc::accelerator] Cleaning up Accelerator Registry.");
xacc::ServiceRegistry::instance()->destroy();
xacc::xaccFrameworkInitialized = false;
}
void Finalize();
}
......
......@@ -48,8 +48,6 @@ namespace xacc {
*/
class IR {
protected:
public:
/**
......@@ -60,7 +58,8 @@ public:
* @param accBufferVarName The name of the AcceleratorBuffer
* @return
*/
virtual std::string toAssemblyString(const std::string& kernelName, const std::string& accBufferVarName) = 0;
virtual std::string toAssemblyString(const std::string& kernelName,
const std::string& accBufferVarName) = 0;
/**
* Persist this IR instance to the given
......
......@@ -184,7 +184,7 @@ public:
build();
// Create a lambda that executes the kernel on the Accelerator.
return [=](std::shared_ptr<AcceleratorBuffer> buffer, RuntimeArgs... args) {
return std::move([=](std::shared_ptr<AcceleratorBuffer> buffer, RuntimeArgs... args) {
// Get the Function for the Kernel from the IR
auto kernel = xaccIR->getKernel(kernelName);
......@@ -208,7 +208,7 @@ public:
accelerator->execute(buffer, kernel);
return;
};
});
}
};
......
......@@ -102,7 +102,8 @@ protected:
for (boost::filesystem::directory_iterator itr(xaccLibPath);
itr != end_itr; ++itr) {
auto p = itr->path();
if (p.extension() == ".so" || p.extension() == ".a") {
if ((p.extension() == ".so" || p.extension() == ".a")
&& (p.filename().string() != "libxacc.so")) {
context.InstallBundles(p.string());
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment