config.cc 1.07 KB
Newer Older
1
/**
2
 *  Copyright (c) 2019 by Contributors
3
4
 * @file runtime/config.cc
 * @brief DGL runtime config
5
6
7
 */

#include <dgl/runtime/config.h>
8
#include <dgl/runtime/registry.h>
9
#include <libxsmm_cpuid.h>
10
11
12
13
14
15

using namespace dgl::runtime;

namespace dgl {
namespace runtime {

16
17
18
19
20
21
22
23
24
25
Config::Config() {
#if !defined(_WIN32) && defined(USE_LIBXSMM)
  int cpu_id = libxsmm_cpuid_x86();
  // Enable libxsmm on AVX machines by default
  libxsmm_ = LIBXSMM_X86_AVX2 <= cpu_id && cpu_id <= LIBXSMM_X86_ALLFEAT;
#else
  libxsmm_ = false;
#endif
}

26
void Config::EnableLibxsmm(bool b) { libxsmm_ = b; }
27

28
bool Config::IsLibxsmmAvailable() const { return libxsmm_; }
29
30

DGL_REGISTER_GLOBAL("global_config._CAPI_DGLConfigSetLibxsmm")
31
32
33
34
    .set_body([](DGLArgs args, DGLRetValue* rv) {
      bool use_libxsmm = args[0];
      dgl::runtime::Config::Global()->EnableLibxsmm(use_libxsmm);
    });
35
36

DGL_REGISTER_GLOBAL("global_config._CAPI_DGLConfigGetLibxsmm")
37
38
39
    .set_body([](DGLArgs args, DGLRetValue* rv) {
      *rv = dgl::runtime::Config::Global()->IsLibxsmmAvailable();
    });
40
41
42

}  // namespace runtime
}  // namespace dgl