Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
1719fb67
Commit
1719fb67
authored
Oct 06, 2017
by
Jaikrishnan Menon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Codegen: CRLF -> LF
parent
522b6fb2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
90 deletions
+90
-90
codegen.cpp
test/codegen.cpp
+90
-90
No files found.
test/codegen.cpp
View file @
1719fb67
// ----------------------------------------------------------------------------
// Copyright 2017 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#include <sstream>
#include <string>
#include <vector>
#include "gtest/gtest.h"
#include "ngraph/codegen/compiler.hpp"
using
namespace
std
;
TEST
(
codegen
,
simple_return
)
{
constexpr
auto
name
=
"test.cpp"
;
constexpr
auto
source
=
R"(extern "C" int test() { return 2+5; })"
;
nervana
::
cpu
::
execution_state
estate
;
auto
module
=
estate
.
compile
(
source
,
name
);
ASSERT_NE
(
nullptr
,
module
);
estate
.
add_module
(
module
);
estate
.
finalize
();
auto
func
=
estate
.
find_function
<
int
()
>
(
"test"
);
ASSERT_NE
(
nullptr
,
func
);
int
result
=
func
();
EXPECT_EQ
(
7
,
result
);
}
TEST
(
codegen
,
pass_args
)
{
constexpr
auto
name
=
"test.cpp"
;
constexpr
auto
source
=
R"(extern "C" int test(int a, int b) { return a+b; })"
;
nervana
::
cpu
::
execution_state
estate
;
auto
module
=
estate
.
compile
(
source
,
name
);
ASSERT_NE
(
nullptr
,
module
);
estate
.
add_module
(
module
);
estate
.
finalize
();
auto
func
=
estate
.
find_function
<
int
(
int
,
int
)
>
(
"test"
);
ASSERT_NE
(
nullptr
,
func
);
int
result
=
func
(
20
,
22
);
EXPECT_EQ
(
42
,
result
);
}
TEST
(
codegen
,
include
)
{
constexpr
auto
name
=
"test.cpp"
;
constexpr
auto
source
=
R"(
#include <cmath>
extern "C" int test(int a, int b)
{
return (int)pow((double)a,(double)b);
}
)"
;
nervana
::
cpu
::
execution_state
estate
;
auto
module
=
estate
.
compile
(
source
,
name
);
ASSERT_NE
(
nullptr
,
module
);
estate
.
add_module
(
module
);
estate
.
finalize
();
auto
func
=
estate
.
find_function
<
int
(
int
,
int
)
>
(
"test"
);
ASSERT_NE
(
nullptr
,
func
);
int
result
=
func
(
20
,
2
);
EXPECT_EQ
(
400
,
result
);
}
// ----------------------------------------------------------------------------
// Copyright 2017 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#include <sstream>
#include <string>
#include <vector>
#include "gtest/gtest.h"
#include "ngraph/codegen/compiler.hpp"
using
namespace
std
;
TEST
(
codegen
,
simple_return
)
{
constexpr
auto
name
=
"test.cpp"
;
constexpr
auto
source
=
R"(extern "C" int test() { return 2+5; })"
;
nervana
::
cpu
::
execution_state
estate
;
auto
module
=
estate
.
compile
(
source
,
name
);
ASSERT_NE
(
nullptr
,
module
);
estate
.
add_module
(
module
);
estate
.
finalize
();
auto
func
=
estate
.
find_function
<
int
()
>
(
"test"
);
ASSERT_NE
(
nullptr
,
func
);
int
result
=
func
();
EXPECT_EQ
(
7
,
result
);
}
TEST
(
codegen
,
pass_args
)
{
constexpr
auto
name
=
"test.cpp"
;
constexpr
auto
source
=
R"(extern "C" int test(int a, int b) { return a+b; })"
;
nervana
::
cpu
::
execution_state
estate
;
auto
module
=
estate
.
compile
(
source
,
name
);
ASSERT_NE
(
nullptr
,
module
);
estate
.
add_module
(
module
);
estate
.
finalize
();
auto
func
=
estate
.
find_function
<
int
(
int
,
int
)
>
(
"test"
);
ASSERT_NE
(
nullptr
,
func
);
int
result
=
func
(
20
,
22
);
EXPECT_EQ
(
42
,
result
);
}
TEST
(
codegen
,
include
)
{
constexpr
auto
name
=
"test.cpp"
;
constexpr
auto
source
=
R"(
#include <cmath>
extern "C" int test(int a, int b)
{
return (int)pow((double)a,(double)b);
}
)"
;
nervana
::
cpu
::
execution_state
estate
;
auto
module
=
estate
.
compile
(
source
,
name
);
ASSERT_NE
(
nullptr
,
module
);
estate
.
add_module
(
module
);
estate
.
finalize
();
auto
func
=
estate
.
find_function
<
int
(
int
,
int
)
>
(
"test"
);
ASSERT_NE
(
nullptr
,
func
);
int
result
=
func
(
20
,
2
);
EXPECT_EQ
(
400
,
result
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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