QCOR
xacc_internal_compiler.hpp
1 /*******************************************************************************
2  * Copyright (c) 2020 UT-Battelle, LLC.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and Eclipse Distribution License v1.0 which accompanies this
6  * distribution. The Eclipse Public License is available at
7  * http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution
8  *License is available at https://eclipse.org/org/documents/edl-v10.php
9  *
10  * Contributors:
11  * Alexander J. McCaskey - initial API and implementation
12  *******************************************************************************/
13 #ifndef XACC_XACC_INTERNAL_COMPILER_HPP_
14 #define XACC_XACC_INTERNAL_COMPILER_HPP_
15 
16 #include <vector>
17 #include <memory>
18 
19 namespace xacc {
20 class CompositeInstruction;
21 class AcceleratorBuffer;
22 class Accelerator;
23 
24 namespace internal_compiler {
25 extern std::shared_ptr<Accelerator> qpu;
26 extern std::shared_ptr<CompositeInstruction> lastCompiled;
27 extern bool __execute;
28 
29 enum OptLevel { DEFAULT, LEVEL1, LEVEL2, LEVEL3 };
30 
31 void compiler_InitializeXACC(const char *qpu_backend = "qpp",
32  const std::vector<std::string> cmd_line_args = {});
33 void compiler_InitializeXACC(const char *qpu_backend, int shots);
34 
35 void setAccelerator(const char *qpu_backend);
36 void setAccelerator(const char *qpu_backend, int shots);
37 std::shared_ptr<Accelerator> get_qpu();
38 
39 void __set_verbose(bool verbose);
40 
41 // Map kernel source string representing a single
42 // kernel function to a single CompositeInstruction (src to IR)
43 std::shared_ptr<CompositeInstruction> compile(const char *compiler_name,
44  const char *kernel_src);
45 
46 std::shared_ptr<CompositeInstruction> getLastCompiled();
47 std::shared_ptr<CompositeInstruction> getCompiled(const char *kernel_name);
48 
49 // Run quantum compilation routines on IR
50 void optimize(std::shared_ptr<CompositeInstruction> program,
51  const OptLevel opt = DEFAULT);
52 
53 // Execute on the specified QPU, persisting results to
54 // the provided buffer.
55 void execute(AcceleratorBuffer *buffer,
56  std::vector<std::shared_ptr<CompositeInstruction>> programs);
57 void execute(AcceleratorBuffer *buffer,
58  std::shared_ptr<CompositeInstruction> program,
59  double *parameters = nullptr);
60 void execute(AcceleratorBuffer **buffers, const int nBuffers,
61  std::shared_ptr<CompositeInstruction> program,
62  double *parameters = nullptr);
63 } // namespace internal_compiler
64 } // namespace xacc
65 
66 #endif