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
38abf879
Commit
38abf879
authored
Jan 31, 2018
by
Jaikrishnan Menon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
e4bc5d67
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
184 additions
and
0 deletions
+184
-0
cpu_tensor_view.cpp
src/ngraph/runtime/cpu/cpu_tensor_view.cpp
+78
-0
cpu_tensor_view.hpp
src/ngraph/runtime/cpu/cpu_tensor_view.hpp
+61
-0
cpu_tensor_allocation.hpp
src/ngraph/runtime/cpu/pass/cpu_tensor_allocation.hpp
+45
-0
No files found.
src/ngraph/runtime/cpu/cpu_tensor_view.cpp
0 → 100644
View file @
38abf879
// ----------------------------------------------------------------------------
// 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 <cstring>
#include <memory>
#include "cpu_tensor_view.hpp"
#include "ngraph/descriptor/layout/tensor_view_layout.hpp"
#include "ngraph/descriptor/primary_tensor_view.hpp"
using
namespace
ngraph
;
using
namespace
std
;
runtime
::
cpu
::
CPUTensorView
::
CPUTensorView
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
,
const
string
&
name
)
:
runtime
::
TensorView
(
std
::
make_shared
<
ngraph
::
descriptor
::
PrimaryTensorView
>
(
std
::
make_shared
<
ngraph
::
TensorViewType
>
(
element_type
,
shape
),
name
,
true
,
true
,
false
))
,
buffer
(
nullptr
)
,
aligned_buffer
(
nullptr
)
{
}
runtime
::
cpu
::
CPUTensorView
::~
CPUTensorView
()
{
free
(
buffer
);
}
char
*
runtime
::
cpu
::
CPUTensorView
::
get_data_ptr
()
{
return
aligned_buffer
;
}
const
char
*
runtime
::
cpu
::
CPUTensorView
::
get_data_ptr
()
const
{
return
aligned_buffer
;
}
void
runtime
::
cpu
::
CPUTensorView
::
write
(
const
void
*
source
,
size_t
tensor_offset
,
size_t
n
)
{
if
(
tensor_offset
+
n
>
buffer_size
)
{
throw
out_of_range
(
"write access past end of tensor"
);
}
char
*
target
=
get_data_ptr
();
memcpy
(
&
target
[
tensor_offset
],
source
,
n
);
}
void
runtime
::
cpu
::
CPUTensorView
::
read
(
void
*
target
,
size_t
tensor_offset
,
size_t
n
)
const
{
if
(
tensor_offset
+
n
>
buffer_size
)
{
throw
out_of_range
(
"read access past end of tensor"
);
}
const
char
*
source
=
get_data_ptr
();
memcpy
(
target
,
&
source
[
tensor_offset
],
n
);
}
size_t
runtime
::
cpu
::
CPUTensorView
::
get_size
()
const
{
return
get_tensor_view_layout
()
->
get_size
();
}
const
element
::
Type
&
runtime
::
cpu
::
CPUTensorView
::
get_element_type
()
const
{
return
get_tensor_view_layout
()
->
get_element_type
();
}
src/ngraph/runtime/cpu/cpu_tensor_view.hpp
0 → 100644
View file @
38abf879
// ----------------------------------------------------------------------------
// 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
// ----------------------------------------------------------------------------
#pragma once
#include <string>
#include "ngraph/runtime/tensor_view.hpp"
#include "ngraph/types/element_type.hpp"
namespace
ngraph
{
namespace
runtime
{
namespace
cpu
{
class
CPUTensorView
:
public
ngraph
::
runtime
::
TensorView
{
public
:
CPUTensorView
(
const
ngraph
::
element
::
Type
&
element_type
,
const
Shape
&
shape
,
const
std
::
string
&
name
=
"external"
);
virtual
~
CPUTensorView
();
char
*
get_data_ptr
();
const
char
*
get_data_ptr
()
const
;
size_t
get_size
()
const
;
const
element
::
Type
&
get_element_type
()
const
;
/// @brief Write bytes directly into the tensor
/// @param p Pointer to source of data
/// @param tensor_offset Offset into tensor storage to begin writing. Must be element-aligned.
/// @param n Number of bytes to write, must be integral number of elements.
void
write
(
const
void
*
p
,
size_t
tensor_offset
,
size_t
n
)
override
;
/// @brief Read bytes directly from the tensor
/// @param p Pointer to destination for data
/// @param tensor_offset Offset into tensor storage to begin reading. Must be element-aligned.
/// @param n Number of bytes to read, must be integral number of elements.
void
read
(
void
*
p
,
size_t
tensor_offset
,
size_t
n
)
const
override
;
private
:
char
*
buffer
;
char
*
aligned_buffer
;
size_t
buffer_size
;
};
}
}
}
src/ngraph/runtime/cpu/pass/cpu_tensor_allocation.hpp
0 → 100644
View file @
38abf879
// ----------------------------------------------------------------------------
// 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
// ----------------------------------------------------------------------------
#pragma once
#include <memory>
#include "ngraph/descriptor/output.hpp"
#include "ngraph/pass/pass.hpp"
namespace
ngraph
{
namespace
pass
{
namespace
cpu
{
class
CPUTensorAllocation
:
public
ngraph
::
pass
::
FunctionPass
{
public
:
virtual
bool
run_on_function
(
std
::
shared_ptr
<
ngraph
::
Function
>
function
)
override
{
for
(
std
::
shared_ptr
<
ngraph
::
Node
>
node
:
function
->
get_ops
())
{
for
(
size_t
i
=
0
;
i
<
node
->
get_output_size
();
++
i
)
{
auto
tv
=
node
->
get_output_tensor_view
(
i
);
}
}
return
false
;
}
};
}
}
}
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