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
4f2ceafc
Commit
4f2ceafc
authored
Jul 01, 2019
by
Mccaskey, Alex
Browse files
fixing a few bugs
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
56f1c5a8
Pipeline
#61779
passed with stages
in 10 minutes and 26 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tools/compiler/clang/KernelVisitor.cpp
View file @
4f2ceafc
...
...
@@ -117,7 +117,9 @@ bool KernelVisitor::VisitFunctionDecl(FunctionDecl *F) {
", std::shared_ptr<xacc::Observable> obs)"
);
}
else
{
if
(
F
->
getAttrs
().
size
()
>
1
)
replacement
+=
"function = function->operator()(params);
\n
"
;
if
(
F
->
getNumParams
()
>
1
)
{
replacement
+=
"function = function->operator()(params);
\n
"
;
}
replacement
+=
"acc->execute("
+
bufferName
+
",function);
\n
"
;
}
replacement
+=
"}
\n
"
;
...
...
tools/compiler/clang/XACCASTConsumer.cpp
View file @
4f2ceafc
...
...
@@ -16,23 +16,28 @@ XACCASTConsumer::XACCASTConsumer(CompilerInstance &c, Rewriter &rw)
c
.
getASTContext
())),
rewriter
(
rw
)
{}
bool
XACCASTConsumer
::
HandleTopLevelDecl
(
DeclGroupRef
DR
)
{
using
namespace
std
::
chrono
;
auto
start
=
std
::
chrono
::
high_resolution_clock
::
now
();
KernelVisitor
visitor
(
ci
,
rewriter
);
for
(
DeclGroupRef
::
iterator
b
=
DR
.
begin
(),
e
=
DR
.
end
();
b
!=
e
;
++
b
)
{
// if (std::string((*b)->getDeclKindName()) == "Function") {
// std::cout << (*b)->getDeclKindName() << "\n";
// (*b)->dumpColor();
visitor
.
TraverseDecl
(
*
b
);
// }
void
XACCASTConsumer
::
HandleTranslationUnit
(
ASTContext
&
ctx
)
{
KernelVisitor
visitor
(
ci
,
rewriter
);
visitor
.
TraverseDecl
(
ctx
.
getTranslationUnitDecl
());
}
auto
stop
=
std
::
chrono
::
high_resolution_clock
::
now
();
auto
duration
=
std
::
chrono
::
duration_cast
<
microseconds
>
(
stop
-
start
);
// std::cout << "Visitor time: " << duration.count() << ", " << std::endl;
return
true
;
}
// bool XACCASTConsumer::HandleTopLevelDecl(DeclGroupRef DR) {
// using namespace std::chrono;
// auto start = std::chrono::high_resolution_clock::now();
// KernelVisitor visitor(ci, rewriter);
// for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) {
// // if (std::string((*b)->getDeclKindName()) == "Function") {
// // std::cout << (*b)->getDeclKindName() << "\n";
// // (*b)->dumpColor();
// visitor.TraverseDecl(*b);
// // }
// }
// auto stop = std::chrono::high_resolution_clock::now();
// auto duration = std::chrono::duration_cast<microseconds>(stop - start);
// // std::cout << "Visitor time: " << duration.count() << ", " << std::endl;
// return true;
// }
}
// namespace compiler
}
// namespace xacc
\ No newline at end of file
tools/compiler/clang/XACCASTConsumer.hpp
View file @
4f2ceafc
...
...
@@ -17,7 +17,8 @@ class XACCASTConsumer : public ASTConsumer {
public:
XACCASTConsumer
(
CompilerInstance
&
c
,
Rewriter
&
rw
);
bool
HandleTopLevelDecl
(
DeclGroupRef
DR
)
override
;
// bool HandleTopLevelDecl(DeclGroupRef DR) override;
void
HandleTranslationUnit
(
ASTContext
&
ctx
)
override
;
private:
CompilerInstance
&
ci
;
...
...
tools/compiler/clang/XACCPragmaHandler.hpp
View file @
4f2ceafc
...
...
@@ -15,19 +15,6 @@ using namespace clang;
namespace
xacc
{
namespace
compiler
{
class
XACCPragmaHandler
:
public
PragmaHandler
{
protected:
// Rewriter &rewriter;
struct
XACCPragmaAttributeInfo
{
// enum ActionType { Push, Pop, Attribute };
// ParsedAttributes &Attributes;
// ActionType Action;
const
IdentifierInfo
*
Namespace
=
nullptr
;
ArrayRef
<
Token
>
Tokens
;
// PragmaAttributeInfo(ParsedAttributes &Attributes) :
// Attributes(Attributes) {}
};
public:
...
...
@@ -35,14 +22,34 @@ public:
std
::
string
functionName
=
""
;
XACCPragmaHandler
()
:
PragmaHandler
(
"xacc"
)
{}
// XACCPragmaHandler(Rewriter &r) : PragmaHandler("xacc"), rewriter(r) {}
void
HandlePragma
(
Preprocessor
&
PP
,
PragmaIntroducer
Introducer
,
Token
&
FirstTok
)
override
{
// #pragma xacc observe hamiltonian
// std::cout << "XACC HANDLING PRAGMA:\n";
Token
Tok
;
std
::
stringstream
ss
;
int
found
=
0
;
std
::
string
declaration
;
while
(
!
Tok
.
is
(
tok
::
eod
))
{
PP
.
Lex
(
Tok
);
if
(
PP
.
getSpelling
(
Tok
)
==
"observe"
)
{
PP
.
Lex
(
Tok
);
observable
=
PP
.
getSpelling
(
Tok
);
}
}
// This is the Function name we want!!!
PP
.
Lex
(
Tok
);
functionName
=
PP
.
getSpelling
(
Tok
);
PP
.
EnterToken
(
Tok
,
false
);
}
};
}
// namespace compiler
}
// namespace xacc
#endif
// // first slurp the directive content in a string.
// std::ostringstream MyAnnotateDirective;
// while(Tok.isNot(tok::eod)) {
...
...
@@ -107,31 +114,3 @@ public:
// int found = -1;
// // auto sl = FirstTok.getLocation();
// // sl.dump(PP.getSourceManager());
std
::
stringstream
ss
;
int
found
=
0
;
std
::
string
declaration
;
// // FirstTok.getAnnotationRange().dump(PP.getSourceManager());
while
(
!
Tok
.
is
(
tok
::
eod
))
{
PP
.
Lex
(
Tok
);
if
(
PP
.
getSpelling
(
Tok
)
==
"observe"
)
{
PP
.
Lex
(
Tok
);
observable
=
PP
.
getSpelling
(
Tok
);
}
}
// This is the Function name we want!!!
PP
.
Lex
(
Tok
);
functionName
=
PP
.
getSpelling
(
Tok
);
// std::cout << "SS: "<< functionName<< "\n";
PP
.
EnterToken
(
Tok
,
false
);
}
};
}
// namespace compiler
}
// namespace xacc
// static PragmaHandlerRegistry::Add<xacc::compiler::XACCPragmaHandler> YYYY("xacc","xacc pragma description");
#endif
\ No newline at end of file
tools/compiler/clang/xacc-driver.in.cpp
View file @
4f2ceafc
...
...
@@ -61,19 +61,16 @@ protected:
public:
XACCPragmaASTConsumer
(
std
::
map
<
std
::
string
,
SourceLocation
>
&
m
)
:
map
(
m
)
{}
bool
HandleTopLevelDecl
(
DeclGroupRef
DR
)
override
{
PragmaVisitorHelper
visitor
(
map
);
//(ci, rewriter);
for
(
DeclGroupRef
::
iterator
b
=
DR
.
begin
(),
e
=
DR
.
end
();
b
!=
e
;
++
b
)
{
visitor
.
TraverseDecl
(
*
b
);
}
return
true
;
void
HandleTranslationUnit
(
ASTContext
&
ctx
)
override
{
PragmaVisitorHelper
visitor
(
map
);
visitor
.
TraverseDecl
(
ctx
.
getTranslationUnitDecl
());
}
private:
std
::
map
<
std
::
string
,
SourceLocation
>
&
map
;
// CompilerInstance &ci;
// Rewriter &rewriter;
};
std
::
unique_ptr
<
clang
::
ASTConsumer
>
CreateASTConsumer
(
clang
::
CompilerInstance
&
Compiler
,
llvm
::
StringRef
/* dummy */
)
override
{
...
...
tools/compiler/clang/xacc_runtime.hpp
View file @
4f2ceafc
...
...
@@ -3,8 +3,6 @@
#include
"IRProvider.hpp"
#include
"Observable.hpp"
#define OBSERVE "observe"
#define __qpu__ __attribute__((annotate("__qpu__")))
#define __observe__(OBS) __attribute__((annotate("observe_" #OBS)))
...
...
tools/compiler/examples/deuteron.cpp
View file @
4f2ceafc
...
...
@@ -31,20 +31,10 @@ __qpu__ void Y0Y1(qbit &q, double t0) {
Measure
(
1
);
}
template
<
typename
T
>
std
::
vector
<
T
>
linspace
(
T
a
,
T
b
,
size_t
N
)
{
T
h
=
(
b
-
a
)
/
static_cast
<
T
>
(
N
-
1
);
std
::
vector
<
T
>
xs
(
N
);
typename
std
::
vector
<
T
>::
iterator
x
;
T
val
;
for
(
x
=
xs
.
begin
(),
val
=
a
;
x
!=
xs
.
end
();
++
x
,
val
+=
h
)
*
x
=
val
;
return
xs
;
}
int
main
(
int
argc
,
char
**
argv
)
{
xacc
::
Initialize
(
argc
,
argv
);
std
::
vector
<
double
>
sweep
=
linspace
(
-
3.14
,
3.14
,
40
);
std
::
vector
<
double
>
sweep
=
xacc
::
linspace
(
-
3.14
,
3.14
,
40
);
for
(
auto
&
t
:
sweep
)
{
// Allocate a register of 2 qubits
...
...
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