Commit 210bb7a3 authored by incardon's avatar incardon

Fixing gpu context

parent abf3d2d2
......@@ -704,7 +704,7 @@ template<unsigned int dim, typename T, typename CellS> void Test_cell_gpu(SpaceB
pl_prp.template hostToDevice<0,1,2>();
// create an mgpu context
mgpu::ofp_context_t context(false);
mgpu::ofp_context_t context(mgpu::gpu_context_opt::no_print_props);
cl2.template construct<decltype(pl),decltype(pl_prp)>(pl,pl_out,pl_prp,pl_prp_out,context);
// Check
......@@ -1156,7 +1156,7 @@ template<unsigned int dim, typename T, typename CellS, int impl> void Test_cell_
size_t g_m = pl.size() / 2;
mgpu::ofp_context_t context(false);
mgpu::ofp_context_t context(mgpu::gpu_context_opt::no_print_props);
cl2.template construct<decltype(pl),decltype(pl_prp)>(pl,pl_out,pl_prp,pl_prp_out,context,g_m);
auto & s_t_ns = cl2.getSortToNonSort();
......@@ -1503,7 +1503,7 @@ BOOST_AUTO_TEST_CASE( CellList_swap_test )
size_t g_m = pl.size() / 2;
mgpu::ofp_context_t context(false);
mgpu::ofp_context_t context(mgpu::gpu_context_opt::no_print_props);
cl2.template construct<decltype(pl),decltype(pl_prp)>(pl,pl_out,pl_prp,pl_prp_out,context,g_m);
cl4.template construct<decltype(pl),decltype(pl_prp)>(pl,pl_out,pl_prp,pl_prp_out,context,g_m);
......
......@@ -322,7 +322,7 @@ private:
*/
void initCl(CellListImpl & cli, vector_pos_type & pos, size_t g_m, size_t opt)
{
mgpu::ofp_context_t context(false);
mgpu::ofp_context_t context(mgpu::gpu_context_opt::dummy);
if (opt & VL_SYMMETRIC || opt & VL_CRS_SYMMETRIC)
{populate_cell_list(pos,cli,context,g_m,CL_SYMMETRIC);}
else
......
......@@ -15,6 +15,12 @@
namespace mgpu
{
enum gpu_context_opt
{
no_print_props,//!< no_print_props
print_props, //!< print_props
dummy //!< dummy
};
////////////////////////////////////////////////////////////////////////////////
......@@ -34,7 +40,7 @@ namespace mgpu
// Making this a template argument means we won't generate an instance
// of dummy_k for each translation unit.
template<int dummy_arg = 0>
void init(int dev_num)
void init(int dev_num, gpu_context_opt opt)
{
cudaFuncAttributes attr;
cudaError_t result = cudaFuncGetAttributes(&attr, dummy_k<0>);
......@@ -43,7 +49,10 @@ namespace mgpu
int num_dev;
cudaGetDeviceCount(&num_dev);
cudaSetDevice(dev_num % num_dev);
if (opt != gpu_context_opt::dummy)
{
cudaSetDevice(dev_num % num_dev);
}
int ord;
cudaGetDevice(&ord);
......@@ -56,11 +65,17 @@ namespace mgpu
public:
ofp_context_t(bool print_prop = true, int dev_num = 0, cudaStream_t stream_ = 0)
/*! \brief gpu context constructor
*
* \param opt options for this gpu context
*
*/
ofp_context_t(gpu_context_opt opt = gpu_context_opt::no_print_props , int dev_num = 0, cudaStream_t stream_ = 0)
:context_t(), _stream(stream_)
{
init(dev_num);
if(print_prop)
init(dev_num,opt);
if(opt == gpu_context_opt::print_props)
{
printf("%s\n", device_prop_string(_props).c_str());
}
......@@ -151,6 +166,12 @@ namespace mgpu
namespace mgpu
{
enum gpu_context_opt
{
no_print_props,//!< no_print_props
print_props, //!< print_props
dummy //!< dummy
};
////////////////////////////////////////////////////////////////////////////////
......@@ -161,6 +182,7 @@ namespace mgpu
{
protected:
cudaDeviceProp _props;
int _ptx_version;
cudaStream_t _stream;
cudaEvent_t _timer[2];
......@@ -169,13 +191,18 @@ namespace mgpu
// Making this a template argument means we won't generate an instance
// of dummy_k for each translation unit.
template<int dummy_arg = 0>
void init(int dev_num)
void init(int dev_num, gpu_context_opt opt)
{
cudaFuncAttributes attr;
_ptx_version = 0;
int num_dev;
cudaGetDeviceCount(&num_dev);
cudaSetDevice(dev_num % num_dev);
if (opt != gpu_context_opt::dummy)
{
cudaSetDevice(dev_num % num_dev);
}
int ord;
cudaGetDevice(&ord);
......@@ -188,11 +215,16 @@ namespace mgpu
public:
ofp_context_t(bool print_prop = true, int dev_num = 0, cudaStream_t stream_ = 0)
/*! \brief gpu context constructor
*
* \param opt options for this gpu context
*
*/
ofp_context_t(gpu_context_opt opt = gpu_context_opt::no_print_props , int dev_num = 0, cudaStream_t stream_ = 0)
:context_t(), _stream(stream_)
{
init(dev_num);
if(print_prop)
init(dev_num,opt);
if(opt == gpu_context_opt::print_props)
{
printf("%s\n", device_prop_string(_props).c_str());
}
......
......@@ -20,16 +20,6 @@
#ifndef __NVCC__
// namespace mgpu
// {
// // Stub class for modern gpu
//
// struct ofp_context_t
// {
// ofp_context_t(bool print_prop = true, int dev_num = 0)
// {}
// };
// }
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment