Skip to content

Commit

Permalink
memset cuda to gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
brucefan1983 committed Oct 23, 2024
1 parent 707dd3b commit 3d3736a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/force/neighbor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ void find_cell_list(
cell_count_sum.resize(N_cells);
}

CHECK(cudaMemset(cell_count.data(), 0, sizeof(int) * N_cells));
CHECK(cudaMemset(cell_count_sum.data(), 0, sizeof(int) * N_cells));
CHECK(cudaMemset(cell_contents.data(), 0, sizeof(int) * N));
CHECK(gpuMemset(cell_count.data(), 0, sizeof(int) * N_cells));
CHECK(gpuMemset(cell_count_sum.data(), 0, sizeof(int) * N_cells));
CHECK(gpuMemset(cell_contents.data(), 0, sizeof(int) * N));

find_cell_counts<<<grid_size, block_size>>>(
box, N, cell_count.data(), x, y, z, num_bins[0], num_bins[1], num_bins[2], rc_inv);
Expand All @@ -194,7 +194,7 @@ void find_cell_list(
thrust::exclusive_scan(
thrust::device, cell_count.data(), cell_count.data() + N_cells, cell_count_sum.data());

CHECK(cudaMemset(cell_count.data(), 0, sizeof(int) * N_cells));
CHECK(gpuMemset(cell_count.data(), 0, sizeof(int) * N_cells));

find_cell_contents<<<grid_size, block_size>>>(
box,
Expand Down
2 changes: 1 addition & 1 deletion src/main_gpumd/run.cu
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void calculate_time_step(
}
const int N = velocity_per_atom.size() / 3;
double* gpu_v2_max;
CHECK(cudaGetSymbolAddress((void**)&gpu_v2_max, device_v2_max));
CHECK(gpuGetSymbolAddress((void**)&gpu_v2_max, device_v2_max));
gpu_find_largest_v2<<<1, 1024>>>(
N,
(N - 1) / 1024 + 1,
Expand Down
6 changes: 3 additions & 3 deletions src/mc/mc_ensemble_canonical.cu
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void MC_Ensemble_Canonical::compute(
type_j = atom.cpu_type[j];
}

CHECK(cudaMemset(NN_ij.data(), 0, sizeof(int)));
CHECK(gpuMemset(NN_ij.data(), 0, sizeof(int)));
get_neighbors_of_i_and_j<<<(atom.number_of_atoms - 1) / 64 + 1, 64>>>(
atom.number_of_atoms,
box,
Expand Down Expand Up @@ -280,8 +280,8 @@ void MC_Ensemble_Canonical::compute(
local_type_after.data());
CUDA_CHECK_KERNEL

CHECK(cudaMemset(NN_radial.data(), 0, sizeof(int) * NN_radial.size()));
CHECK(cudaMemset(NN_angular.data(), 0, sizeof(int) * NN_angular.size()));
CHECK(gpuMemset(NN_radial.data(), 0, sizeof(int) * NN_radial.size()));
CHECK(gpuMemset(NN_angular.data(), 0, sizeof(int) * NN_angular.size()));
create_inputs_for_energy_calculator<<<(atom.number_of_atoms - 1) / 64 + 1, 64>>>(
atom.number_of_atoms,
NN_ij_cpu,
Expand Down
6 changes: 3 additions & 3 deletions src/mc/mc_ensemble_sgc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void MC_Ensemble_SGC::compute(
type_j = types[index_new_species];
}

CHECK(cudaMemset(NN_ij.data(), 0, sizeof(int)));
CHECK(gpuMemset(NN_ij.data(), 0, sizeof(int)));
get_neighbors_of_i<<<(atom.number_of_atoms - 1) / 64 + 1, 64>>>(
atom.number_of_atoms,
box,
Expand Down Expand Up @@ -388,8 +388,8 @@ void MC_Ensemble_SGC::compute(
local_type_after.data());
CUDA_CHECK_KERNEL

CHECK(cudaMemset(NN_radial.data(), 0, sizeof(int) * NN_radial.size()));
CHECK(cudaMemset(NN_angular.data(), 0, sizeof(int) * NN_angular.size()));
CHECK(gpuMemset(NN_radial.data(), 0, sizeof(int) * NN_radial.size()));
CHECK(gpuMemset(NN_angular.data(), 0, sizeof(int) * NN_angular.size()));
create_inputs_for_energy_calculator<<<(atom.number_of_atoms - 1) / 64 + 1, 64>>>(
atom.number_of_atoms,
NN_ij_cpu,
Expand Down
12 changes: 10 additions & 2 deletions src/utilities/gpu_macro.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@

#include "hip/hip_runtime.h"

// memory manipulation
#define gpuMalloc hipMalloc
#define gpuMallocManaged hipMallocManaged
#define gpuFree hipFree

#define gpuMemcpy hipMemcpy
#define gpuMemcpyFromSymbol hipMemcpyFromSymbol
#define gpuMemcpyToSymbol hipMemcpyToSymbol
#define gpuGetSymbolAddress hipGetSymbolAddress
#define gpuMemcpyHostToDevice hipMemcpyHostToDevice
#define gpuMemcpyDeviceToHost hipMemcpyDeviceToHost
#define gpuMemcpyHostToHost hipMemcpyHostToHost
#define gpuMemcpyDeviceToDevice hipMemcpyDeviceToDevice
#define gpuMemset hipMemset

// error handling
#define gpuError_t hipError_t
#define gpuSuccess hipSuccess
#define gpuGetErrorString hipGetErrorString
#define gpuGetLastError hipGetLastError

// device manipulation
#define gpuSetDevice hipSetDevice
#define gpuGetDeviceCount hipGetDeviceCount
#define gpuDeviceProp hipDeviceProp
Expand All @@ -46,23 +50,27 @@

#else // CUDA for Nvidia card

// memory manipulation
#define gpuMalloc cudaMalloc
#define gpuMallocManaged cudaMallocManaged
#define gpuFree cudaFree

#define gpuMemcpy cudaMemcpy
#define gpuMemcpyFromSymbol cudaMemcpyFromSymbol
#define gpuMemcpyToSymbol cudaMemcpyToSymbol
#define gpuGetSymbolAddress cudaGetSymbolAddress
#define gpuMemcpyHostToDevice cudaMemcpyHostToDevice
#define gpuMemcpyDeviceToHost cudaMemcpyDeviceToHost
#define gpuMemcpyHostToHost cudaMemcpyHostToHost
#define gpuMemcpyDeviceToDevice cudaMemcpyDeviceToDevice
#define gpuMemset cudaMemset

// error handling
#define gpuError_t cudaError_t
#define gpuSuccess cudaSuccess
#define gpuGetErrorString cudaGetErrorString
#define gpuGetLastError cudaGetLastError

// device manipulation
#define gpuSetDevice cudaSetDevice
#define gpuGetDeviceCount cudaGetDeviceCount
#define gpuDeviceProp cudaDeviceProp
Expand Down

0 comments on commit 3d3736a

Please sign in to comment.