Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ORNL Quantum Computing Institute
xacc
Commits
bc3c58bd
Commit
bc3c58bd
authored
Aug 08, 2017
by
Mccaskey, Alex
Browse files
Adding Kernel class, and setting up Program to take a file at construction
parent
06e805b5
Changes
9
Hide whitespace changes
Inline
Side-by-side
impls/dwave/accelerator/DWAccelerator.hpp
View file @
bc3c58bd
...
...
@@ -130,8 +130,8 @@ public:
* so return an empty list, for now.
* @return
*/
virtual
std
::
vector
<
xacc
::
IRTransformation
>
getIRTransformations
()
{
std
::
vector
<
xacc
::
IRTransformation
>
v
;
virtual
std
::
vector
<
std
::
shared_ptr
<
IRTransformation
>
>
getIRTransformations
()
{
std
::
vector
<
std
::
shared_ptr
<
IRTransformation
>
>
v
;
return
v
;
}
...
...
impls/dwave/tests/DWQMICompilerTester.cpp
View file @
bc3c58bd
...
...
@@ -54,7 +54,7 @@ public:
return
true
;
}
virtual
std
::
vector
<
xacc
::
IRTransformation
>
getIRTransformations
()
{
virtual
std
::
vector
<
std
::
shared_ptr
<
xacc
::
IRTransformation
>
>
getIRTransformations
()
{
};
...
...
impls/rigetti/accelerator/RigettiAccelerator.hpp
View file @
bc3c58bd
...
...
@@ -104,8 +104,8 @@ public:
* so return an empty list, for now.
* @return
*/
virtual
std
::
vector
<
xacc
::
IRTransformation
>
getIRTransformations
()
{
std
::
vector
<
xacc
::
IRTransformation
>
v
;
virtual
std
::
vector
<
std
::
shared_ptr
<
IRTransformation
>
>
getIRTransformations
()
{
std
::
vector
<
std
::
shared_ptr
<
IRTransformation
>
>
v
;
return
v
;
}
...
...
impls/simple-simulator/SimpleAccelerator.hpp
View file @
bc3c58bd
...
...
@@ -99,8 +99,8 @@ public:
* so return an empty list
* @return
*/
virtual
std
::
vector
<
xacc
::
IRTransformation
>
getIRTransformations
()
{
std
::
vector
<
xacc
::
IRTransformation
>
v
;
virtual
std
::
vector
<
std
::
shared_ptr
<
IRTransformation
>
>
getIRTransformations
()
{
std
::
vector
<
std
::
shared_ptr
<
IRTransformation
>
>
v
;
return
v
;
}
...
...
quantum/gate/compiler/tests/KernelReplacementPreprocessorTester.cpp
View file @
bc3c58bd
...
...
@@ -112,8 +112,8 @@ public:
}
virtual
std
::
vector
<
IRTransformation
>
getIRTransformations
()
{
std
::
vector
<
IRTransformation
>
ts
;
virtual
std
::
vector
<
std
::
shared_ptr
<
IRTransformation
>
>
getIRTransformations
()
{
std
::
vector
<
std
::
shared_ptr
<
IRTransformation
>
>
ts
;
return
ts
;
}
...
...
xacc/accelerator/Accelerator.hpp
View file @
bc3c58bd
...
...
@@ -102,7 +102,7 @@ public:
*
* @return transformations The IR transformations this Accelerator exposes
*/
virtual
std
::
vector
<
IRTransformation
>
getIRTransformations
()
=
0
;
virtual
std
::
vector
<
std
::
shared_ptr
<
IRTransformation
>
>
getIRTransformations
()
=
0
;
/**
* Execute the provided XACC IR Function on the provided AcceleratorBuffer.
...
...
xacc/program/Kernel.hpp
0 → 100644
View file @
bc3c58bd
#ifndef XACC_PROGRAM_KERNEL_HPP_
#define XACC_PROGRAM_KERNEL_HPP_
#include
"Function.hpp"
namespace
xacc
{
/**
* The Kernel represents an functor to be executed
* on the attached Accelerator.
*/
template
<
typename
...
RuntimeArgs
>
class
Kernel
{
protected:
std
::
shared_ptr
<
Function
>
function
;
std
::
shared_ptr
<
Accelerator
>
accelerator
;
public:
Kernel
(
std
::
shared_ptr
<
Accelerator
>
acc
,
std
::
shared_ptr
<
Function
>
f
)
:
function
(
f
),
accelerator
(
acc
)
{
}
Kernel
(
const
Kernel
&
k
)
:
function
(
k
.
function
),
accelerator
(
k
.
accelerator
)
{}
void
operator
()(
std
::
shared_ptr
<
AcceleratorBuffer
>
buffer
,
RuntimeArgs
...
args
)
{
if
(
sizeof
...(
RuntimeArgs
)
>
0
)
{
// Store the runtime parameters in a tuple
auto
argsTuple
=
std
::
make_tuple
(
args
...);
// Loop through the tuple, and add InstructionParameters
// to the parameters vector.
std
::
vector
<
InstructionParameter
>
parameters
;
xacc
::
tuple_for_each
(
argsTuple
,
[
&
](
auto
value
)
{
parameters
.
push_back
(
InstructionParameter
(
value
));
});
// Evaluate all Variable Parameters
function
->
evaluateVariableParameters
(
parameters
);
}
// Execute the Kernel on the Accelerator
accelerator
->
execute
(
buffer
,
function
);
}
void
prepend
(
const
std
::
shared_ptr
<
Function
>
prependFunction
)
{
function
->
insertInstruction
(
0
,
prependFunction
);
}
};
}
#endif
xacc/program/Program.hpp
View file @
bc3c58bd
/***********************************************************************************
* Copyright (c) 201
6
, UT-Battelle
* Copyright (c) 201
7
, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
...
...
@@ -45,6 +45,7 @@
#include
"RuntimeOptions.hpp"
#include
"Preprocessor.hpp"
#include
"ServiceRegistry.hpp"
#include
"Kernel.hpp"
namespace
xacc
{
...
...
@@ -106,11 +107,34 @@ protected:
*/
std
::
shared_ptr
<
Compiler
>
compiler
;
public:
/**
* The Constructor, takes the Accelerator
* to execute on, and the source to compile and execute
*
* @param acc Attached Accelerator to execute
* @param sourceFile The kernel source code
*/
Program
(
std
::
shared_ptr
<
Accelerator
>
acc
,
const
std
::
string
&
sourceFile
)
:
src
(
sourceFile
),
accelerator
(
std
::
move
(
acc
))
{
}
/**
* The Constructor, takes the Accelerator to execute on,
* and the source kernel string as a stream.
* @param acc Attached Accelerator to execute
* @param stream The file stream containing kernel source code
*/
Program
(
std
::
shared_ptr
<
Accelerator
>
acc
,
std
::
istream
&
stream
)
:
accelerator
(
std
::
move
(
acc
)),
src
(
std
::
istreambuf_iterator
<
char
>
(
stream
),
{
})
{
}
/**
* Execute the compilation mechanism on the provided program
* source kernel code to produce XACC IR that can be executed
* on the attached Accelerator.
*
*/
void
build
()
{
...
...
@@ -145,6 +169,12 @@ protected:
XACCError
(
"Bad source string or something.
\n
"
);
}
// Execute hardware dependent IR Transformations
auto
accTransforms
=
accelerator
->
getIRTransformations
();
for
(
auto
t
:
accTransforms
)
{
xaccIR
=
t
->
transform
(
xaccIR
);
}
// Write the IR to file if the user requests it
if
(
runtimeOptions
->
exists
(
"persist-ir"
))
{
auto
fileStr
=
(
*
runtimeOptions
)[
"persist-ir"
];
...
...
@@ -155,60 +185,44 @@ protected:
return
;
}
public:
/**
* The Constructor, takes the Accelerator
* to execute on, and the source to compile and execute
*
* @param acc Attached Accelerator to execute
* @param sourceFile The kernel source code
*/
Program
(
std
::
shared_ptr
<
Accelerator
>
acc
,
const
std
::
string
&
sourceFile
)
:
src
(
sourceFile
),
accelerator
(
std
::
move
(
acc
))
{
}
/**
* Return an executable version of the
quantum
kernel
* Return an executable version of the kernel
* referenced by the kernelName string.
*
* @param name
* @param args
* @return
* @param name The name of the kernel
* @return kernel The Kernel represented by kernelName
*/
template
<
typename
...
RuntimeArgs
>
std
::
function
<
void
(
std
::
shared_ptr
<
AcceleratorBuffer
>
,
RuntimeArgs
...)
>
getKernel
(
const
std
::
string
&
kernelName
)
{
auto
getKernel
(
const
std
::
string
&
kernelName
)
->
Kernel
<
RuntimeArgs
...
>
{
// Build the kernel with the appropriate compiler
build
();
// Create a lambda that executes the kernel on the Accelerator.
return
std
::
move
([
=
](
std
::
shared_ptr
<
AcceleratorBuffer
>
buffer
,
RuntimeArgs
...
args
)
{
// Get the Function for the Kernel from the IR
auto
kernel
=
xaccIR
->
getKernel
(
kernelName
);
if
(
!
xaccIR
)
{
build
();
}
if
(
sizeof
...(
RuntimeArgs
)
>
0
)
{
// Store the runtime parameters in a tuple
auto
argsTuple
=
std
::
make_tuple
(
args
...);
return
Kernel
<
RuntimeArgs
...
>
(
accelerator
,
xaccIR
->
getKernel
(
kernelName
));
}
// Loop through the tuple, and add InstructionParameters
// to the parameters vector.
std
::
vector
<
InstructionParameter
>
parameters
;
xacc
::
tuple_for_each
(
argsTuple
,
[
&
](
auto
value
)
{
parameters
.
push_back
(
InstructionParameter
(
value
));
});
/**
* Return all Kernels that have sizeof...(RuntimeArgs)
* InstructionParameters.
* @return kernels Kernels with sizeof...(RuntimeArgs) Parameters.
*/
template
<
typename
...
RuntimeArgs
>
auto
getKernels
()
->
std
::
vector
<
Kernel
<
RuntimeArgs
...
>>
{
std
::
vector
<
Kernel
<
RuntimeArgs
...
>>
kernels
;
if
(
!
xaccIR
)
{
build
();
}
// Evaluate all Variable Parameters
kernel
->
evaluateVariableParameters
(
parameters
);
for
(
auto
k
:
xaccIR
->
getKernels
())
{
if
(
k
->
nParameters
()
==
(
sizeof
...(
RuntimeArgs
)))
{
kernels
.
push_back
(
Kernel
<
RuntimeArgs
...
>
(
accelerator
,
k
));
}
}
// Execute the Kernel on the Accelerator
accelerator
->
execute
(
buffer
,
kernel
);
return
;
});
return
kernels
;
}
};
...
...
xacc/utils/CLIParser.hpp
View file @
bc3c58bd
...
...
@@ -72,15 +72,10 @@ public:
(
"persist-ir"
,
value
<
std
::
string
>
(),
"Persist generated IR to provided file name."
)
(
"load"
,
value
<
std
::
string
>
(),
"Load a XACC plugin at the given path"
)
(
"list-compilers"
,
"List all available XACC Compilers"
)
(
"list-accelerators"
,
"List all available XACC Accelerators"
)
(
"verbose-registry"
,
"Print registry actions"
);
(
"list-accelerators"
,
"List all available XACC Accelerators"
);
}
/**
* Parse the command line options. Provide a Boost options_description
* built up and provided by all available OptionsProviders. This
* method also loads all Compilers and Accelerators available
* in the XACC_INSTALL_DIR.
*/
void
parse
(
int
argc
,
char
**
argv
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment