diff --git a/README.md b/README.md index 6863d7620838563d5fb2db4f7be75098dc61309b..1f6f3123ee723dcc923a825e782feb09d3b0b34a 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,12 @@ Linux workstation with CUDA-compatible GPU (minimum 3.5 compute capability) - CMake >= 3.9 - gcc >= 4.9 - cuda >= 9.0 (> 11.5 recommended) + - spdlog >= 1.10.0 (note: this is normally installed to extern/spdlog by running `git submodule update --init` from this directory) ### Build process +From the root arbd directory (where this README is found), ensure you have spdlog installed to the extern directory, usually by running `git submodule update --init`. + From the root arbd directory (where this README is found), run: ``` ## Determine the compute capability of your CUDA-enabled graphics card @@ -52,4 +55,4 @@ ARBD2 is being developed by the Aksimentiev group - Christopher Maffeo <mailto:cmaffeo2@illinois.edu> - Han-yi Chao -Please direct questions or problems to Chris. \ No newline at end of file +Please direct questions, problems or suggestions to Chris. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 58105496ea8cf256dd4bb95e090b61043c4f1159..342243cfc0879395c5724ab0e4b1f36fc83fc384 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ add_library("lib${PROJECT_NAME}" ARBDException.cpp + Resource.cu GPUManager.cpp ParticlePatch.cpp SimSystem.cpp diff --git a/src/Patch.h b/src/Patch.h index f7559f5c71478b41a345c1e5e2b5564208e440f5..cd211f94457eae5a9dac48c3ec6bfb9d472e099a 100644 --- a/src/Patch.h +++ b/src/Patch.h @@ -39,6 +39,7 @@ private: // Particle data size_t num_particles; + idx_t* global_idx; // global index of particle size_t* type_ids; Pos* pos; Force* force; diff --git a/src/Proxy.h b/src/Proxy.h index 3f3dd0442de04a12f60854744460870c96641bdc..e1c49e553f9468cfe8994be5732929b0ce6df73f 100644 --- a/src/Proxy.h +++ b/src/Proxy.h @@ -2,44 +2,7 @@ #include <future> #include <iostream> -#include "ARBDException.h" - -/** - * @brief Represents a resource that can store data and perform computations. - */ -struct Resource { - /** - * @brief Enum to specify the type of the resource (e.g., CPU or GPU). - */ - enum ResourceType {CPU, MPI, GPU}; - ResourceType type; ///< Type of the resource. - size_t id; ///< ID or any other identifier associated with the resource. - - // Q: should this return True for GPU that is attached/assigned to current thread? Currently assuming yes. - HOST DEVICE bool is_local() const { - bool ret = true; -// #ifdef __CUDA_ACC__ -// ret = (type == GPU); -// #else -// ret = (type == CPU); -// #endif - LOGWARN("Resource::is_local() not fully implemented; returning {}",ret); - return ret; - }; - // HOST DEVICE static bool is_local() { // check if thread/gpu idx matches some global idx }; - - static Resource Local() { - LOGWARN("Resource::Local() not properly implemented"); -#ifdef __CUDA_ACC__ - return Resource{ GPU, 0 }; -#else - return Resource{ CPU, 0 }; -#endif - }; - bool operator==(const Resource& other) const { return type == other.type && id == other.id; }; - -}; - +#include "Resource.h" // START traits // These ugly bits of code help implement SFINAE in C++14 and should likely be removed if a newer standard is adopted diff --git a/src/Resource.cu b/src/Resource.cu new file mode 100644 index 0000000000000000000000000000000000000000..bff4d609fe55a4fb79d8830a81b729f86b910b92 --- /dev/null +++ b/src/Resource.cu @@ -0,0 +1,15 @@ +#include "Resource.h" + +HOST DEVICE size_t current_thread_idx() { +#ifdef USE_MPI + Exception( NotImplementedError, "current_thread_idx() not implemented on GPU" ); + int world_rank; + return MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); +#else +#ifdef __CUDA_ACC__ + Exception( NotImplementedError, "current_thread_idx() not implemented on GPU" ); +#else + return 0; +#endif +#endif +} diff --git a/src/Resource.h b/src/Resource.h new file mode 100644 index 0000000000000000000000000000000000000000..8a6b054af8ea8e2e1f54dc6d0139ea9ae4680f88 --- /dev/null +++ b/src/Resource.h @@ -0,0 +1,68 @@ +#pragma once + +#ifdef USE_MPI +#include <mpi.h> +#endif + +#include "ARBDException.h" +#include "GPUManager.h" + + +HOST DEVICE size_t current_thread_idx(); + + + +/** + * @brief Represents a resource that can store data and perform computations. + */ +struct Resource { + /** + * @brief Enum to specify the type of the resource (e.g., CPU or GPU). + */ + enum ResourceType {CPU, MPI, GPU}; + ResourceType type; ///< Type of the resource. + size_t id; ///< Unique identifier associated with the resource. + Resource* parent; ///< Parent resource; nullptr unless type is GPU + + /** + * @brief Checks if the resource is running on the calling thread. + */ + HOST DEVICE bool is_running() const { + bool ret = true; +// #ifdef __CUDA_ACC__ +// ret = (type == GPU); +// #else +// ret = (type == CPU); +// #endif + return ret; + } + + // Q: should this return True for GPU that is attached/assigned to current thread? Currently assuming yes. + HOST DEVICE bool is_local() const { + bool ret = true; +#ifdef __CUDA_ACC__ + ret = (type == GPU); + LOGWARN("Resource::is_local() not fully implemented on GPU devices; returning {}",ret); +#else + if (type == GPU && parent != nullptr) { + ret = parent->is_local(); + } else { + ret = (current_thread_idx() == id); + } +#endif + return ret; + }; + // HOST DEVICE static bool is_local() { // check if thread/gpu idx matches some global idx }; + + static Resource Local() { + LOGWARN("Resource::Local() not properly implemented"); +#ifdef __CUDA_ACC__ + return Resource{ GPU, 0 }; +#else + return Resource{ CPU, 0 }; +#endif + }; + bool operator==(const Resource& other) const { return type == other.type && id == other.id; }; + +}; + diff --git a/src/Types.h b/src/Types.h index 9213ebb14f7534319883ac161e05c2d86e372245..e42a83c9f07be146c8561265744c0c48dd5326e2 100644 --- a/src/Types.h +++ b/src/Types.h @@ -55,3 +55,6 @@ HOST DEVICE inline Vector3_t<size_t> index_to_ijk(size_t idx, const Vector3_t<si return index_to_ijk(idx, n.x, n.y, n.z); } +using idx_t = size_t; /* We will sometimes refer to global + * particle index, which may be too + * large to represent via size_t */