Skip to content

Commit

Permalink
[Mode] Mode registration can now be toggled at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
dmed256 committed Sep 9, 2018
1 parent e2ab51f commit 0c975e1
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 19 deletions.
7 changes: 4 additions & 3 deletions include/occa/mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace occa {
public:
modeInfo_v();

virtual void init() = 0;
virtual bool init() = 0;
virtual styling::section& getDescription();
};

Expand All @@ -71,8 +71,9 @@ namespace occa {
public:
mode(std::string modeName_) {
modeName = modeName_;
registerMode(this);
modeInfo_t().init();
if (modeInfo_t().init()) {
registerMode(this);
}
}

styling::section &getDescription() {
Expand Down
2 changes: 1 addition & 1 deletion include/occa/mode/cuda/registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace occa {
public:
modeInfo();

void init();
bool init();
styling::section& getDescription();
};

Expand Down
2 changes: 1 addition & 1 deletion include/occa/mode/hip/registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace occa {
public:
modeInfo();

void init();
bool init();
styling::section& getDescription();
};

Expand Down
2 changes: 1 addition & 1 deletion include/occa/mode/opencl/registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace occa {
public:
modeInfo();

void init();
bool init();
styling::section& getDescription();
};

Expand Down
2 changes: 2 additions & 0 deletions include/occa/mode/opencl/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ namespace occa {
std::string vendor(int type);
}

bool isEnabled();

cl_device_type deviceType(int type);

int getPlatformCount();
Expand Down
2 changes: 1 addition & 1 deletion include/occa/mode/openmp/registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace occa {
public:
modeInfo();

void init();
bool init();
void setupProperties();
};

Expand Down
2 changes: 1 addition & 1 deletion include/occa/mode/serial/registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace occa {
public:
modeInfo();

void init();
bool init();
styling::section& getDescription();
};

Expand Down
3 changes: 2 additions & 1 deletion src/mode/cuda/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ namespace occa {
namespace cuda {
modeInfo::modeInfo() {}

void modeInfo::init() {
bool modeInfo::init() {
cuda::init();
return true;
}

styling::section& modeInfo::getDescription() {
Expand Down
3 changes: 2 additions & 1 deletion src/mode/hip/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ namespace occa {
namespace hip {
modeInfo::modeInfo() {}

void modeInfo::init() {
bool modeInfo::init() {
hip::init();
return true;
}

styling::section& modeInfo::getDescription() {
Expand Down
5 changes: 4 additions & 1 deletion src/mode/opencl/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@

#if OCCA_OPENCL_ENABLED

#include <occa/mode/opencl/utils.hpp>
#include <occa/mode/opencl/registration.hpp>

namespace occa {
namespace opencl {
modeInfo::modeInfo() {}

void modeInfo::init() {}
bool modeInfo::init() {
return occa::opencl::isEnabled();
}

styling::section& modeInfo::getDescription() {
static styling::section section("OpenCL");
Expand Down
6 changes: 6 additions & 0 deletions src/mode/opencl/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ namespace occa {
}
}

bool isEnabled() {
cl_uint platformCount;
cl_int error = clGetPlatformIDs(0, NULL, &platformCount);
return !error;
}

cl_device_type deviceType(int type) {
cl_device_type ret = 0;

Expand Down
7 changes: 1 addition & 6 deletions src/mode/openmp/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#if OCCA_OPENMP_ENABLED

#include <omp.h>

#include <occa/mode/serial/device.hpp>
#include <occa/mode/openmp/device.hpp>
#include <occa/mode/openmp/utils.hpp>
Expand All @@ -34,10 +32,7 @@
namespace occa {
namespace openmp {
device::device(const occa::properties &properties_) :
serial::device(properties_) {
// Generate an OpenMP library dependency (so it doesn't crash when dlclose())
omp_get_num_threads();
}
serial::device(properties_) {}

hash_t device::kernelHash(const occa::properties &props) const {
return (
Expand Down
8 changes: 7 additions & 1 deletion src/mode/openmp/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@

#if OCCA_OPENMP_ENABLED

#include <omp.h>

#include <occa/mode/openmp/registration.hpp>

namespace occa {
namespace openmp {
modeInfo::modeInfo() {}

void modeInfo::init() {}
bool modeInfo::init() {
// Generate an OpenMP library dependency (so it doesn't crash when dlclose())
omp_get_num_threads();
return true;
}

occa::mode<openmp::modeInfo,
openmp::device> mode("OpenMP");
Expand Down
4 changes: 3 additions & 1 deletion src/mode/serial/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ namespace occa {
namespace serial {
modeInfo::modeInfo() {}

void modeInfo::init() {}
bool modeInfo::init() {
return true;
}

styling::section& modeInfo::getDescription() {
static styling::section section("CPU(s)");
Expand Down

0 comments on commit 0c975e1

Please sign in to comment.