Skip to content

Commit

Permalink
Merge branch 'development' into more_soa_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSinn authored Jul 22, 2023
2 parents 7cb63ed + e41dbfa commit 9196be0
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 81 deletions.
3 changes: 0 additions & 3 deletions Src/Base/AMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,11 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse,
if (invalid) curr_fpe_excepts |= FE_INVALID;
if (divbyzero) curr_fpe_excepts |= FE_DIVBYZERO;
if (overflow) curr_fpe_excepts |= FE_OVERFLOW;
#if !defined(AMREX_USE_SYCL) && (!defined(__PGI) || (__PGIC__ >= 16))
// xxxxx SYCL todo: fpe trap
prev_fpe_excepts = fegetexcept();
if (curr_fpe_excepts != 0) {
feenableexcept(curr_fpe_excepts); // trap floating point exceptions
prev_handler_sigfpe = std::signal(SIGFPE, BLBackTrace::handler);
}
#endif

#elif defined(__APPLE__) && defined(__x86_64__)
prev_fpe_mask = _MM_GET_EXCEPTION_MASK();
Expand Down
17 changes: 13 additions & 4 deletions Src/Base/AMReX_GpuDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ Device::Initialize ()

#elif defined(AMREX_USE_SYCL)

#if 0
auto const& d = *sycl_device;
if (d.has(sycl::aspect::ext_intel_device_info_uuid)) {
auto uuid = d.get_info<sycl::ext::intel::info::device::uuid>();
Expand All @@ -345,10 +344,20 @@ Device::Initialize ()
}
num_devices_used = uuid_counts.size();
num_device_partners = uuid_counts[my_uuid];
}
#else
num_device_partners = 1; // xxxxx SYCL: todo, also check memory available when implicit scaling is off.

#if 0
for (int i = 0; i < ParallelDescriptor::NProcs(); ++i) {
if (i == ParallelDescriptor::MyProc()) {
std::cout << "Proc. " << i << ": |";
for (auto x : uuid) {
std::cout << std::hex << static_cast<unsigned int>(x) << "|";
}
std::cout << std::endl;;
}
ParallelDescriptor::Barrier();
}
#endif
}

#endif

Expand Down
22 changes: 8 additions & 14 deletions Src/Base/AMReX_GpuUtility.H
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ namespace Gpu {
CUresult r = cuPointerGetAttributes(1, &attrib, data, (CUdeviceptr)p);
return r == CUDA_SUCCESS && is_managed;
#elif defined(AMREX_USE_SYCL)
amrex::ignore_unused(p);
// xxxxx SYCL todo: get_pointer_type
// auto const info = sycl::get_pointer_info(p);
// auto type = sycl::get_pointer_type(p,Device::syclContext());
return false;
auto type = sycl::get_pointer_type(p,Device::syclContext());
return type == sycl::usm::alloc::shared;
#else
amrex::ignore_unused(p);
return false;
Expand All @@ -74,9 +71,8 @@ namespace Gpu {
CUresult r = cuPointerGetAttributes(1, &attrib, data, (CUdeviceptr)p);
return r == CUDA_SUCCESS && mem_type == CU_MEMORYTYPE_DEVICE;
#elif defined(AMREX_USE_SYCL)
amrex::ignore_unused(p);
// xxxxx SYCL todo: get_pointer_type
return false;
auto type = sycl::get_pointer_type(p,Device::syclContext());
return type == sycl::usm::alloc::device;
#else
amrex::ignore_unused(p);
return false;
Expand All @@ -95,9 +91,8 @@ namespace Gpu {
CUresult r = cuPointerGetAttributes(1, &attrib, data, (CUdeviceptr)p);
return r == CUDA_SUCCESS && mem_type == CU_MEMORYTYPE_HOST;
#elif defined(AMREX_USE_SYCL)
amrex::ignore_unused(p);
// xxxxx SYCL todo: get_pointer_type
return false;
auto type = sycl::get_pointer_type(p,Device::syclContext());
return type == sycl::usm::alloc::host;
#else
amrex::ignore_unused(p);
return false;
Expand Down Expand Up @@ -126,9 +121,8 @@ namespace Gpu {
mem_type == CU_MEMORYTYPE_ARRAY ||
mem_type == CU_MEMORYTYPE_UNIFIED);
#elif defined(AMREX_USE_SYCL)
amrex::ignore_unused(p);
// xxxxx SYCL todo: get_pointer_type
return false;
auto type = sycl::get_pointer_type(p,Device::syclContext());
return type != sycl::usm::alloc::unknown;
#else
amrex::ignore_unused(p);
return false;
Expand Down
7 changes: 4 additions & 3 deletions Src/Base/AMReX_ParallelReduce.H
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ namespace detail {
inline void Reduce (ReduceOp op, T* v, int cnt, int root, MPI_Comm comm)
{
auto mpi_op = mpi_ops[static_cast<int>(op)]; // NOLINT
Vector<T> tmp(v, v+cnt);
if (root == -1) {
// TODO: add BL_COMM_PROFILE commands
MPI_Allreduce(tmp.data(), v, cnt, ParallelDescriptor::Mpi_typemap<T>::type(),
MPI_Allreduce(MPI_IN_PLACE, v, cnt, ParallelDescriptor::Mpi_typemap<T>::type(),
mpi_op, comm);
} else {
// TODO: add BL_COMM_PROFILE commands
MPI_Reduce(tmp.data(), v, cnt, ParallelDescriptor::Mpi_typemap<T>::type(),
const auto* sendbuf = (ParallelDescriptor::MyProc(comm) == root) ?
(void const*)(MPI_IN_PLACE) : (void const*) v;
MPI_Reduce(sendbuf, v, cnt, ParallelDescriptor::Mpi_typemap<T>::type(),
mpi_op, root, comm);
}
}
Expand Down
36 changes: 22 additions & 14 deletions Src/Base/AMReX_ParmParse.H
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,24 @@ class IntVect;
//
// Comments in an input file include all text from a '#' character to the
// end of the line. Here is an example input file:
//
// niter = 100 # niter is an integer
// title = "Double Wammy" # example of a string with spaces
// cell_size = 0.5 0.75 # cell spacing in each dimension
// plot.var = Density 1 10 # a list of values
// plot.var = Energy 5 12 # another list of values
// bigarray = 1 2 3 4 5 6 7 8 # first part of array
// 9 10 11 12 # continuation of bigarray
// test = apple "boy blue" 10 20 30 40
// FILE = prob_file # insert contents of this "prob_file" here
//
// The "FILE = <filename>" definition is special. Rather than just
/*
niter = 100 # niter is an integer
title = "Double Wammy" # example of a string with spaces
cell_size = 0.5 0.75 # cell spacing in each dimension
plot.var = Density 1 10 # a list of values
plot.var = Energy 5 12 # another list of values
bigarray = 1 2 3 4 5 6 7 8 \
9 10 11 12 # continuation of bigarray
multi_line_string = "This is a
multi-line string."
test = apple "boy blue" 10 20 30 40
FILE = prob_file # insert contents of this "prob_file" here
*/
// For values spanning multiple lines, one must use '\' at the end of a line
// for continuation, otherwise it's a runtime error. Note that there must be
// at least one space before the continuation character `\`. Multiple lines
// inside a pair of double quotes are considered a single string containing
// '\n's. The "FILE = <filename>" definition is special. Rather than just
// adding this entry to the database, it reads the contents of <filename>
// into the database.
//
Expand Down Expand Up @@ -229,10 +235,12 @@ class IntVect;
*
* plot.var = Energy 5 12
*
* bigarray = 1 2 3 4 5 6 7 8
*
* bigarray = 1 2 3 4 5 6 7 8 \
* 9 10 11 12
*
* multi_line_string = "This is a
* multi-line string."
*
* aBox = ((0,0) (5,5))
*
* test = apple "boy blue" 10 20 30 40
Expand Down
95 changes: 73 additions & 22 deletions Src/Base/AMReX_ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <iostream>
#include <iterator>
#include <list>
#include <numeric>
#include <regex>
#include <set>
#include <sstream>
Expand Down Expand Up @@ -257,9 +258,10 @@ state_name[] =
"LIST"
};

void
int
eat_garbage (const char*& str)
{
int num_linefeeds = 0;
for (;;)
{
if ( *str == 0 ) break; // NOLINT
Expand All @@ -271,31 +273,41 @@ eat_garbage (const char*& str)
}
continue;
}
else if ( isspace(*str) )
else if ( std::isspace(*str) )
{
if (*str == '\n') { ++num_linefeeds; }
str++;
}
else if ( *str == '\\' ) // '\' followed by a line break is continuation to next line
{
// Unfortunately, a line break has three variants, \r, \n, and \r\n.
if (*(str+1) == '\n') {
str += 2;
} else if (*(str+1) == '\r') {
if (*(str+2) == '\n') {
str += 3;
} else {
str += 2;
}
} else {
break;
}
}
else
{
break;
}
}
return num_linefeeds;
}

PType
getToken (const char*& str,
std::string& ostr)
{
#define ERROR_MESS \
amrex::ErrorStream() << "ParmParse::getToken(): invalid string = " << ostr << '\n'; \
amrex::ErrorStream() << "STATE = " << state_name[state] \
<< ", next char = " << ch << '\n'; \
amrex::ErrorStream() << ", rest of input = \n" << str << '\n'; \
amrex::Abort()
getToken (const char*& str, std::string& ostr, int& num_linefeeds)
{
//
// Eat white space and comments.
//
eat_garbage(str);
num_linefeeds = eat_garbage(str);
//
// Check for end of file.
//
Expand Down Expand Up @@ -343,7 +355,7 @@ getToken (const char*& str,
str++;
return pCloseBracket;
}
else if ( isalpha(ch) )
else if ( std::isalpha(ch) )
{
ostr += ch; str++;
state = IDENTIFIER;
Expand All @@ -355,11 +367,11 @@ getToken (const char*& str,
}
break;
case IDENTIFIER:
if ( isalnum(ch) || ch == '_' || ch == '.' || ch == '[' || ch == ']' || ch == '+' || ch == '-' )
if ( std::isalnum(ch) || ch == '_' || ch == '.' || ch == '[' || ch == ']' || ch == '+' || ch == '-' )
{
ostr += ch; str++;
}
else if ( isspace(ch) || ch == '=' )
else if ( std::isspace(ch) || ch == '=' )
{
return pDefn;
}
Expand Down Expand Up @@ -388,7 +400,7 @@ getToken (const char*& str,
}
break;
case STRING:
if ( isspace(ch) || ch == '=' )
if ( std::isspace(ch) || ch == '=' )
{
return pValue;
}
Expand All @@ -409,10 +421,13 @@ getToken (const char*& str,
}
break;
default:
ERROR_MESS;
amrex::ErrorStream() << "ParmParse::getToken(): invalid string = " << ostr << '\n'
<< "STATE = " << state_name[state]
<< ", next char = " << ch << '\n'
<< ", rest of input = \n" << str << '\n';
amrex::Abort();
}
}
#undef ERROR_MESS
}


Expand Down Expand Up @@ -676,12 +691,14 @@ bldTable (const char*& str,
std::list<std::string> cur_list;
ParmParse::Table cur_table;
std::string tmp_str;
std::vector<int> cur_linefeeds;

for (;;)
{
std::string tokname;
int num_linefeeds;

PType token = getToken(str,tokname);
PType token = getToken(str,tokname, num_linefeeds);

switch (token)
{
Expand All @@ -692,6 +709,16 @@ bldTable (const char*& str,
}
AMREX_FALLTHROUGH;
case pEOF:
if (std::accumulate(cur_linefeeds.begin(), cur_linefeeds.end(), int(0)) > 0)
{
std::string error_message("ParmParse: Multiple lines in ");
error_message.append(cur_name).append(" =");
for (auto const& x : cur_list) {
error_message.append(" ").append(x);
}
error_message.append(". Must use \\ for line continuation.");
amrex::Abort(error_message);
}
addDefn(cur_name,cur_list,tab);
return;
case pOpenBracket:
Expand All @@ -703,6 +730,17 @@ bldTable (const char*& str,
{
tmp_str = cur_list.back();
cur_list.pop_back();
cur_linefeeds.pop_back();
if (std::accumulate(cur_linefeeds.begin(), cur_linefeeds.end(), int(0)) > 0)
{
std::string error_message("ParmParse: Multiple lines in ");
error_message.append(cur_name).append(" =");
for (auto const& x : cur_list) {
error_message.append(" ").append(x);
}
error_message.append(". Must use \\ for line continuation.");
amrex::Abort(error_message);
}
addDefn(cur_name, cur_list, tab);
cur_name = tmp_str;
}
Expand All @@ -716,14 +754,26 @@ bldTable (const char*& str,
}
if ( !cur_list.empty() )
{
//
// Read one too far, remove last name on list.
//
tmp_str = cur_list.back();
cur_list.pop_back();
cur_linefeeds.pop_back();
if (std::accumulate(cur_linefeeds.begin(), cur_linefeeds.end(), int(0)) > 0)
{
std::string error_message("ParmParse: Multiple lines in ");
error_message.append(cur_name).append(" =");
for (auto const& x : cur_list) {
error_message.append(" ").append(x);
}
error_message.append(". Must use \\ for line continuation.");
amrex::Abort(error_message);
}
addDefn(cur_name,cur_list,tab);
cur_name = tmp_str;
}
//
// Read one too far, remove last name on list.
//
cur_linefeeds.clear();
break;
case pDefn:
if ( cur_name.empty() )
Expand All @@ -743,6 +793,7 @@ bldTable (const char*& str,
amrex::Abort(msg.c_str());
}
cur_list.push_back(tokname);
cur_linefeeds.push_back(num_linefeeds);
break;
}
}
Expand Down
Loading

0 comments on commit 9196be0

Please sign in to comment.