Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
redesign-prototype
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nektar
redesign-prototype
Commits
3cb0a677
Commit
3cb0a677
authored
2 years ago
by
Pavol Margitfalvi
Committed by
Chris Cantwell
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add warning when requesting storage different from the current one
parent
95c87476
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Updated code to use a common base class and single factory pattern.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Field.hpp
+20
-11
20 additions, 11 deletions
Field.hpp
with
20 additions
and
11 deletions
Field.hpp
+
20
−
11
View file @
3cb0a677
...
...
@@ -77,31 +77,40 @@ public:
template
<
template
<
typename
>
class
TMemoryRegion
=
MemoryRegionCPU
>
TMemoryRegion
<
TType
>
&
GetStorage
()
{
static_assert
(
std
::
is_base_of
<
MemoryRegionCPU
<
TType
>
,
TMemoryRegion
<
TType
>>::
value
,
"TMemoryRegion must derive MemoryRegionCPU<TType>"
);
using
T
=
TMemoryRegion
<
TType
>
;
static_assert
(
std
::
is_base_of
<
MemoryRegionCPU
<
TType
>
,
T
>::
value
,
"TMemoryRegion must derive MemoryRegionCPU<TType>"
);
try
{
return
dynamic_cast
<
TMemoryRegion
<
TType
>
&>
(
*
m_storage
);
auto
&
ret
=
dynamic_cast
<
T
&>
(
*
m_storage
);
if
(
typeid
(
*
m_storage
)
!=
typeid
(
T
))
{
std
::
cout
<<
"WARNING: Requested backing storage type "
<<
typeid
(
T
).
name
()
<<
" != actual storage type "
<<
typeid
(
*
m_storage
).
name
()
<<
std
::
endl
;
}
return
ret
;
}
catch
(
const
std
::
bad_cast
&
e
)
{
std
::
cout
<<
"WARNING: Converting backing storage from "
<<
typeid
(
*
m_storage
).
name
()
<<
" to "
<<
typeid
(
T
).
name
()
<<
std
::
endl
;
// This is just here so that the fromCPU method does
// not need to be declared for MemoryRegionCPU
if
constexpr
(
!
std
::
is_same
<
TMemoryRegion
<
TType
>
,
MemoryRegionCPU
<
TType
>>::
value
)
if
constexpr
(
!
std
::
is_same
<
T
,
MemoryRegionCPU
<
TType
>>::
value
)
{
m_storage
->
ToCPU
();
using
T
=
TMemoryRegion
<
TType
>
;
m_storage
=
std
::
make_unique
<
T
>
(
T
::
fromCPU
(
std
::
move
(
*
m_storage
)));
}
std
::
cout
<<
"WARNING: Converting backing storage to "
<<
typeid
(
TMemoryRegion
<
TType
>
).
name
()
<<
std
::
endl
;
return
dynamic_cast
<
TMemoryRegion
<
TType
>
&>
(
*
m_storage
);
return
dynamic_cast
<
T
&>
(
*
m_storage
);
}
}
...
...
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