Skip to content

Commit 6764c24

Browse files
committed
Autoformat.
1 parent e3f6f60 commit 6764c24

9 files changed

Lines changed: 178 additions & 149 deletions

File tree

src/axom/core/ConduitMemory.cpp

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,66 @@
77

88
namespace axom
99
{
10-
std::map<int, std::shared_ptr<ConduitMemory>> ConduitMemory::s_axomToInstance;
11-
std::map<conduit::index_t, std::shared_ptr<ConduitMemory>> ConduitMemory::s_conduitToInstance;
10+
std::map<int, std::shared_ptr<ConduitMemory>> ConduitMemory::s_axomToInstance;
11+
std::map<conduit::index_t, std::shared_ptr<ConduitMemory>>
12+
ConduitMemory::s_conduitToInstance;
1213

13-
const ConduitMemory& ConduitMemory::instanceForAxomId(int axomAllocId)
14-
{
15-
// This method IS NOT thread safe.
16-
17-
if(s_axomToInstance.empty())
18-
{
19-
// Required one-time actions
20-
static auto axomMemcopy = [](void* dst, const void* src, size_t byteCount) {
21-
axom::copy(dst, src, byteCount);
22-
};
23-
static auto axomMemset = [](void* ptr, int value, size_t count) {
24-
if(axom::getAllocatorIDFromPointer(ptr) == axom::DYNAMIC_ALLOCATOR_ID)
25-
{
26-
std::memset(ptr, value, count);
27-
}
28-
else
29-
{
30-
umpire::ResourceManager& rm = umpire::ResourceManager::getInstance();
31-
rm.memset(ptr, value, count);
32-
}
33-
};
34-
conduit::utils::set_memcpy_handler(axomMemcopy);
35-
conduit::utils::set_memset_handler(axomMemset);
36-
}
14+
const ConduitMemory& ConduitMemory::instanceForAxomId(int axomAllocId)
15+
{
16+
// This method IS NOT thread safe.
3717

38-
auto it = s_axomToInstance.find(axomAllocId);
39-
if(it == s_axomToInstance.end())
40-
{
41-
std::shared_ptr<ConduitMemory> newInstance(new ConduitMemory(axomAllocId));
42-
s_axomToInstance[axomAllocId] = newInstance;
43-
it = s_axomToInstance.insert({axomAllocId, newInstance}).first;
18+
if(s_axomToInstance.empty())
19+
{
20+
// Required one-time actions
21+
static auto axomMemcopy = [](void* dst, const void* src, size_t byteCount) {
22+
axom::copy(dst, src, byteCount);
23+
};
24+
static auto axomMemset = [](void* ptr, int value, size_t count) {
25+
if(axom::getAllocatorIDFromPointer(ptr) == axom::DYNAMIC_ALLOCATOR_ID)
26+
{
27+
std::memset(ptr, value, count);
28+
}
29+
else
30+
{
31+
umpire::ResourceManager& rm = umpire::ResourceManager::getInstance();
32+
rm.memset(ptr, value, count);
33+
}
34+
};
35+
conduit::utils::set_memcpy_handler(axomMemcopy);
36+
conduit::utils::set_memset_handler(axomMemset);
37+
}
4438

45-
auto conduitAllocId = newInstance->m_conduitId;
46-
assert(s_conduitToInstance.find(conduitAllocId) == s_conduitToInstance.end());
47-
s_conduitToInstance[conduitAllocId] = newInstance;
48-
}
49-
assert(it->first == axomAllocId);
39+
auto it = s_axomToInstance.find(axomAllocId);
40+
if(it == s_axomToInstance.end())
41+
{
42+
std::shared_ptr<ConduitMemory> newInstance(new ConduitMemory(axomAllocId));
43+
s_axomToInstance[axomAllocId] = newInstance;
44+
it = s_axomToInstance.insert({axomAllocId, newInstance}).first;
5045

51-
return *it->second;
46+
auto conduitAllocId = newInstance->m_conduitId;
47+
assert(s_conduitToInstance.find(conduitAllocId) == s_conduitToInstance.end());
48+
s_conduitToInstance[conduitAllocId] = newInstance;
5249
}
50+
assert(it->first == axomAllocId);
5351

54-
const ConduitMemory& ConduitMemory::instanceForConduitId(conduit::index_t conduitAllocId)
55-
{
56-
// This method IS thread safe.
52+
return *it->second;
53+
}
5754

58-
auto it = s_conduitToInstance.find(conduitAllocId);
59-
if(it == s_conduitToInstance.end())
60-
{
61-
std::cerr << "*** Error: Axom allocator for Conduit allocator id " << conduitAllocId << " doesn't exist. You have to register the Axom allocator first, using ConduitMemory::getAxomInstance()." << std::endl;
62-
axom::utilities::processAbort();
63-
}
64-
assert(it->first == conduitAllocId);
55+
const ConduitMemory& ConduitMemory::instanceForConduitId(
56+
conduit::index_t conduitAllocId)
57+
{
58+
// This method IS thread safe.
6559

66-
return *it->second;
60+
auto it = s_conduitToInstance.find(conduitAllocId);
61+
if(it == s_conduitToInstance.end())
62+
{
63+
std::cerr << "*** Error: Axom allocator for Conduit allocator id "
64+
<< conduitAllocId << " doesn't exist. You have to register the Axom allocator first, using ConduitMemory::getAxomInstance()."
65+
<< std::endl;
66+
axom::utilities::processAbort();
6767
}
68+
assert(it->first == conduitAllocId);
69+
70+
return *it->second;
71+
}
6872
} // end namespace axom

src/axom/quest/Shaper.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -120,36 +120,35 @@ Shaper::Shaper(RuntimePolicy execPolicy,
120120
Ordered by likeliest to be correct.
121121
*/
122122
const auto hostAllocId = axom::execution_space<axom::SEQ_EXEC>::allocatorID();
123-
auto viewToStandardAllocator =
124-
[&](const axom::sidre::View& v) {
125-
if ( v.isString() || (v.isExternal() && v.getNumElements() == 1) )
126-
{
127-
// String or likely external string
128-
return hostAllocId;
129-
}
130-
if ( (v.hasBuffer() || v.isExternal())
131-
&& (v.getName() == "offsets" || v.getName() == "strides")
132-
&& (v.getNumElements() <= 3) )
133-
{
134-
// Likely Blueprint specification of array offsets or strides.
135-
return hostAllocId;
136-
}
137-
if ( v.hasBuffer() && v.getPath().find("/values/") == std::string::npos )
138-
{
139-
// Likely Blueprint mesh data or coordinate values.
140-
return axom::INVALID_ALLOCATOR_ID;
141-
}
142-
if ( v.isScalar() || (v.isExternal() && v.getNumElements() == 1) )
143-
{
144-
// Scalar or likely external scalar
145-
return hostAllocId;
146-
}
147-
if ( v.hasBuffer() && v.getNumElements() <= 3 )
148-
{
149-
return hostAllocId;
150-
}
123+
auto viewToStandardAllocator = [&](const axom::sidre::View& v) {
124+
if(v.isString() || (v.isExternal() && v.getNumElements() == 1))
125+
{
126+
// String or likely external string
127+
return hostAllocId;
128+
}
129+
if((v.hasBuffer() || v.isExternal()) &&
130+
(v.getName() == "offsets" || v.getName() == "strides") &&
131+
(v.getNumElements() <= 3))
132+
{
133+
// Likely Blueprint specification of array offsets or strides.
134+
return hostAllocId;
135+
}
136+
if(v.hasBuffer() && v.getPath().find("/values/") == std::string::npos)
137+
{
138+
// Likely Blueprint mesh data or coordinate values.
151139
return axom::INVALID_ALLOCATOR_ID;
152-
};
140+
}
141+
if(v.isScalar() || (v.isExternal() && v.getNumElements() == 1))
142+
{
143+
// Scalar or likely external scalar
144+
return hostAllocId;
145+
}
146+
if(v.hasBuffer() && v.getNumElements() <= 3)
147+
{
148+
return hostAllocId;
149+
}
150+
return axom::INVALID_ALLOCATOR_ID;
151+
};
153152
m_bpGrp->reallocateTo(viewToStandardAllocator);
154153

155154
// We want unstructured topo but can accomodate structured.

src/axom/quest/examples/quest_shape_in_memory.cpp

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -478,47 +478,48 @@ std::shared_ptr<sidre::MFEMSidreDataCollection> shapingDC;
478478
axom::sidre::Group* compMeshGrp = nullptr;
479479
std::shared_ptr<conduit::Node> compMeshNode;
480480

481-
auto selectScalarAndStringViews =
482-
[](const axom::sidre::View& v) { return v.isScalar() || v.isString(); };
483-
auto selectNonHostViews =
484-
[](const axom::sidre::View& v) { return v.getVoidPtr() != nullptr && !v.isHostAccessible(); };
481+
auto selectScalarAndStringViews = [](const axom::sidre::View& v) {
482+
return v.isScalar() || v.isString();
483+
};
484+
auto selectNonHostViews = [](const axom::sidre::View& v) {
485+
return v.getVoidPtr() != nullptr && !v.isHostAccessible();
486+
};
485487

486488
/*
487489
Whether View data should live on host or another allocator (like device data).
488490
Return the "right" choice based on View type, using a heuristic.
489491
as determined by heuristics.
490492
Ordered by likeliest to be correct.
491493
*/
492-
auto viewToStandardAllocator =
493-
[](const axom::sidre::View& v) {
494-
if ( v.isString() || (v.isExternal() && v.getNumElements() == 1) )
495-
{
496-
// String or likely external string
497-
return hostAllocId;
498-
}
499-
if ( (v.hasBuffer() || v.isExternal())
500-
&& (v.getName() == "offsets" || v.getName() == "strides")
501-
&& (v.getNumElements() <= 3) )
502-
{
503-
// Likely Blueprint specification of array offsets or strides.
504-
return hostAllocId;
505-
}
506-
if ( v.hasBuffer() && v.getPath().find("/values/") == std::string::npos )
507-
{
508-
// Likely Blueprint mesh data or coordinate values.
509-
return arrayAllocId;
510-
}
511-
if ( v.isScalar() || (v.isExternal() && v.getNumElements() == 1) )
512-
{
513-
// Scalar or likely external scalar
514-
return hostAllocId;
515-
}
516-
if ( v.hasBuffer() && v.getNumElements() <= 3 )
517-
{
518-
return hostAllocId;
519-
}
494+
auto viewToStandardAllocator = [](const axom::sidre::View& v) {
495+
if(v.isString() || (v.isExternal() && v.getNumElements() == 1))
496+
{
497+
// String or likely external string
498+
return hostAllocId;
499+
}
500+
if((v.hasBuffer() || v.isExternal()) &&
501+
(v.getName() == "offsets" || v.getName() == "strides") &&
502+
(v.getNumElements() <= 3))
503+
{
504+
// Likely Blueprint specification of array offsets or strides.
505+
return hostAllocId;
506+
}
507+
if(v.hasBuffer() && v.getPath().find("/values/") == std::string::npos)
508+
{
509+
// Likely Blueprint mesh data or coordinate values.
520510
return arrayAllocId;
521-
};
511+
}
512+
if(v.isScalar() || (v.isExternal() && v.getNumElements() == 1))
513+
{
514+
// Scalar or likely external scalar
515+
return hostAllocId;
516+
}
517+
if(v.hasBuffer() && v.getNumElements() <= 3)
518+
{
519+
return hostAllocId;
520+
}
521+
return arrayAllocId;
522+
};
522523

523524
axom::sidre::Group* createBoxMesh(axom::sidre::Group* meshGrp)
524525
{
@@ -1606,7 +1607,7 @@ int main(int argc, char** argv)
16061607
"-DAXOM_ENABLE_MFEM_SIDRE_DATACOLLECTION.");
16071608
#endif
16081609

1609-
conduit::Node* topoCoordsetNode = nullptr;
1610+
conduit::Node* topoCoordsetNode = nullptr;
16101611
if(params.useBlueprintSidre() || params.useBlueprintConduit())
16111612
{
16121613
compMeshGrp = ds.getRoot()->createGroup("compMesh");

src/axom/quest/util/mesh_helpers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ axom::sidre::Group* make_structured_blueprint_box_mesh(
119119

120120
topoGrp->createView("type")->setString("structured", hostAllocId);
121121
topoGrp->createView("coordset")->setString(coordsetName, hostAllocId);
122-
auto* dimsGrp = topoGrp->createGroup("elements/dims")->setDefaultAllocator(hostAllocId);
122+
auto* dimsGrp =
123+
topoGrp->createGroup("elements/dims")->setDefaultAllocator(hostAllocId);
123124

124125
constexpr int DIM = 3;
125126

src/axom/sidre/core/Group.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ View* Group::createView(const std::string& path, const DataType& dtype)
492492
if(view != nullptr)
493493
{
494494
view->describe(dtype);
495-
assert(view->m_state == View::State::BUFFER || view->m_state == View::State::EMPTY);
495+
assert(view->m_state == View::State::BUFFER ||
496+
view->m_state == View::State::EMPTY);
496497
}
497498

498499
return view;
@@ -518,7 +519,8 @@ View* Group::createView(const std::string& path, Buffer* buff)
518519
if(view != nullptr)
519520
{
520521
view->attachBuffer(buff);
521-
assert(view->m_state == View::State::BUFFER || view->m_state == View::State::EMPTY);
522+
assert(view->m_state == View::State::BUFFER ||
523+
view->m_state == View::State::EMPTY);
522524
}
523525
return view;
524526
}
@@ -540,7 +542,8 @@ View* Group::createView(const std::string& path,
540542
if(view != nullptr)
541543
{
542544
view->attachBuffer(buff);
543-
assert(view->m_state == View::State::BUFFER || view->m_state == View::State::EMPTY);
545+
assert(view->m_state == View::State::BUFFER ||
546+
view->m_state == View::State::EMPTY);
544547
}
545548
return view;
546549
}
@@ -563,7 +566,8 @@ View* Group::createViewWithShape(const std::string& path,
563566
if(view != nullptr)
564567
{
565568
view->attachBuffer(buff);
566-
assert(view->m_state == View::State::BUFFER || view->m_state == View::State::EMPTY);
569+
assert(view->m_state == View::State::BUFFER ||
570+
view->m_state == View::State::EMPTY);
567571
}
568572
return view;
569573
}
@@ -582,7 +586,8 @@ View* Group::createView(const std::string& path, const DataType& dtype, Buffer*
582586
if(view != nullptr)
583587
{
584588
view->attachBuffer(buff);
585-
assert(view->m_state == View::State::BUFFER || view->m_state == View::State::EMPTY);
589+
assert(view->m_state == View::State::BUFFER ||
590+
view->m_state == View::State::EMPTY);
586591
}
587592

588593
return view;
@@ -700,7 +705,8 @@ View* Group::createViewAndAllocate(const std::string& path,
700705
if(view != nullptr)
701706
{
702707
view->allocate(allocID);
703-
assert(view->m_state == View::State::BUFFER || view->m_state == View::State::EMPTY);
708+
assert(view->m_state == View::State::BUFFER ||
709+
view->m_state == View::State::EMPTY);
704710
}
705711
return view;
706712
}
@@ -725,7 +731,8 @@ View* Group::createViewWithShapeAndAllocate(const std::string& path,
725731
if(view != nullptr)
726732
{
727733
view->allocate(allocID);
728-
assert(view->m_state == View::State::BUFFER || view->m_state == View::State::EMPTY);
734+
assert(view->m_state == View::State::BUFFER ||
735+
view->m_state == View::State::EMPTY);
729736
}
730737
return view;
731738
}
@@ -748,7 +755,8 @@ View* Group::createViewAndAllocate(const std::string& path,
748755
if(view != nullptr)
749756
{
750757
view->allocate(allocID);
751-
assert(view->m_state == View::State::BUFFER || view->m_state == View::State::EMPTY);
758+
assert(view->m_state == View::State::BUFFER ||
759+
view->m_state == View::State::EMPTY);
752760
}
753761
return view;
754762
}
@@ -1471,7 +1479,9 @@ Group* Group::deepCopyGroup(const Group* srcGroup, int allocID)
14711479
Group* Group::deepCopyGroupToSelf(const Group* srcGroup)
14721480
{
14731481
SLIC_ERROR_IF(m_is_list && !srcGroup->m_is_list,
1474-
"Group::deepCopyToSelf cannot copy from a list Group '" + srcGroup->getPath() + "' to a non-list Group '" + getPath() + "'");
1482+
"Group::deepCopyToSelf cannot copy from a list Group '" +
1483+
srcGroup->getPath() + "' to a non-list Group '" + getPath() +
1484+
"'");
14751485

14761486
destroyGroupsAndData();
14771487
destroyViewsAndData();
@@ -1550,7 +1560,8 @@ Group* Group::reallocateTo(int newAllocId,
15501560

15511561
Group* Group::reallocateTo(int newAllocId)
15521562
{
1553-
return reallocateTo(std::function<int(const View&)>{[=](const View&) { return newAllocId; }});
1563+
return reallocateTo(
1564+
std::function<int(const View&)> {[=](const View&) { return newAllocId; }});
15541565
}
15551566

15561567
/*
@@ -1593,7 +1604,8 @@ axom::IndexType Group::findViews(const std::function<bool(View&)>& criteria,
15931604

15941605
for(auto& view : views())
15951606
{
1596-
if(criteria(view)) {
1607+
if(criteria(view))
1608+
{
15971609
found.push_back(&view);
15981610
}
15991611
}

0 commit comments

Comments
 (0)