-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added wrapper functions for GPU acceleration
- Loading branch information
1 parent
3055c26
commit 0bb525a
Showing
12 changed files
with
264 additions
and
42 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef GPU_H_ | ||
#define GPU_H_ | ||
//----------------------------------------------------------------------------- | ||
// | ||
// This header file is part of the VAMPIRE open source package under the | ||
// GNU GPL (version 2) licence (see licence file for details). | ||
// | ||
// (c) R F L Evans 2015. All rights reserved. | ||
// | ||
//----------------------------------------------------------------------------- | ||
|
||
namespace gpu{ | ||
|
||
//----------------------------------------------------------------------------- | ||
// Variables used for GPU acceleration | ||
//----------------------------------------------------------------------------- | ||
extern bool acceleration; // flag to enable gpu_acceleration | ||
|
||
//----------------------------------------------------------------------------- | ||
// Functions for GPU acceleration | ||
//----------------------------------------------------------------------------- | ||
extern void initialize(); | ||
extern void llg_heun(); | ||
extern void stats_update(); | ||
extern void finalize(); | ||
|
||
} // end of gpu namespace | ||
|
||
#endif //GPU_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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//----------------------------------------------------------------------------- | ||
// | ||
// This source file is part of the VAMPIRE open source package under the | ||
// GNU GPL (version 2) licence (see licence file for details). | ||
// | ||
// (c) R F L Evans 2014. All rights reserved. | ||
// | ||
//----------------------------------------------------------------------------- | ||
|
||
// C++ standard library headers | ||
|
||
// Vampire headers | ||
#include "gpu.hpp" | ||
|
||
namespace gpu{ | ||
|
||
//----------------------------------------------------------------------------- | ||
// Shared variables used for GPU acceleration | ||
//----------------------------------------------------------------------------- | ||
bool acceleration = false; // flag to enable gpu_acceleration | ||
|
||
namespace internal{ | ||
|
||
} // end of internal namespace | ||
|
||
} // end of gpu namespace |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//----------------------------------------------------------------------------- | ||
// | ||
// This source file is part of the VAMPIRE open source package under the | ||
// GNU GPL (version 2) licence (see licence file for details). | ||
// | ||
// (c) R F L Evans 2014. All rights reserved. | ||
// | ||
//----------------------------------------------------------------------------- | ||
|
||
// C++ standard library headers | ||
|
||
// Vampire headers | ||
#include "gpu.hpp" | ||
#include "cuda.hpp" | ||
#include "errors.hpp" | ||
//#include "opencl.hpp" | ||
|
||
namespace gpu{ | ||
|
||
//---------------------------------------------------------------------------------- | ||
// Function to call correct de-initialization function depending on cuda,opencl etc | ||
//---------------------------------------------------------------------------------- | ||
void finalize(){ | ||
|
||
#ifdef CUDA | ||
cuda::finalize(); | ||
#elseif OPENCL | ||
opencl::finalize(); | ||
#endif | ||
|
||
return; | ||
} | ||
|
||
} // end of namespace gpu |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//----------------------------------------------------------------------------- | ||
// | ||
// This source file is part of the VAMPIRE open source package under the | ||
// GNU GPL (version 2) licence (see licence file for details). | ||
// | ||
// (c) R F L Evans 2014. All rights reserved. | ||
// | ||
//----------------------------------------------------------------------------- | ||
|
||
// C++ standard library headers | ||
#include <iostream> | ||
|
||
// Vampire headers | ||
#include "gpu.hpp" | ||
#include "cuda.hpp" | ||
#include "errors.hpp" | ||
#include "vio.hpp" | ||
//#include "opencl.hpp" | ||
|
||
namespace gpu{ | ||
|
||
//------------------------------------------------------------------------------- | ||
// Function to call correct initialization function depending on cuda,opencl etc | ||
//------------------------------------------------------------------------------- | ||
void initialize(){ | ||
|
||
// flag to check for successful initialization | ||
bool initialized=false; | ||
|
||
#ifdef CUDA | ||
initialized = cuda::initialize(); | ||
#elseif OPENCL | ||
initialized = opencl::initialize(); | ||
#endif | ||
|
||
// Check for no initialization | ||
if(initialized == false){ | ||
std::cerr << "Error: no support for GPU acceleration, please recompile using -D CUDA compile" << std::endl; | ||
std::cerr << "time flag with cuda development libraries v6.0 or greater." << std::endl; | ||
std::cerr << "Aborting program." << std::endl; | ||
zlog << zTs() << "Error: no support for GPU acceleration, please recompile using -D CUDA compile time flag with cuda development libraries v6.0 or greater." << std::endl; | ||
err::vexit(); | ||
} | ||
|
||
return; | ||
} | ||
|
||
} // end of namespace gpu |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//----------------------------------------------------------------------------- | ||
// | ||
// This source file is part of the VAMPIRE open source package under the | ||
// GNU GPL (version 2) licence (see licence file for details). | ||
// | ||
// (c) R F L Evans 2014. All rights reserved. | ||
// | ||
//----------------------------------------------------------------------------- | ||
|
||
// C++ standard library headers | ||
|
||
// Vampire headers | ||
#include "gpu.hpp" | ||
#include "cuda.hpp" | ||
#include "errors.hpp" | ||
//#include "opencl.hpp" | ||
|
||
namespace gpu{ | ||
|
||
//-------------------------------------------------------------------------- | ||
// Function to call correct llg_heun function depending on cuda,opencl etc | ||
//-------------------------------------------------------------------------- | ||
void llg_heun(){ | ||
|
||
#ifdef CUDA | ||
cuda::llg_heun(); | ||
#elseif OPENCL | ||
opencl::llg_heun(); | ||
#endif | ||
|
||
return; | ||
} | ||
|
||
} // end of namespace gpu |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#-------------------------------------------------------------- | ||
# Makefile for gpu module | ||
#-------------------------------------------------------------- | ||
|
||
# List module object filenames | ||
gpu_objects=\ | ||
data.o \ | ||
finalize.o \ | ||
initialize.o \ | ||
llg_heun.o \ | ||
statistics.o | ||
|
||
# Append module objects to global tree | ||
OBJECTS+=$(addprefix obj/gpu/,$(gpu_objects)) |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//----------------------------------------------------------------------------- | ||
// | ||
// This source file is part of the VAMPIRE open source package under the | ||
// GNU GPL (version 2) licence (see licence file for details). | ||
// | ||
// (c) R F L Evans 2014. All rights reserved. | ||
// | ||
//----------------------------------------------------------------------------- | ||
|
||
// C++ standard library headers | ||
|
||
// Vampire headers | ||
#include "gpu.hpp" | ||
#include "cuda.hpp" | ||
#include "errors.hpp" | ||
//#include "opencl.hpp" | ||
|
||
namespace gpu{ | ||
|
||
//------------------------------------------------------------------------------- | ||
// Function to call correct statistics update function | ||
//------------------------------------------------------------------------------- | ||
void stats_update(){ | ||
|
||
#ifdef CUDA | ||
cuda::stats_update(); | ||
#elseif OPENCL | ||
opencl::stats_update(); | ||
#endif | ||
|
||
return; | ||
} | ||
|
||
} // end of namespace gpu |
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 |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
#include "program.hpp" | ||
#include "demag.hpp" | ||
#include "errors.hpp" | ||
#include "gpu.hpp" | ||
#include "material.hpp" | ||
#include "random.hpp" | ||
#include "sim.hpp" | ||
|
@@ -158,7 +159,7 @@ namespace sim{ | |
int save_checkpoint_rate=1; // Default increment between checkpoints | ||
|
||
// Local function declarations | ||
int integrate_serial(int); | ||
void integrate_serial(int); | ||
int integrate_mpi(int); | ||
|
||
// Monte Carlo statistics counters | ||
|
@@ -252,6 +253,9 @@ int run(){ | |
// Check for load spin configurations from checkpoint | ||
if(sim::load_checkpoint_flag) load_checkpoint(); | ||
|
||
// Initialize GPU acceleration if enabled | ||
if(gpu::acceleration) gpu::initialize(); | ||
|
||
// Select program to run | ||
switch(sim::program){ | ||
case 0: | ||
|
@@ -417,6 +421,9 @@ int run(){ | |
|
||
//program::LLB_Boltzmann(); | ||
|
||
// De-initialize GPU | ||
gpu::finalize(); | ||
|
||
// optionally save checkpoint file | ||
if(sim::save_checkpoint_flag && !sim::save_checkpoint_continuous_flag) save_checkpoint(); | ||
|
||
|
@@ -475,35 +482,32 @@ int integrate(int n_steps){ | |
/// | ||
/// @section Information | ||
/// @author Richard Evans, [email protected] | ||
/// @version 1.0 | ||
/// @date 05/02/2011 | ||
/// @version 1.1 | ||
/// @date 10/06/2015 | ||
/// | ||
/// @return EXIT_SUCCESS | ||
/// | ||
/// @internal | ||
/// Created: 05/02/2011 | ||
/// Revision: --- | ||
///===================================================================================== | ||
/// | ||
int integrate_serial(int n_steps){ | ||
|
||
// Check for calling of function | ||
if(err::check==true) std::cout << "sim::integrate_serial has been called" << std::endl; | ||
|
||
// Case statement to call integrator | ||
switch(sim::integrator){ | ||
case 0: // LLG Heun | ||
for(int ti=0;ti<n_steps;ti++){ | ||
// Select CUDA version if supported | ||
#ifdef CUDA | ||
sim::LLG_Heun_cuda(); | ||
#else | ||
sim::LLG_Heun(); | ||
#endif | ||
// increment time | ||
increment_time(); | ||
} | ||
break; | ||
void integrate_serial(int n_steps){ | ||
|
||
// Check for calling of function | ||
if(err::check==true) std::cout << "sim::integrate_serial has been called" << std::endl; | ||
|
||
// Case statement to call integrator | ||
switch(sim::integrator){ | ||
|
||
case 0: // LLG Heun | ||
for(int ti=0;ti<n_steps;ti++){ | ||
// Optionally select GPU accelerated version | ||
if(gpu::acceleration) gpu::llg_heun(); | ||
// Otherwise use CPU version | ||
else sim::LLG_Heun(); | ||
// Increment time | ||
increment_time(); | ||
} | ||
break; | ||
|
||
case 1: // Montecarlo | ||
for(int ti=0;ti<n_steps;ti++){ | ||
|
@@ -512,20 +516,15 @@ int integrate_serial(int n_steps){ | |
increment_time(); | ||
} | ||
break; | ||
|
||
case 2: // LLG Midpoint | ||
for(int ti=0;ti<n_steps;ti++){ | ||
// Select CUDA version if supported | ||
#ifdef CUDA | ||
sim::LLG_Midpoint_cuda(); | ||
#else | ||
sim::LLG_Midpoint(); | ||
#endif | ||
// increment time | ||
increment_time(); | ||
} | ||
break; | ||
|
||
|
||
case 2: // LLG Midpoint | ||
for(int ti=0;ti<n_steps;ti++){ | ||
sim::LLG_Midpoint(); | ||
// increment time | ||
increment_time(); | ||
} | ||
break; | ||
|
||
case 3: // Constrained Monte Carlo | ||
for(int ti=0;ti<n_steps;ti++){ | ||
sim::ConstrainedMonteCarlo(); | ||
|
@@ -544,11 +543,11 @@ int integrate_serial(int n_steps){ | |
|
||
default:{ | ||
std::cerr << "Unknown integrator type "<< sim::integrator << " requested, exiting" << std::endl; | ||
exit (EXIT_FAILURE); | ||
} | ||
err::vexit(); | ||
} | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
return; | ||
} | ||
|
||
/// @brief Wrapper function to call MPI parallel integrators | ||
|
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