-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
playing with cmake, added McMaster server instructions to readme
- Loading branch information
1 parent
96e661a
commit 86b6562
Showing
7 changed files
with
59 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,8 +61,7 @@ downloaded marshalgen from another source, you need to fix this) | |
2. `mkdir /path/to/GEANT4-GPU/geant4.10.01.p02-build /path/to/GEANT4-GPU/ | ||
geant4.10.01.p02-install`<br> | ||
3. `cd /path/to/GEANT4-GPU/geant4.10.01.p02-build`<br> | ||
4. `cmake -DGEANT4_INSTALL_DATA=ON -DCMAKE_INSTALL_PREFIX=/path/to/GEANT4-GPU/ | ||
geant4.10.01.p02-install /path/to/GEANT4-GPU/geant4.10.01.p02`<br> | ||
4. `cmake -DGEANT4_INSTALL_DATA=ON -DCMAKE_INSTALL_PREFIX=/path/to/GEANT4-GPU/geant4.10.01.p02-install /path/to/GEANT4-GPU/geant4.10.01.p02`<br> | ||
5. `make -jN` where `N` is the number of processors on your computer<br> | ||
6. `make install` | ||
|
||
|
@@ -79,6 +78,17 @@ geant4.10.01.p02-install /path/to/GEANT4-GPU/geant4.10.01.p02`<br> | |
8. Open `/path/to/GEANT4-GPU/Build/addFilesG4STORK` and modify the top few | ||
variables with the correct paths for your install. | ||
|
||
**Installing Geant4 on McMaster's Server (no root privileges)**<br> | ||
1. SSH into one of McMaster's servers (i.e. `ssh [email protected]`), account is on a shared drive across all department servers so once you install once you can access it from any one. | ||
2. Set up your .gitconfig file and clone the repo in your home folder (path is `/u50/yourMacId/`) | ||
3. You'll need to install expat and cmake, to do this download the latest versions of both onto your regular desktop. | ||
4. Copy both tarred files to McMaster's server via SSH: `scp cmake-3.4.0.tar [email protected]:/u50/yourMacId/` and `scp expat-2.0.1.tar [email protected]:/u50/yourMacId/` | ||
5. Return to your SSH terminal and untar both files (this may take a while): `tar -xvf cmake-3.4.0.tar; tar -xvf expat-2.0.1.tar` | ||
6. Build and install cmake: `cd cmake-3.4.0;./bootstrap;make;make install` | ||
7. Build and install expat: `mkdir bin;cd expat-2.0.1;./configure --prefix=/u50/yourMacId/bin;make;make install` | ||
8. Add cmake's bin folder to your path. Open `/u50/yourMacId/.bash_profile` and add the following line right before `export PATH`: `PATH=$PATH:$HOME/cmake-3.4.0/bin` | ||
9. Follow the instructions above to "Install GEANT-4" (starting from 2) | ||
|
||
**Setting Environment Variables**<br> | ||
It is recommended to add a line to your bash_profile that loads the Geant4 | ||
environment variables, like so: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 10 additions & 7 deletions
17
geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/cuda/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
cmake_minimum_required (VERSION 2.8) | ||
find_package (CUDA REQUIRED) | ||
|
||
include_directories(/usr/local/cuda/include) | ||
option (GEANT4_ENABLE_CUDA "Use CUDA to run simulations in parallel on the GPU" ON) | ||
#add_subdirectory(Hadr04) | ||
|
||
if (GEANT4_ENABLE_CUDA) | ||
find_package (CUDA REQUIRED) | ||
|
||
cuda_add_library (CUDA_G4NeutronHPVector SHARED CUDA_G4NeutronHPVector.h CUDA_G4NeutronHPVector.cu) | ||
include_directories(/usr/local/cuda/include) | ||
cuda_add_library (CUDA_G4NeutronHPVector SHARED CUDA_G4NeutronHPVector.h CUDA_G4NeutronHPVector.cu) | ||
|
||
LIST(APPEND CUDA_NVCC_FLAGS --compiler-options -fno-strict-aliasing -lineinfo -use_fast_math -Xptxas -dlcm=cg) | ||
LIST(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_30,code=sm_30) | ||
|
||
#target_link_libraries(Geant4 CUDA_G4NeutronHPVector /usr/local/cuda/lib/libcudart_static.a) | ||
LIST(APPEND CUDA_NVCC_FLAGS --compiler-options -fno-strict-aliasing -lineinfo -use_fast_math -Xptxas -dlcm=cg) | ||
LIST(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_30,code=sm_30) | ||
endif() |
51 changes: 21 additions & 30 deletions
51
geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/cuda/CUDA_G4NeutronHPVector.cu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,32 @@ | ||
#include <cuda_runtime.h> | ||
#include <cuda.h> | ||
#include <stdio.h> | ||
#include "CUDA_G4NeutronHPVector.h" | ||
|
||
// Kernel that executes on the CUDA device | ||
// CUDA kernel | ||
__global__ | ||
void square_array(float *a, int N) | ||
void sumArrays(int* arr1, int* arr2, int* res, int n) | ||
{ | ||
int idx = blockIdx.x * blockDim.x + threadIdx.x; | ||
if (idx<N) | ||
a[idx] = a[idx] * a[idx]; | ||
int tid = blockIdx.x; | ||
if (tid < n) | ||
res[tid] = arr1[tid] + arr2[tid]; | ||
} | ||
|
||
float squareArray(int N) { | ||
float *a_h, *a_d; // Pointer to host & device arrays | ||
size_t size = N * sizeof(float); | ||
|
||
a_h = (float *)malloc(size); // Allocate array on host | ||
cudaMalloc((void **) &a_d, size); // Allocate array on device | ||
|
||
// Initialize host array and copy it to CUDA device | ||
for (int i=0; i<N; i++) { | ||
a_h[i] = (float)i; | ||
} | ||
cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice); | ||
|
||
// Do calculation on device: | ||
int block_size = 4; | ||
int n_blocks = N/block_size + (N%block_size == 0 ? 0:1); | ||
|
||
square_array <<< n_blocks, block_size >>> (a_d, N); | ||
|
||
// Retrieve result from device and store it in host array | ||
cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost); | ||
void CUDA_sumArrays(int* arr1, int* arr2, int* res, int n) { | ||
int *gpu_arr1, *gpu_arr2, *gpu_res; | ||
|
||
// Cleanup | ||
free(a_h); | ||
cudaFree(a_d); | ||
cudaMalloc((void**)&gpu_arr1, n*sizeof(int)); | ||
cudaMalloc((void**)&gpu_arr2, n*sizeof(int)); | ||
cudaMalloc((void**)&gpu_res, n*sizeof(int)); | ||
|
||
cudaMemcpy(gpu_arr1, arr1, n*sizeof(int), cudaMemcpyHostToDevice); | ||
cudaMemcpy(gpu_arr2, arr2, n*sizeof(int), cudaMemcpyHostToDevice); | ||
|
||
return a_h[N-1]; | ||
sumArrays<<<n,1>>>(gpu_arr1, gpu_arr2, gpu_res, n); | ||
|
||
cudaMemcpy(res, gpu_res, n*sizeof(int), cudaMemcpyDeviceToHost); | ||
|
||
cudaFree(gpu_arr1); | ||
cudaFree(gpu_arr2); | ||
cudaFree(gpu_res); | ||
} |
2 changes: 1 addition & 1 deletion
2
geant4.10.00.p02/source/processes/hadronic/models/neutron_hp/cuda/CUDA_G4NeutronHPVector.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
float squareArray(int N); | ||
void CUDA_sumArrays(int* arr1, int* arr2, int* res, int n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters