Skip to content

Commit

Permalink
Merge branch '82-milhoja-should-be-able-to-build-without-amrex' into …
Browse files Browse the repository at this point in the history
…'master'

Resolve "Milhoja should be able to build without AMReX"

Closes #82

See merge request joneal/OrchestrationRuntime!68
  • Loading branch information
ylee88 committed Jul 16, 2024
2 parents a12e7df + b02b0a5 commit 810ea5a
Show file tree
Hide file tree
Showing 28 changed files with 114 additions and 82 deletions.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ else ifeq ($(RUNTIME_BACKEND),HOSTMEM)
BACKEND_BUILDDIR := $(BUILDDIR)/FakeCudaBackend
endif


include $(CONFIG_MAKEFILE)

GRID_BACKEND := $(shell echo $(GRID_BACKEND) | tr A-Z a-z)

LIBNAME ?= milhoja
TARGET := $(BUILDDIR)/lib$(LIBNAME).a

Expand Down Expand Up @@ -64,10 +65,21 @@ endif

CPP_SRCS := $(wildcard $(SRCDIR)/Milhoja_*.cpp)
CPP_HDRS := $(wildcard $(INCDIR)/Milhoja_*.h)
CPP_SRCS_GRID := $(wildcard $(SRCDIR)/Milhoja_Grid*.cpp $(SRCDIR)/Milhoja_*Iter*.cpp)
CPP_HDRS_GRID := $(wildcard $(INCDIR)/Milhoja_Grid*.h $(INCDIR)/Milhoja_*Iter*.h)

ifeq ($(SUPPORT_PUSH),)
CPP_SRCS := $(filter-out $(SRCDIR)/Milhoja_TileFlashxr.cpp,$(CPP_SRCS))
CPP_HDRS := $(filter-out $(INCDIR)/Milhoja_TileFlashxr.h $(INCDIR)/Milhoja_FlashxrTileRaw.h,$(CPP_HDRS))
endif
ifeq ($(SUPPORT_EXEC),)
CPP_SRCS := $(filter-out $(SRCDIR)/Milhoja_TileAmrex.cpp,$(CPP_SRCS))
CPP_HDRS := $(filter-out $(INCDIR)/Milhoja_TileAmrex.h,$(CPP_HDRS))
endif
ifeq ($(GRID_BACKEND),none)
CPP_SRCS := $(filter-out $(CPP_SRCS_GRID),$(CPP_SRCS))
CPP_HDRS := $(filter-out $(CPP_HDRS_GRID),$(CPP_HDRS))
endif

CINT_SRCS := $(wildcard $(INTERFACEDIR)/Milhoja_*.cpp)
FINT_SRCS := $(wildcard $(INTERFACEDIR)/Milhoja_*.F90)
Expand Down
5 changes: 2 additions & 3 deletions includes/Milhoja_DataPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@
#define MILHOJA_DATA_PACKET_H__

#include <stdexcept>
#include <memory>
#include <deque>

#include "Milhoja.h"
#include "Milhoja_IntVect.h"
#include "Milhoja_RealVect.h"
#include "Milhoja_FArray4D.h"
#include "Milhoja_Tile.h"
#include "Milhoja_DataItem.h"
#include "Milhoja_Stream.h"
Expand Down
21 changes: 0 additions & 21 deletions includes/Milhoja_TileFlashxr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

#include <vector>

#include <AMReX.H>
#include <AMReX_Box.H>

#include "Milhoja.h"
#include "Milhoja_RealVect.h"
#include "Milhoja_IntVect.h"
Expand All @@ -18,28 +15,10 @@

namespace milhoja {

/**
* \brief Fully-implemented Tile class for use with AMReX.
*
* \todo lo/hi -> interiorBox(lo, hi)
* \todo loGC/hiGC -> dataArrayBox(lo, hi)
* \todo need grownTileBox as well.
*
* Contains a reference to the multifab for the appropriate level
* so pointers into it can be returned.
*/
class TileFlashxr
: public Tile
{
public:
TileFlashxr(const unsigned int level,
const int gridIdxOrBlkId,
const int tileIdx,
const amrex::Box&& interior,
const amrex::Box&& dataArray,
Real* unkBlkPtr,
std::vector<Real*>&& fluxBlkPtrs);

TileFlashxr(const FlashxrTileRawPtrs tP,
const FlashxTileRawInts tI,
const FlashxTileRawReals tR);
Expand Down
2 changes: 2 additions & 0 deletions includes/Milhoja_TileWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef MILHOJA_TILE_WRAPPER_H__
#define MILHOJA_TILE_WRAPPER_H__

#include <memory>

#include "Milhoja_Tile.h"

namespace milhoja {
Expand Down
2 changes: 2 additions & 0 deletions src/FakeCudaBackend/Milhoja_FakeCudaBackend.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Milhoja_FakeCudaBackend.h"

#include <cstring>

#include "Milhoja_Logger.h"
#include "Milhoja_FakeCudaGpuEnvironment.h"
#include "Milhoja_FakeCudaStreamManager.h"
Expand Down
1 change: 1 addition & 0 deletions src/Milhoja_RuntimeBackend.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Milhoja_RuntimeBackend.h"

#include <iostream>
#include <stdexcept>

#include "Milhoja.h"
Expand Down
58 changes: 11 additions & 47 deletions src/Milhoja_TileFlashxr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "Milhoja_TileFlashxr.h"

#include "Milhoja_Logger.h"
#include "Milhoja_Grid.h"

#include <cassert>


namespace milhoja {

Expand All @@ -19,53 +21,15 @@ namespace milhoja {
* \todo Include a single metadata routine that gets gId, level, lo/hi, and
* loGC/hiGC in one call? This could replace the lo(int*), etc. calls.
*
* \param level The 0-based refinement level of the tile
* \param gridIdx The integer index for the block that contains the tile
* \param tileIdx The local integer index for the tile in its block
* \param interior The lo/hi global indices of the tile's interior cells
* \param dataArray The lo/hi global indices of the tile's cell-centered data array
* \param unkBlkPtr The FAB containing the cell-centered data at the given
* level
* \param fluxBlkPtrs A vector of pointers to the FABs that store the
* face-centered flux data at the given level. If there are
* no flux variables for the problem, this vector should be
* empty. Otherwise, it should have MILHOJA_NDIM elements.
* \note Refer Milhoja_FlashxrTileRaw.h
*
* \param tP The struct that has raw pointers for constructing Flash-X tileDesc
* e.g.) Unk, FLUX[XYZ]
* \param tI The struct that has integer variables for constructing Flash-X tileDesc
* e.g.) level, tileIdx, ...
* \param tR The struct that has real variables for constructing Flash-X tileDesc
* e.g.) delta[XYZ]
*/
TileFlashxr::TileFlashxr(const unsigned int level,
const int gridIdx,
const int tileIdx,
const amrex::Box&& interior,
const amrex::Box&& dataArray,
Real* unkBlkPtr,
std::vector<Real*>&& fluxBlkPtrs)
: Tile{},
level_{level},
gridIdxOrBlkId_{gridIdx},
tileIdx_{tileIdx},
lo_{interior.smallEnd()}, hi_{interior.bigEnd()},
loGC_{dataArray.smallEnd()}, hiGC_{dataArray.bigEnd()},
nCcComp_{-1},
nFluxComp_{0},
deltas_{},
unkBlkPtr_{unkBlkPtr},
fluxBlkPtrs_{std::move(fluxBlkPtrs)}
{
for (auto i=0; i<fluxBlkPtrs_.size(); ++i) {
if (!(fluxBlkPtrs_[i])) {
throw std::invalid_argument("[TileFlashxr::TileFlashxr] Null flux data pointer");
}
}

#ifdef DEBUG_RUNTIME
std::string msg = "[TileFlashxr] Created Tile (level="
+ std::to_string(level_)
+ " / grid ID=" + std::to_string(gridIdxOrBlkId_)
+ " / tile ID=" + std::to_string(tileIdx_) + ") with "
+ std::to_string(fluxBlkPtrs_.size()) + " flux vars";
Logger::instance().log(msg);
#endif
}

TileFlashxr::TileFlashxr(const FlashxrTileRawPtrs tP,
const FlashxTileRawInts tI,
const FlashxTileRawReals tR)
Expand Down
53 changes: 53 additions & 0 deletions tools/milhoja_pypkg/src/milhoja/templates/cg-tpl.Tile_cpp2c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <iostream>
#include <Milhoja.h>
#include <Milhoja_real.h>
#include <Milhoja_interface_error_codes.h>
#include "_param:data_item_header_file_name"

extern "C" {
//----- C DECLARATION OF FORTRAN ROUTINE WITH C-COMPATIBLE INTERFACE
int _param:instance(
/* _link:c2f_dummy_args */
void** wrapper
) {
if (wrapper == nullptr) {
std::cerr << "[_param:instance] wrapper is NULL" << std::endl;
return MILHOJA_ERROR_POINTER_IS_NULL;
} else if (*wrapper != nullptr) {
std::cerr << "[_param:instance] *wrapper not NULL" << std::endl;
return MILHOJA_ERROR_POINTER_NOT_NULL;
}

try {
*wrapper = static_cast<void*>(new _param:class_name{
/* _link:constructor_args */
});
} catch (const std::exception& exc) {
std::cerr << exc.what() << std::endl;
return MILHOJA_ERROR_UNABLE_TO_CREATE_WRAPPER;
} catch (...) {
std::cerr << "[_param:instance] Unknown error caught" << std::endl;
return MILHOJA_ERROR_UNABLE_TO_CREATE_WRAPPER;
}
return MILHOJA_SUCCESS;
}

int _param:deletion(void* wrapper) {
if (wrapper == nullptr) {
std::cerr << "[_param:deletion] wrapper is NULL" << std::endl;
return MILHOJA_ERROR_POINTER_IS_NULL;
}
delete static_cast<_param:class_name*>(wrapper);
return MILHOJA_SUCCESS;
}

int _param:acquire_scratch(void) {
_param:class_name::acquireScratch();
return MILHOJA_SUCCESS;
}

int _param:release_scratch(void) {
_param:class_name::releaseScratch();
return MILHOJA_SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <Milhoja_Grid.h>
#include <Milhoja_RuntimeBackend.h>

#if 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
/* _link:includes */
#include <Milhoja.h>
#include <Milhoja_real.h>
#include <Milhoja_IntVect.h>
#include <Milhoja_RealVect.h>
#include <Milhoja_FArray4D.h>
#include <Milhoja_DataPacket.h>
#include <climits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <Milhoja_Grid.h>
#include <Milhoja_RuntimeBackend.h>

std::unique_ptr<milhoja::DataPacket> DataPacket_gpu_tf_hydro::clone(void) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <Milhoja.h>
#include <Milhoja_real.h>
#include <Milhoja_IntVect.h>
#include <Milhoja_RealVect.h>
#include <Milhoja_FArray4D.h>
#include <Milhoja_DataPacket.h>
#include <climits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <Milhoja_Grid.h>
#include <Milhoja_RuntimeBackend.h>

std::unique_ptr<milhoja::DataPacket> DataPacket_gpu_tf_hydro::clone(void) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <Milhoja.h>
#include <Milhoja_real.h>
#include <Milhoja_IntVect.h>
#include <Milhoja_RealVect.h>
#include <Milhoja_FArray4D.h>
#include <Milhoja_DataPacket.h>
#include <climits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <Milhoja_Grid.h>
#include <Milhoja_RuntimeBackend.h>

std::unique_ptr<milhoja::DataPacket> DataPacket_gpu_tf_hydro::clone(void) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <Milhoja.h>
#include <Milhoja_real.h>
#include <Milhoja_IntVect.h>
#include <Milhoja_RealVect.h>
#include <Milhoja_FArray4D.h>
#include <Milhoja_DataPacket.h>
#include <climits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <Milhoja_Grid.h>
#include <Milhoja_RuntimeBackend.h>

std::unique_ptr<milhoja::DataPacket> DataPacket_gpu_tf_hydro::clone(void) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <Milhoja.h>
#include <Milhoja_real.h>
#include <Milhoja_IntVect.h>
#include <Milhoja_RealVect.h>
#include <Milhoja_FArray4D.h>
#include <Milhoja_DataPacket.h>
#include <climits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <Milhoja_Grid.h>
#include <Milhoja_RuntimeBackend.h>

std::unique_ptr<milhoja::DataPacket> DataPacket_gpu_tf_hydro::clone(void) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <Milhoja.h>
#include <Milhoja_real.h>
#include <Milhoja_IntVect.h>
#include <Milhoja_RealVect.h>
#include <Milhoja_FArray4D.h>
#include <Milhoja_DataPacket.h>
#include <climits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <Milhoja_Grid.h>
#include <Milhoja_RuntimeBackend.h>

std::unique_ptr<milhoja::DataPacket> DataPacket_gpu_tf_dens::clone(void) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <Milhoja.h>
#include <Milhoja_real.h>
#include <Milhoja_IntVect.h>
#include <Milhoja_RealVect.h>
#include <Milhoja_FArray4D.h>
#include <Milhoja_DataPacket.h>
#include <climits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <Milhoja_Grid.h>
#include <Milhoja_RuntimeBackend.h>

std::unique_ptr<milhoja::DataPacket> DataPacket_gpu_tf_ener::clone(void) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <Milhoja.h>
#include <Milhoja_real.h>
#include <Milhoja_IntVect.h>
#include <Milhoja_RealVect.h>
#include <Milhoja_FArray4D.h>
#include <Milhoja_DataPacket.h>
#include <climits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <Milhoja_Grid.h>
#include <Milhoja_RuntimeBackend.h>

std::unique_ptr<milhoja::DataPacket> DataPacket_gpu_tf_fused_actions::clone(void) const {
Expand Down
Loading

0 comments on commit 810ea5a

Please sign in to comment.