Skip to content

Commit

Permalink
Merge pull request #1455 from LLNL/feature/gunney/blueprint-mesh-shaping
Browse files Browse the repository at this point in the history
Support Blueprint mesh in shaping
  • Loading branch information
gunney1 authored Jan 30, 2025
2 parents 11dd613 + 59d3aed commit 74fbbf5
Show file tree
Hide file tree
Showing 40 changed files with 2,880 additions and 847 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/
## [Unreleased] - Release date yyyy-mm-dd

### Added
- Support in `quest::IntersectionShaper` for Blueprint mesh stored in a `conduit::Node`
or `sidre::Group`.
- Adds new CMake configuration options, `AXOM_ENABLE_ASAN` and `AXOM_ENABLE_UBSAN`, to enable/disable AddressSanitizer and UndefinedBehaviorSanitizer respectively in Axom. Default is OFF for both.
- A number of new `klee::Geometry` constructors are added, for the different shapes now supported.
This is a temporary change. The class will be subclassed in the future to support a diversity of geometries.
Expand All @@ -35,6 +37,8 @@ to use Open Cascade's file I/O capabilities in support of Quest applications.
of `loadExternalData` in `sidre::IOManager` and `sidre::Group`.

### Changed
- `quest::Shaper` and `quest::IntersectionShaper` constructors require a runtime policy.
Changing the policy after construction is no longer supported.
- Importing Conduit array data into `sidre::View` now allocates destination
data using the `View`'s parent's allocator ID, instead of always using
host memory. This is consistent with the behavior of deep-copying data
Expand Down
1 change: 1 addition & 0 deletions src/axom/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ blt_list_append( TO core_depends ELEMENTS caliper IF CALIPER_FOUND )
blt_list_append( TO core_depends ELEMENTS camp IF CAMP_FOUND )
blt_list_append( TO core_depends ELEMENTS umpire IF UMPIRE_FOUND )
blt_list_append( TO core_depends ELEMENTS RAJA IF RAJA_FOUND )
blt_list_append( TO core_depends ELEMENTS conduit::conduit IF CONDUIT_FOUND )
blt_list_append( TO core_depends ELEMENTS mpi IF AXOM_ENABLE_MPI )

# HACK: RAJA's dependencies are not getting added to core due to a bug in
Expand Down
44 changes: 44 additions & 0 deletions src/axom/core/execution/execution_space.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "axom/config.hpp"
#include "axom/core/memory_management.hpp"
#include "axom/core/execution/runtime_policy.hpp"

/*!
* \file execution_space.hpp
Expand Down Expand Up @@ -88,6 +89,20 @@ struct execution_space
static constexpr bool onDevice() noexcept { return false; }
static constexpr char* name() noexcept { return (char*)"[UNDEFINED]"; }
static int allocatorID() noexcept { return axom::INVALID_ALLOCATOR_ID; }
static constexpr runtime_policy::Policy runtimePolicy() noexcept
{
return runtime_policy::Policy::seq;
}
//!@brief Returns whether @c ExecSpace can use the given @c MemorySpace.
static bool usesMemorySpace(axom::MemorySpace m) noexcept
{
return m == memory_space;
}
//!@brief Returns whether @c ExecSpace can use the given allocator id.
static bool usesAllocId(int allocId) noexcept
{
return usesMemorySpace(axom::detail::getAllocatorSpace(allocId));
}
};

} // namespace axom
Expand All @@ -109,4 +124,33 @@ struct execution_space
#include "axom/core/execution/internal/hip_exec.hpp"
#endif

namespace axom
{

/// \brief Return default allocator id for a runtime policy.
inline int policyToDefaultAllocatorID(axom::runtime_policy::Policy policy)
{
return policy == axom::runtime_policy::Policy::seq
? axom::execution_space<axom::SEQ_EXEC>::allocatorID()
:
#if defined(AXOM_RUNTIME_POLICY_USE_OPENMP)
policy == axom::runtime_policy::Policy::omp
? axom::execution_space<axom::OMP_EXEC>::allocatorID()
:
#endif
#if defined(AXOM_RUNTIME_POLICY_USE_CUDA)
policy == axom::runtime_policy::Policy::cuda
? axom::execution_space<axom::CUDA_EXEC<256>>::allocatorID()
:
#endif
#if defined(AXOM_RUNTIME_POLICY_USE_HIP)
policy == axom::runtime_policy::Policy::hip
? axom::execution_space<axom::HIP_EXEC<256>>::allocatorID()
:
#endif
INVALID_ALLOCATOR_ID;
}

} // namespace axom

#endif // AXOM_EXECUTIONSPACE_HPP_
25 changes: 25 additions & 0 deletions src/axom/core/execution/internal/cuda_exec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ struct execution_space<CUDA_EXEC<BLOCK_SIZE, SYNCHRONOUS>>
{
return axom::getUmpireResourceAllocatorID(umpire::resource::Device);
}
static constexpr runtime_policy::Policy runtimePolicy() noexcept
{
return runtime_policy::Policy::cuda;
}
static bool usesMemorySpace(axom::MemorySpace m) noexcept
{
return m == memory_space || m == MemorySpace::Unified;
}
static bool usesAllocId(int allocId) noexcept
{
return usesMemorySpace(axom::detail::getAllocatorSpace(allocId));
}
};

/*!
Expand Down Expand Up @@ -95,6 +107,19 @@ struct execution_space<CUDA_EXEC<BLOCK_SIZE, ASYNC>>
{
return axom::getUmpireResourceAllocatorID(umpire::resource::Device);
}
static constexpr runtime_policy::Policy runtimePolicy() noexcept
{
return runtime_policy::Policy::cuda;
}
static bool usesMemorySpace(axom::MemorySpace m) noexcept
{
return m == memory_space || m == MemorySpace::Unified;
}
static bool usesAllocId(int allocId) noexcept
{
return allocId == 0 ||
usesMemorySpace(axom::detail::getAllocatorSpace(allocId));
}
};
} // namespace axom

Expand Down
25 changes: 25 additions & 0 deletions src/axom/core/execution/internal/hip_exec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ struct execution_space<HIP_EXEC<BLOCK_SIZE, SYNCHRONOUS>>
{
return axom::getUmpireResourceAllocatorID(umpire::resource::Device);
}
static constexpr runtime_policy::Policy runtimePolicy() noexcept
{
return runtime_policy::Policy::hip;
}
static bool usesMemorySpace(axom::MemorySpace m) noexcept
{
return m == memory_space || m == MemorySpace::Unified;
}
static bool usesAllocId(int allocId) noexcept
{
return allocId == 0 ||
usesMemorySpace(axom::detail::getAllocatorSpace(allocId));
}
};

/*!
Expand Down Expand Up @@ -90,6 +103,18 @@ struct execution_space<HIP_EXEC<BLOCK_SIZE, ASYNC>>
{
return axom::getUmpireResourceAllocatorID(umpire::resource::Device);
}
static constexpr runtime_policy::Policy runtimePolicy() noexcept
{
return runtime_policy::Policy::hip;
}
static bool usesMemorySpace(axom::MemorySpace m) noexcept
{
return m == memory_space || m == MemorySpace::Unified;
}
static bool usesAllocId(int allocId) noexcept
{
return usesMemorySpace(axom::detail::getAllocatorSpace(allocId));
}
};
} // namespace axom

Expand Down
16 changes: 16 additions & 0 deletions src/axom/core/execution/internal/omp_exec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ struct execution_space<OMP_EXEC>
return axom::getDefaultAllocatorID();
#endif
}
static constexpr runtime_policy::Policy runtimePolicy() noexcept
{
return runtime_policy::Policy::omp;
}
static bool usesMemorySpace(axom::MemorySpace m) noexcept
{
return m == memory_space
#ifdef AXOM_USE_UMPIRE
|| m == MemorySpace::Unified
#endif
;
}
static bool usesAllocId(int allocId) noexcept
{
return usesMemorySpace(axom::detail::getAllocatorSpace(allocId));
}
};

} // namespace axom
Expand Down
16 changes: 16 additions & 0 deletions src/axom/core/execution/internal/seq_exec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ struct execution_space<SEQ_EXEC>
return axom::getDefaultAllocatorID();
#endif
}
static constexpr runtime_policy::Policy runtimePolicy() noexcept
{
return runtime_policy::Policy::seq;
}
static bool usesMemorySpace(axom::MemorySpace m) noexcept
{
return m == memory_space
#ifdef AXOM_USE_UMPIRE
|| m == MemorySpace::Unified
#endif
;
}
static bool usesAllocId(int allocId) noexcept
{
return usesMemorySpace(axom::detail::getAllocatorSpace(allocId));
}
};

} // namespace axom
Expand Down
3 changes: 2 additions & 1 deletion src/axom/core/execution/runtime_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#ifndef AXOM_CORE_EXECUTION_RUNTIME_POLICY_HPP_
#define AXOM_CORE_EXECUTION_RUNTIME_POLICY_HPP_

#include "axom/config.hpp" /* for compile time defs. */
#include "axom/config.hpp" /* for compile time defs. */
#include <string>
#include "axom/fmt/format.h" /* for axom::fmt */

#include <map>
Expand Down
33 changes: 29 additions & 4 deletions src/axom/core/memory_management.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace axom
{
constexpr int INVALID_ALLOCATOR_ID = -1;
constexpr int DYNAMIC_ALLOCATOR_ID = 0;

// _memory_space_start
/*!
Expand Down Expand Up @@ -106,10 +107,32 @@ inline int getDefaultAllocatorID()
#ifdef AXOM_USE_UMPIRE
return umpire::ResourceManager::getInstance().getDefaultAllocator().getId();
#else
return 0;
return DYNAMIC_ALLOCATOR_ID;
#endif
}

/*!
* \brief Get the allocator id from which data has been allocated.
* \return Allocator id. If Umpire doesn't have an allocator for
* the pointer, or Axom wasn't configured with Umpire, return
* \c axom::DYNAMIC_ALLOCATOR_ID.
*
* \pre ptr has a valid pointer value.
*/
inline int getAllocatorIDFromPointer(const void* ptr)
{
#ifdef AXOM_USE_UMPIRE
umpire::ResourceManager& rm = umpire::ResourceManager::getInstance();
if(rm.hasAllocator(const_cast<void*>(ptr)))
{
umpire::Allocator allocator = rm.getAllocator(const_cast<void*>(ptr));
return allocator.getId();
}
#endif
AXOM_UNUSED_VAR(ptr);
return DYNAMIC_ALLOCATOR_ID;
}

/*!
* \brief Allocates a chunk of memory of type T.
*
Expand Down Expand Up @@ -303,6 +326,11 @@ inline int getAllocatorID<MemorySpace::Dynamic>()

inline MemorySpace getAllocatorSpace(int allocatorId)
{
// Treat non-Umpire allocatorID first. Umpire's getAllocator
// throws exception if given a non-Umpire id.
assert(allocatorId != INVALID_ALLOCATOR_ID);
if(allocatorId == DYNAMIC_ALLOCATOR_ID) return MemorySpace::Dynamic;

#ifdef AXOM_USE_UMPIRE
using ump_res_type = typename umpire::MemoryResourceTraits::resource_type;

Expand All @@ -325,9 +353,6 @@ inline MemorySpace getAllocatorSpace(int allocatorId)
default:
return MemorySpace::Dynamic;
}
#else
AXOM_UNUSED_VAR(allocatorId);
return MemorySpace::Dynamic;
#endif
}

Expand Down
26 changes: 26 additions & 0 deletions src/axom/core/tests/utils_fileUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "gtest/gtest.h"
#include <fstream>
#include <exception>

#include "axom/config.hpp"
#include "axom/core/utilities/FileUtilities.hpp"
Expand Down Expand Up @@ -103,3 +104,28 @@ TEST(utils_fileUtilities, changeCWD_smoke)
EXPECT_EQ(origCWD, fs::getCWD());
std::cout << "[cwd after change]: '" << fs::getCWD() << "'" << std::endl;
}

TEST(utils_fileUtilities, prefixRelativePath)
{
using namespace axom::utilities::filesystem;
EXPECT_EQ(prefixRelativePath("rel/path", "/pre/fix"), "/pre/fix/rel/path");
EXPECT_EQ(prefixRelativePath("rel/path", ""), "rel/path");
EXPECT_THROW(prefixRelativePath("", "/pre/fix"), std::invalid_argument);

// These full paths should not change.
EXPECT_EQ(prefixRelativePath("/full/path", "/pre/fix"), "/full/path");
EXPECT_EQ(prefixRelativePath("/full/path", ""), "/full/path");
}

TEST(utils_fileUtilities, getParentPath)
{
using namespace axom::utilities::filesystem;
EXPECT_EQ(getParentPath("/full/multi/level/path"), "/full/multi/level");
EXPECT_EQ(getParentPath("/full/multi/level"), "/full/multi");
EXPECT_EQ(getParentPath("rel/multi/level/path"), "rel/multi/level");
EXPECT_EQ(getParentPath("rel/multi/level"), "rel/multi");
EXPECT_EQ(getParentPath("level"), "");
EXPECT_EQ(getParentPath("/level0/level1"), "/level0");
EXPECT_EQ(getParentPath("/level0"), "/");
EXPECT_EQ(getParentPath("/"), "");
}
50 changes: 50 additions & 0 deletions src/axom/core/utilities/FileUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#define Unlink unlink
#endif

// Note: The hard-wired path separator character in this file
// should be set to the backslash when on Windows.

namespace axom
{
namespace utilities
Expand Down Expand Up @@ -106,6 +109,53 @@ int makeDirsForPath(const std::string& path)
return err;
}

//-----------------------------------------------------------------------------
std::string prefixRelativePath(const std::string& path, const std::string& prefix)
{
if(path.empty())
{
throw std::invalid_argument("path must not be empty");
};
if(path[0] == '/' || prefix.empty())
{
return path;
}
return utilities::filesystem::joinPath(prefix, path);
}

//-----------------------------------------------------------------------------
std::string getParentPath(const std::string& path)
{
if(path.empty())
{
throw std::invalid_argument("path must not be empty");
};

char separator = '/';

std::string parent;

if(path.size() == 1 && path[0] == separator)
{
// path is root, so parent is blank.
}
else
{
std::size_t found = path.rfind(separator);

if(found != std::string::npos)
{
if(found == 0)
{
++found;
}
parent = path.substr(0, found);
}
}

return parent;
}

//-----------------------------------------------------------------------------
void getDirName(std::string& dir, const std::string& path)
{
Expand Down
Loading

0 comments on commit 74fbbf5

Please sign in to comment.