Skip to content

Commit

Permalink
Merge branch 'develop' into task/UM-1020-asan-poisoning-for-hip
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienbernede committed Jun 19, 2024
2 parents 9022631 + 1828c82 commit c458f02
Show file tree
Hide file tree
Showing 36 changed files with 634 additions and 113 deletions.
12 changes: 12 additions & 0 deletions .gitlab/custom-jobs-and-variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ variables:
artifacts:
reports:
junit: junit.xml

.reproducer_vars:
script:
- |
echo -e "
# Required variables \n
export MODULE_LIST=\"${MODULE_LIST}\" \n
export SPEC=\"${SPEC//\"/\\\"}\" \n
# Allow to set job script for debugging (only this differs from CI) \n
export DEBUG_MODE=true \n
# Using the CI build cache is optional and requires a token. Set it like so: \n
# export REGISTRY_TOKEN=\"<your token here>\" \n"
4 changes: 1 addition & 3 deletions .gitlab/jobs/corona.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# Override reproducer section to define Umpire specific variables.
.corona_reproducer_vars:
script:
- |
echo -e "export MODULE_LIST=\"${MODULE_LIST}\""
echo -e "export SPEC=\"${SPEC//\"/\\\"}\""
- !reference [.reproducer_vars, script]

########################
# Overridden shared jobs
Expand Down
4 changes: 1 addition & 3 deletions .gitlab/jobs/lassen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# Override reproducer section to define Umpire specific variables.
.lassen_reproducer_vars:
script:
- |
echo -e "export MODULE_LIST=\"${MODULE_LIST}\""
echo -e "export SPEC=\"${SPEC//\"/\\\"}\""
- !reference [.reproducer_vars, script]

########################
# Overridden shared jobs
Expand Down
4 changes: 1 addition & 3 deletions .gitlab/jobs/poodle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# Override reproducer section to define Umpire specific variables.
.poodle_reproducer_vars:
script:
- |
echo -e "export MODULE_LIST=\"${MODULE_LIST}\""
echo -e "export SPEC=\"${SPEC//\"/\\\"}\""
- !reference [.reproducer_vars, script]

########################
# Overridden shared jobs
Expand Down
4 changes: 1 addition & 3 deletions .gitlab/jobs/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# Override reproducer section to define UMPIRE specific variables.
.ruby_reproducer_vars:
script:
- |
echo -e "export MODULE_LIST=\"${MODULE_LIST}\""
echo -e "export SPEC=\"${SPEC//\"/\\\"}\""
- !reference [.reproducer_vars, script]

########################
# Overridden shared jobs
Expand Down
5 changes: 1 addition & 4 deletions .gitlab/jobs/tioga.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
# Override reproducer section to define Umpire specific variables.
.tioga_reproducer_vars:
script:
- |
echo -e "export MODULE_LIST=\"${MODULE_LIST}\""
echo -e "export SPEC=\"${SPEC//\"/\\\"}\""
- !reference [.reproducer_vars, script]

########################
# Overridden shared jobs
########################
# We duplicate the shared jobs description and add necessary changes for RAJA.
Expand Down
36 changes: 36 additions & 0 deletions cmake/SetupCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,42 @@ endif ()

if (ENABLE_HIP)
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -Wno-inconsistent-missing-override")

blt_check_code_compiles(CODE_COMPILES UMPIRE_ENABLE_HIP_COHERENCE_GRANULARITY
VERBOSE_OUTPUT OFF
DEPENDS_ON hip::host
SOURCE_STRING
[=[
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>

int main(int, char**)
{
const std::size_t bytes{1024};
void* ptr1{nullptr};

::hipHostMalloc(&ptr1, bytes, hipHostMallocDefault);

if (ptr1 != nullptr) {
void* ptr2{nullptr};
::hipHostMalloc(&ptr2, bytes, hipHostMallocNonCoherent);

if (ptr2 != nullptr) {
int device;
::hipGetDevice(&device);
::hipMemAdvise(ptr1, bytes, hipMemAdviseSetCoarseGrain, device);
}
}

return 0;
}
]=])

if (UMPIRE_ENABLE_HIP_COHERENCE_GRANULARITY)
message(STATUS "HIP memory coherence granularity: Enabled")
else ()
message(STATUS "HIP memory coherence granularity: Disabled, not supported")
endif ()
endif()

if (ENABLE_PEDANTIC_WARNINGS)
Expand Down
12 changes: 10 additions & 2 deletions examples/cookbook/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ if (UMPIRE_ENABLE_CUDA)
endif ()

if (UMPIRE_ENABLE_HIP)
if (UMPIRE_ENABLE_HIP_COHERENCE_GRANULARITY)
blt_add_executable(
NAME recipe_control_granularity
SOURCES recipe_control_granularity.cpp
DEPENDS_ON ${cookbook_depends})
list(APPEND umpire_cookbooks recipe_control_granularity)
endif ()

blt_add_executable(
NAME recipe_shrink
SOURCES recipe_shrink.cpp
Expand All @@ -138,12 +146,12 @@ if (UMPIRE_ENABLE_HIP)
recipe_pinned_pool.F
PROPERTIES
COMPILE_FLAGS -Mfree)
else()
else ()
set_source_files_properties(
recipe_pinned_pool.F
PROPERTIES
Fortran_FORMAT FREE)
endif()
endif ()
endif ()
endif ()

Expand Down
74 changes: 74 additions & 0 deletions examples/cookbook/recipe_control_granularity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016-22, Lawrence Livermore National Security, LLC and Umpire
// project contributors. See the COPYRIGHT file for details.
//
// SPDX-License-Identifier: (MIT)
//////////////////////////////////////////////////////////////////////////////
#include <hip/hip_runtime_api.h>

#include <iostream>
#include <string>
#include <vector>

#include "umpire/Allocator.hpp"
#include "umpire/ResourceManager.hpp"

// Statistics information for allocated memory
struct myMemStats {
friend std::ostream& operator<<(std::ostream& stream, const myMemStats& mstats);

myMemStats(void* ptr) : name{umpire::ResourceManager::getInstance().getAllocator(ptr).getName()}
{
if (::hipPointerGetAttributes(&hipattrs, ptr) != hipSuccess) {
std::cout << "Allocator: (" << name << ") Error: hipPointerGetAttributes failed for address: " << ptr
<< std::endl;
}
}

void print(std::ostream& stream) const
{
stream << name << std::endl
<< " Memory Type: " << hipattrs.type << std::endl
<< " device: " << hipattrs.device << std::endl
<< " hostPointer: " << hipattrs.hostPointer << std::endl
<< " devicePointer: " << hipattrs.devicePointer << std::endl
<< " allocationFlags: " << hipattrs.allocationFlags << std::endl;
}

hipPointerAttribute_t hipattrs;
std::string name;
};

std::ostream& operator<<(std::ostream& stream, const myMemStats& mstats)
{
mstats.print(stream);
return stream;
}

int main(int, char**)
{
const std::vector<std::string> resources{"DEVICE::COARSE", "DEVICE::FINE", "DEVICE::0::COARSE", "UM::FINE",
"UM::COARSE", "PINNED::FINE", "PINNED::COARSE"};

for (auto&& resource : resources) {
auto& rm = umpire::ResourceManager::getInstance();
auto alloc = rm.getAllocator(resource);

std::vector<void*> ptrs;
const int N{1};
int size{2};

for (int i = 0; i < N; i++) {
ptrs.push_back(alloc.allocate(size));
size *= 2;
}

for (int i = 0; i < N; i++) {
myMemStats stat{ptrs[i]};
std::cout << stat << std::endl;
alloc.deallocate(ptrs[i]);
}
}

return 0;
}
Loading

0 comments on commit c458f02

Please sign in to comment.