Commit c7bd2c65 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Minor updates and bug fixes



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 2327d5b1
......@@ -88,12 +88,21 @@ class qpu(object):
def __call__(self, f):
def wrapped_f(*args, **kwargs):
if 'accelerator' in self.kwargs:
if isinstance(self.kwargs['accelerator'], Accelerator):
qpu = self.kwargs['accelerator']
else:
qpu = getAccelerator(self.kwargs['accelerator'])
elif hasAccelerator('tnqvm'):
qpu = getAccelerator('tnqvm')
else:
print('\033[1;31mError, no Accelerators installed. We suggest installing TNQVM.\033[0;0m')
# Remove the @qpu line from the source
src = '\n'.join(inspect.getsource(f).split('\n')[1:])
# Get the compiler and compile the code
compiler = getCompiler('xacc-py')
if isinstance(self.kwargs['accelerator'], Accelerator):
qpu = self.kwargs['accelerator']
else:
qpu = getAccelerator(self.kwargs['accelerator'])
ir = compiler.compile(src, qpu)
program = Program(qpu, ir)
compiledKernel = program.getKernels()[0]
......
......@@ -201,7 +201,8 @@ PYBIND11_MODULE(_pyxacc, m) {
"code and the Accelerator instance, and the Program handles compiling the code and provides Kernel instances to execute.")
.def(py::init<std::shared_ptr<xacc::Accelerator>, const std::string &>(), "The constructor")
.def(py::init<std::shared_ptr<xacc::Accelerator>, std::shared_ptr<xacc::IR>>(), "The constructor")
.def("build", &xacc::Program::build, "Compile this program.")
.def("build", (void (xacc::Program::*)(const std::string&)) &xacc::Program::build, "Compile this program with the given Compiler name.")
.def("build", (void (xacc::Program::*)()) &xacc::Program::build, "Compile this program.")
.def("getKernel", (xacc::Kernel<> (xacc::Program::*)(const std::string&)) &xacc::Program::getKernel<>,
py::return_value_policy::reference, "Return a Kernel representing the source code.")
.def("getKernels", &xacc::Program::getRuntimeKernels, "Return all Kernels.")
......@@ -228,6 +229,8 @@ PYBIND11_MODULE(_pyxacc, m) {
"Return the IRGenerator of given name.");
m.def("setOption", &xacc::setOption, "Set an XACC framework option.");
m.def("getOption", &xacc::getOption, "Get an XACC framework option.");
m.def("hasAccelerator", &xacc::hasAccelerator, "Does XACC have the given Accelerator installed?");
m.def("hasCompiler", &xacc::hasCompiler, "Does XACC have the given Accelerator installed?");
m.def("optionExists", &xacc::optionExists, "Set an XACC framework option.");
m.def("Finalize", &xacc::Finalize, "Finalize the framework");
......
......@@ -49,13 +49,13 @@ void Program::addIRPreprocessor(const std::string& name) {
}
}
void Program::build() {
void Program::build(const std::string& compilerName) {
// Get reference to the runtime options
auto runtimeOptions = RuntimeOptions::instance();
// Get the compiler that has been requested.
auto compilerToRun = (*runtimeOptions)["compiler"];
auto compilerToRun = compilerName.empty() ?
(*runtimeOptions)["compiler"] : compilerName;
// Create the appropriate compiler
compiler = xacc::getService<Compiler>(compilerToRun);
......@@ -104,6 +104,10 @@ void Program::build() {
xaccIR->persist(ostr);
}
}
void Program::build() {
build("");
return;
}
......
......@@ -140,7 +140,8 @@ public:
* on the attached Accelerator.
*/
virtual void build();
virtual void build(const std::string& compiler);
/**
* Return the number of Kernels in this Program's XACC IR.
*
......
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