Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cyril Moineau
aidge_core
Commits
d49e923a
Commit
d49e923a
authored
1 year ago
by
Olivier BICHLER
Browse files
Options
Downloads
Patches
Plain Diff
Added capacity() function and fix issue
aidge#112
parent
0d33ca05
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/aidge/backend/TensorImpl.hpp
+11
-0
11 additions, 0 deletions
include/aidge/backend/TensorImpl.hpp
include/aidge/backend/cpu/data/TensorImpl.hpp
+2
-0
2 additions, 0 deletions
include/aidge/backend/cpu/data/TensorImpl.hpp
src/backend/TensorImpl.cpp
+4
-2
4 additions, 2 deletions
src/backend/TensorImpl.cpp
with
17 additions
and
2 deletions
include/aidge/backend/TensorImpl.hpp
+
11
−
0
View file @
d49e923a
...
...
@@ -182,6 +182,17 @@ public:
*/
inline
std
::
size_t
size
()
const
noexcept
{
return
mNbElts
;
}
/**
* @brief Return the current capacity of the tensor, i.e. the actual memory
* currently being allocated. It can be different from the size:
* - Capacity can be 0 if the tensor memory was not yet initialized (because
* of lazy initialization, memory is allocated only when it needs to be
* accessed the first time).
* - Capacity can be > size if the tensor was downsized but memory was not
* reallocated.
*/
virtual
std
::
size_t
capacity
()
const
noexcept
=
0
;
/**
* @brief Return the size (in bytes) of one element (scalar).
*/
...
...
This diff is collapsed.
Click to expand it.
include/aidge/backend/cpu/data/TensorImpl.hpp
+
2
−
0
View file @
d49e923a
...
...
@@ -43,6 +43,8 @@ public:
return
std
::
make_shared
<
TensorImpl_cpu
<
T
>>
(
device
,
dims
);
}
inline
std
::
size_t
capacity
()
const
noexcept
override
final
{
return
mData
.
size
();
}
inline
std
::
size_t
scalarSize
()
const
noexcept
override
final
{
return
sizeof
(
T
);
}
void
zeros
()
override
final
;
...
...
This diff is collapsed.
Click to expand it.
src/backend/TensorImpl.cpp
+
4
−
2
View file @
d49e923a
...
...
@@ -15,7 +15,9 @@
#include
"aidge/utils/ErrorHandling.hpp"
void
Aidge
::
TensorImpl
::
copyFrom
(
const
TensorImpl
&
srcImpl
,
NbElts_t
length
,
NbElts_t
srcOffset
,
NbElts_t
dstOffset
)
{
if
(
&
srcImpl
==
this
&&
srcOffset
==
dstOffset
)
{
// Returns if src and dst are the same
// OR if src capacity is 0 (no valid data must be copied)
if
((
&
srcImpl
==
this
&&
srcOffset
==
dstOffset
)
||
srcImpl
.
capacity
()
==
0
)
{
return
;
}
...
...
@@ -24,7 +26,7 @@ void Aidge::TensorImpl::copyFrom(const TensorImpl& srcImpl, NbElts_t length, NbE
// Same backend, but different device
copyFromDevice
(
srcImpl
.
rawPtr
(
srcOffset
),
srcImpl
.
device
(),
length
,
dstOffset
);
}
else
if
(
srcImpl
.
hostPtr
()
!=
nullptr
)
{
else
if
(
srcImpl
.
hostPtr
()
!=
nullptr
)
{
// capacity() is > 0 so hostPtr() will not assert
// Different backend, but input is valid on host
copyFromHost
(
srcImpl
.
hostPtr
(
srcOffset
),
length
,
dstOffset
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment