Skip to content

Commit

Permalink
cpu compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
aghaeifar committed Aug 1, 2024
1 parent e5e532b commit d97d18c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "file_utils.h"
#include <boost/log/trivial.hpp>
#include <highfive/highfive.hpp>
#include "simulation_parameters.h"
// #include "simulation_parameters.h"

uint8_t find_max(const std::vector<uint8_t> &data);
//---------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/file_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <map>

struct simulation_parameters;
#include "simulation_parameters.h"


//---------------------------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions src/helper.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@


#include <boost/log/trivial.hpp>
#include "helper_cuda.h"

#ifdef __CUDACC__
#include "helper_cuda.h"
#endif

//---------------------------------------------------------------------------------------------
// check for CUDA and GPU device
//---------------------------------------------------------------------------------------------

uint32_t getDeviceCount()
{
int32_t device_count;
int32_t device_count = 0;
checkCudaErrors(cudaGetDeviceCount(&device_count));
return device_count;
}
Expand Down
5 changes: 3 additions & 2 deletions src/kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <algorithm>
#include "kernels.cuh"
#include "basic_functions.cuh"
#include <execution>

#ifdef __CUDACC__
#include "helper_cuda.h"
Expand All @@ -30,7 +31,7 @@ uint8_t find_max(const std::vector<uint8_t> &data)
thrust::device_vector<uint8_t> thrust_vec(data.begin(), data.end());
uint8_t m = *thrust::max_element(thrust_vec.begin(), thrust_vec.end());
#else
uint8_t m = std::max_element(std::execution::par, data.begin(), data.end());
uint8_t m = *std::max_element(std::execution::par, data.begin(), data.end());
#endif
return m;
}
Expand All @@ -51,14 +52,14 @@ void dephase_relax(float *m0, float *m1, float accumulated_phase, float T1, floa

#ifdef __CUDACC__
__global__
#endif
void cu_sim(const simulation_parameters *param, const float *pFieldMap, const uint8_t *pMask, const float *M0, const float *XYZ0, float *M1, float *XYZ1, uint8_t *T)
{
uint32_t spin_no = blockIdx.x * blockDim.x + threadIdx.x ;
if (spin_no >= param->n_spins)
return;
sim(param, pFieldMap,pMask,M0, XYZ0, M1, XYZ1, T, spin_no);
}
#endif

#ifdef __CUDACC__
__host__ __device__
Expand Down
9 changes: 6 additions & 3 deletions src/spinwalk.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
#include <boost/log/utility/setup/common_attributes.hpp>
#include "indicators.hpp"
#include "version.h"
#include "kernels.cuh"
#include "file_utils.h"
#include "shapes/cylinder.cuh"
#include "shapes/sphere.cuh"
#include "kernels.cuh"

#ifdef __CUDACC__
#include "helper.cuh"
#include <cuda_runtime.h>
#include "helper_cuda.h"
#include "helper.cuh"
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/copy.h>
Expand Down Expand Up @@ -350,7 +350,9 @@ int main(int argc, char * argv[])
if (vm.count("help") || argc == 1 || unreg.size() > 0)
{
std::cout << desc;
#ifdef __CUDACC__
print_device_info();
#endif
return 0;
}

Expand Down Expand Up @@ -394,8 +396,9 @@ int main(int argc, char * argv[])
bStatus &= dump_settings(param, filenames, fov_scale);

// ========== Check GPU memory ==========
#ifdef __CUDACC__
bStatus &= check_memory_size(param.get_required_memory(getDeviceCount()));

#endif
if (bStatus == false)
{
std::cout << ERR_MSG << "Simulation failed. See the log file " << log_filename <<", Aborting...!" << std::endl;
Expand Down

0 comments on commit d97d18c

Please sign in to comment.