From efd9d54fef90f52dcdf9c2a449799b6d5f1165e6 Mon Sep 17 00:00:00 2001 From: jpekkila Date: Tue, 30 Jul 2019 14:34:44 +0300 Subject: [PATCH] Stashing WIP changes (interface revision) s.t. I can continue work on a different machine --- include/astaroth.h | 92 +-------------------------- include/astaroth_defines.h | 6 +- include/astaroth_device.h | 124 +++++++++++++++++++++++++++++++++++++ include/astaroth_grid.h | 107 ++++++++++++++++++++++++++++++++ include/astaroth_node.h | 123 ++++++++++++++++++++++++++++++++++++ src/core/astaroth.cu | 2 + src/core/device.cuh | 107 -------------------------------- src/core/grid.cu | 0 src/core/node.cu | 22 +++++++ 9 files changed, 382 insertions(+), 201 deletions(-) create mode 100644 include/astaroth_device.h create mode 100644 include/astaroth_grid.h create mode 100644 include/astaroth_node.h delete mode 100644 src/core/device.cuh create mode 100644 src/core/grid.cu create mode 100644 src/core/node.cu diff --git a/include/astaroth.h b/include/astaroth.h index 52ba3d0..1aef514 100644 --- a/include/astaroth.h +++ b/include/astaroth.h @@ -24,95 +24,9 @@ extern "C" { #include "astaroth_defines.h" -/** Checks whether there are any CUDA devices available. Returns AC_SUCCESS if there is 1 or more, - * AC_FAILURE otherwise. */ -AcResult acCheckDeviceAvailability(void); - -/** Synchronizes the stream shared by all GPUs in the node. Synchronizes all streams if STREAM_ALL - * passed as a parameter */ -AcResult acSynchronizeStream(const StreamType stream); - -/** Synchronizes the mesh distributed across multiple GPUs. Must be called if the data in the halos - * of neighboring GPUs has been modified by an asynchronous function, f.ex. acBoundcondStep() */ -AcResult acSynchronizeMesh(void); - -/** Starting point of all GPU computation. Handles the allocation and -initialization of *all memory needed on all GPUs in the node*. In other words, -setups everything GPU-side so that calling any other GPU interface function -afterwards does not result in illegal memory accesses. */ -AcResult acInit(const AcMeshInfo mesh_info); - -/** Frees all GPU allocations and resets all devices in the node. Should be - * called at exit. */ -AcResult acQuit(void); - -/** Does all three substeps of the RK3 integration and computes the boundary -conditions when necessary. The result is synchronized and the boundary conditions are applied -after the final substep, after which the result can be fetched to CPU memory with acStore. */ -AcResult acIntegrate(const AcReal dt); - -/** Performs a scalar reduction on all GPUs in the node and returns the result. Operates on the - * whole computational domain, which must be up to date and synchronized before calling - * acReduceScal. - */ -AcReal acReduceScal(const ReductionType rtype, const VertexBufferHandle a); - -/** Performs a vector reduction on all GPUs in the node and returns the result. Operates on the - * whole computational domain, which must be up to date and synchronized before calling - * acReduceVec. - */ -AcReal acReduceVec(const ReductionType rtype, const VertexBufferHandle a, - const VertexBufferHandle b, const VertexBufferHandle c); - -/** Distributes the host mesh among the GPUs in the node. Synchronous. */ -AcResult acLoad(const AcMesh host_mesh); - -/** Gathers the mesh stored across GPUs in the node and stores it back to host memory. Synchronous. - */ -AcResult acStore(AcMesh* host_mesh); - -/* - * ============================================================================= - * Astaroth interface: Advanced functions. Asynchronous. - * ============================================================================= - */ -/** Loads a parameter to the constant memory of all GPUs in the node. Asynchronous. */ -AcResult acLoadDeviceConstant(const AcRealParam param, const AcReal value); -AcResult acLoadDeviceConstantAsync(const AcRealParam param, const AcReal value, - const StreamType stream); - -/** Splits a subset of the host_mesh and distributes it among the GPUs in the node. Asynchronous. */ -AcResult acLoadWithOffset(const AcMesh host_mesh, const int3 start, const int num_vertices); -AcResult acLoadWithOffsetAsync(const AcMesh host_mesh, const int3 start, const int num_vertices, - const StreamType stream); - -/** Gathers a subset of the data distributed among the GPUs in the node and stores the mesh back to - * CPU memory. Asynchronous. - */ -AcResult acStoreWithOffset(const int3 start, const int num_vertices, AcMesh* host_mesh); -AcResult acStoreWithOffsetAsync(const int3 start, const int num_vertices, AcMesh* host_mesh, - const StreamType stream); - -/** Performs a single RK3 step without computing boundary conditions. Asynchronous.*/ -AcResult acIntegrateStep(const int isubstep, const AcReal dt); -AcResult acIntegrateStepAsync(const int isubstep, const AcReal dt, const StreamType stream); - -/** Performs a single RK3 step on a subset of the mesh without computing the boundary conditions. - * Asynchronous.*/ -AcResult acIntegrateStepWithOffset(const int isubstep, const AcReal dt, const int3 start, - const int3 end); -AcResult acIntegrateStepWithOffsetAsync(const int isubstep, const AcReal dt, const int3 start, - const int3 end, const StreamType stream); - -/** Performs the boundary condition step on the GPUs in the node. Asynchronous. */ -AcResult acBoundcondStep(void); -AcResult acBoundcondStepAsync(const StreamType stream); - -/* - * ============================================================================= - * Revised interface - * ============================================================================= - */ +#include "astaroth_device.h" +#include "astaroth_grid.h" +#include "astaroth_node.h" #ifdef __cplusplus } // extern "C" diff --git a/include/astaroth_defines.h b/include/astaroth_defines.h index 73a25d9..7aa9751 100644 --- a/include/astaroth_defines.h +++ b/include/astaroth_defines.h @@ -104,11 +104,7 @@ typedef enum { NUM_REDUCTION_TYPES } ReductionType; -typedef enum { - STREAM_DEFAULT, - NUM_STREAM_TYPES, // - STREAM_ALL -} StreamType; +typedef enum { STREAM_DEFAULT, NUM_STREAM_TYPES } Stream; #define AC_GEN_ID(X) X typedef enum { diff --git a/include/astaroth_device.h b/include/astaroth_device.h new file mode 100644 index 0000000..d98ffcb --- /dev/null +++ b/include/astaroth_device.h @@ -0,0 +1,124 @@ +/* + Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae. + + This file is part of Astaroth. + + Astaroth is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Astaroth is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Astaroth. If not, see . +*/ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "astaroth_defines.h" + +typedef struct device_s* Device; // Opaque pointer to device_s. Analogous to dispatchable handles + // in Vulkan, f.ex. VkDevice + +/** */ +AcResult acDeviceCreate(const int id, const AcMeshInfo device_config, Device* device); + +/** */ +AcResult acDeviceDestroy(Device device); + +/** */ +AcResult acDevicePrintInfo(const Device device); + +/** */ +AcResult acDeviceAutoOptimize(const Device device); + +/** */ +AcResult acDeviceSynchronizeStream(const Device device, const Stream stream); + +/** */ +AcResult acDeviceSwapBuffers(const Device device); + +/** */ +AcResult acDeviceLoadConstant(const Device device, const Stream stream, const AcRealParam param, + const AcReal value); + +/** */ +AcResult acDeviceLoadVertexBufferWithOffset(const Device device, const Stream stream, + const AcMesh host_mesh, + const VertexBufferHandle vtxbuf_handle, const int3 src, + const int3 dst, const int num_vertices); + +/** */ +AcResult acDeviceLoadMeshWithOffset(const Device device, const Stream stream, + const AcMesh host_mesh, const int3 src, const int3 dst, + const int num_vertices); + +/** */ +AcResult acDeviceLoadVertexBuffer(const Device device, const Stream stream, const AcMesh host_mesh, + const VertexBufferHandle vtxbuf_handle); + +/** */ +AcResult acDeviceLoadMesh(const Device device, const Stream stream, const AcMesh host_mesh); + +/** */ +AcResult acDeviceStoreVertexBufferWithOffset(const Device device, const Stream stream, + const VertexBufferHandle vtxbuf_handle, const int3 src, + const int3 dst, const int num_vertices, + AcMesh* host_mesh); + +/** */ +AcResult acDeviceStoreMeshWithOffset(const Device device, const Stream stream, const int3 src, + const int3 dst, const int num_vertices, AcMesh* host_mesh); + +/** */ +AcResult acDeviceStoreVertexBuffer(const Device device, const Stream stream, + const VertexBufferHandle vtxbuf_handle, AcMesh* host_mesh); + +/** */ +AcResult acDeviceStoreMesh(const Device device, const Stream stream, AcMesh* host_mesh); + +/** */ +AcResult acDeviceTransferVertexBufferWithOffset(const Device src_device, const Stream stream, + const VertexBufferHandle vtxbuf_handle, + const int3 src, const int3 dst, + const int num_vertices, Device* dst_device); + +/** */ +AcResult acDeviceTransferMeshWithOffset(const Device src_device, const Stream stream, + const int3 src, const int3 dst, const int num_vertices, + Device* dst_device); + +/** */ +AcResult acDeviceTransferVertexBuffer(const Device src_device, const Stream stream, + const VertexBufferHandle vtxbuf_handle, Device* dst_device); + +/** */ +AcResult acDeviceTransferMesh(const Device src_device, const Stream stream, Device* dst_device); + +/** */ +AcResult acDeviceIntegrateSubstep(const Device device, const StreamType stream_type, + const int step_number, const int3 start, const int3 end, + const AcReal dt); +/** */ +AcResult acDevicePeriodicBoundcondStep(const Device device, const StreamType stream_type, + const int3 start, const int3 end); +/** */ +AcResult acDeviceReduceScal(const Device device, const StreamType stream_type, + const ReductionType rtype, const VertexBufferHandle vtxbuf_handle, + AcReal* result); +/** */ +AcResult acDeviceReduceVec(const Device device, const StreamType stream_type, + const ReductionType rtype, const VertexBufferHandle vec0, + const VertexBufferHandle vec1, const VertexBufferHandle vec2, + AcReal* result); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/include/astaroth_grid.h b/include/astaroth_grid.h new file mode 100644 index 0000000..4200343 --- /dev/null +++ b/include/astaroth_grid.h @@ -0,0 +1,107 @@ +/* + Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae. + + This file is part of Astaroth. + + Astaroth is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Astaroth is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Astaroth. If not, see . +*/ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "astaroth_defines.h" + +/** */ +AcResult acGridInit(const AcMeshInfo node_config); + +/** */ +AcResult acGridQuit(void); + +/** */ +AcResult acGridSynchronize(void); + +/** */ +AcResult acGridSwapBuffers(void); + +/** */ +AcResult acGridLoadConstant(const Stream stream, const AcRealParam param, const AcReal value); + +/** */ +AcResult acGridLoadVertexBufferWithOffset(const Stream stream, const AcMesh host_mesh, + const VertexBufferHandle vtxbuf_handle, const int3 src, + const int3 dst, const int num_vertices); + +/** */ +AcResult acGridLoadMeshWithOffset(const Stream stream, const AcMesh host_mesh, const int3 src, + const int3 dst, const int num_vertices); + +/** */ +AcResult acGridLoadVertexBuffer(const Stream stream, const AcMesh host_mesh, + const VertexBufferHandle vtxbuf_handle); + +/** */ +AcResult acGridLoadMesh(const Stream stream, const AcMesh host_mesh); + +/** */ +AcResult acGridStoreVertexBufferWithOffset(const Stream stream, + const VertexBufferHandle vtxbuf_handle, const int3 src, + const int3 dst, const int num_vertices, + AcMesh* host_mesh); + +/** */ +AcResult acGridStoreMeshWithOffset(const Stream stream, const int3 src, const int3 dst, + const int num_vertices, AcMesh* host_mesh); + +/** */ +AcResult acGridStoreVertexBuffer(const Stream stream, const VertexBufferHandle vtxbuf_handle, + AcMesh* host_mesh); + +/** */ +AcResult acGridStoreMesh(const Stream stream, AcMesh* host_mesh); + +/** */ +AcResult acGridTransferVertexBufferWithOffset(const Stream stream, + const VertexBufferHandle vtxbuf_handle, + const int3 src, const int3 dst, + const int num_vertices); + +/** */ +AcResult acGridTransferMeshWithOffset(const Stream stream, const int3 src, const int3 dst, + const int num_vertices); + +/** */ +AcResult acGridTransferVertexBuffer(const Stream stream, const VertexBufferHandle vtxbuf_handle); + +/** */ +AcResult acGridTransferMesh(const Stream stream); + +/** */ +AcResult acGridIntegrateSubstep(const StreamType stream_type, const int step_number, + const int3 start, const int3 end, const AcReal dt); +/** */ +AcResult acGridPeriodicBoundcondStep(const StreamType stream_type, const int3 start, + const int3 end); +/** */ +AcResult acGridReduceScal(const StreamType stream_type, const ReductionType rtype, + const VertexBufferHandle vtxbuf_handle, AcReal* result); +/** */ +AcResult acGridReduceVec(const StreamType stream_type, const ReductionType rtype, + const VertexBufferHandle vec0, const VertexBufferHandle vec1, + const VertexBufferHandle vec2, AcReal* result); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/include/astaroth_node.h b/include/astaroth_node.h new file mode 100644 index 0000000..83e0a45 --- /dev/null +++ b/include/astaroth_node.h @@ -0,0 +1,123 @@ +/* + Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae. + + This file is part of Astaroth. + + Astaroth is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Astaroth is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Astaroth. If not, see . +*/ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include "astaroth_defines.h" + +typedef struct node_s* Node; + +/** */ +AcResult acNodeCreate(const AcMeshInfo node_config, Node* node); + +/** */ +AcResult acNodeDestroy(Node node); + +/** */ +AcResult acNodeQueryDeviceConfiguration(const Node node, DeviceConfiguration* config); + +/** */ +AcResult acNodeSynchronizeStream(const Node node, const Stream stream); + +/** */ +AcResult acNodeSynchronizeVertexBuffer(const Node node, const Stream stream, + const VertexBufferHandle vtxbuf_handle); + +/** */ +AcResult acNodeSynchronizeMesh(const Node node, const Stream stream); + +/** */ +AcResult acNodeSwapBuffers(const Node node); + +/** */ +AcResult acNodeLoadConstant(const Node node, const Stream stream, const AcRealParam param, + const AcReal value); + +/** */ +AcResult acNodeLoadVertexBufferWithOffset(const Node node, const Stream stream, + const AcMesh host_mesh, + const VertexBufferHandle vtxbuf_handle, const int3 src, + const int3 dst, const int num_vertices); + +/** */ +AcResult acNodeLoadMeshWithOffset(const Node node, const Stream stream, const AcMesh host_mesh, + const int3 src, const int3 dst, const int num_vertices); + +/** */ +AcResult acNodeLoadVertexBuffer(const Node node, const Stream stream, const AcMesh host_mesh, + const VertexBufferHandle vtxbuf_handle); + +/** */ +AcResult acNodeLoadMesh(const Node node, const Stream stream, const AcMesh host_mesh); + +/** */ +AcResult acNodeStoreVertexBufferWithOffset(const Node node, const Stream stream, + const VertexBufferHandle vtxbuf_handle, const int3 src, + const int3 dst, const int num_vertices, + AcMesh* host_mesh); + +/** */ +AcResult acNodeStoreMeshWithOffset(const Node node, const Stream stream, const int3 src, + const int3 dst, const int num_vertices, AcMesh* host_mesh); + +/** */ +AcResult acNodeStoreVertexBuffer(const Node node, const Stream stream, + const VertexBufferHandle vtxbuf_handle, AcMesh* host_mesh); + +/** */ +AcResult acNodeStoreMesh(const Node node, const Stream stream, AcMesh* host_mesh); + +/** */ +AcResult acNodeTransferVertexBufferWithOffset(const Node src_node, const Stream stream, + const VertexBufferHandle vtxbuf_handle, + const int3 src, const int3 dst, + const int num_vertices, Node* dst_node); + +/** */ +AcResult acNodeTransferMeshWithOffset(const Node src_node, const Stream stream, const int3 src, + const int3 dst, const int num_vertices, Node* dst_node); + +/** */ +AcResult acNodeTransferVertexBuffer(const Node src_node, const Stream stream, + const VertexBufferHandle vtxbuf_handle, Node* dst_node); + +/** */ +AcResult acNodeTransferMesh(const Node src_node, const Stream stream, Node* dst_node); + +/** */ +AcResult acNodeIntegrateSubstep(const Node node, const StreamType stream_type, + const int step_number, const int3 start, const int3 end, + const AcReal dt); +/** */ +AcResult acNodePeriodicBoundcondStep(const Node node, const StreamType stream_type, + const int3 start, const int3 end); +/** */ +AcResult acNodeReduceScal(const Node node, const StreamType stream_type, const ReductionType rtype, + const VertexBufferHandle vtxbuf_handle, AcReal* result); +/** */ +AcResult acNodeReduceVec(const Node node, const StreamType stream_type, const ReductionType rtype, + const VertexBufferHandle vec0, const VertexBufferHandle vec1, + const VertexBufferHandle vec2, AcReal* result); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/core/astaroth.cu b/src/core/astaroth.cu index 736956b..1cb9f1e 100644 --- a/src/core/astaroth.cu +++ b/src/core/astaroth.cu @@ -671,3 +671,5 @@ acLoadDeviceConstant(const AcRealParam param, const AcReal value) * Revised interface * ============================================================================= */ +======= +>>>>>>> Stashed changes diff --git a/src/core/device.cuh b/src/core/device.cuh deleted file mode 100644 index 7f1fad4..0000000 --- a/src/core/device.cuh +++ /dev/null @@ -1,107 +0,0 @@ -/* - Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae. - - This file is part of Astaroth. - - Astaroth is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Astaroth is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Astaroth. If not, see . -*/ - -/** - * @file - * \brief Brief info. - * - * Detailed info. - * - */ -#pragma once -#include "astaroth.h" - -typedef struct { - int3 m; - int3 n; -} Grid; - -typedef struct device_s* Device; // Opaque pointer to device_s. Analogous to dispatchable handles - // in Vulkan, f.ex. VkDevice - -/** */ -AcResult printDeviceInfo(const Device device); - -/** */ -AcResult createDevice(const int id, const AcMeshInfo device_config, Device* device); - -/** */ -AcResult destroyDevice(Device device); - -/** */ -AcResult boundcondStep(const Device device, const StreamType stream_type, const int3& start, - const int3& end); - -/** */ -AcResult reduceScal(const Device device, const StreamType stream_type, const ReductionType rtype, - const VertexBufferHandle vtxbuf_handle, AcReal* result); - -/** */ -AcResult reduceVec(const Device device, const StreamType stream_type, const ReductionType rtype, - const VertexBufferHandle vec0, const VertexBufferHandle vec1, - const VertexBufferHandle vec2, AcReal* result); - -/** */ -AcResult rkStep(const Device device, const StreamType stream_type, const int step_number, - const int3& start, const int3& end, const AcReal dt); - -/** Sychronizes the device with respect to stream_type. If STREAM_ALL is given as - a StreamType, the function synchronizes all streams on the device. */ -AcResult synchronize(const Device device, const StreamType stream_type); - -/** */ -AcResult copyMeshToDevice(const Device device, const StreamType stream_type, - const AcMesh& host_mesh, const int3& src, const int3& dst, - const int num_vertices); - -/** */ -AcResult copyMeshToHost(const Device device, const StreamType stream_type, const int3& src, - const int3& dst, const int num_vertices, AcMesh* host_mesh); - -/** */ -AcResult copyMeshDeviceToDevice(const Device src, const StreamType stream_type, const int3& src_idx, - Device dst, const int3& dst_idx, const int num_vertices); - -/** Swaps the input/output buffers used in computations */ -AcResult swapBuffers(const Device device); - -/** */ -AcResult loadDeviceConstant(const Device device, const StreamType stream_type, - const AcIntParam param, const int value); - -/** */ -AcResult loadDeviceConstant(const Device device, const StreamType stream_type, - const AcRealParam param, const AcReal value); - -/** */ -AcResult loadGlobalGrid(const Device device, const Grid grid); - -/** */ -AcResult autoOptimize(const Device device); - -// #define PACKED_DATA_TRANSFERS (1) %JP: placeholder for optimized ghost zone packing and transfers -#if PACKED_DATA_TRANSFERS -// Declarations used for packed data transfers -#endif - -/* - * ============================================================================= - * Revised interface - * ============================================================================= - */ diff --git a/src/core/grid.cu b/src/core/grid.cu new file mode 100644 index 0000000..e69de29 diff --git a/src/core/node.cu b/src/core/node.cu new file mode 100644 index 0000000..c3bfc05 --- /dev/null +++ b/src/core/node.cu @@ -0,0 +1,22 @@ +/* + Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae. + + This file is part of Astaroth. + + Astaroth is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Astaroth is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Astaroth. If not, see . +*/ +// #include "astaroth_node.h" + +struct node_s { +};