config.cc 1.12 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
#if !defined(_WIN32) && defined(USE_LIBXSMM)
10
#include <libxsmm_source.h>
11
#endif
12
13
14
15
16
17

using namespace dgl::runtime;

namespace dgl {
namespace runtime {

18
19
20
21
22
23
24
25
26
27
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
}

28
void Config::EnableLibxsmm(bool b) { libxsmm_ = b; }
29

30
bool Config::IsLibxsmmAvailable() const { return libxsmm_; }
31
32

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

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

}  // namespace runtime
}  // namespace dgl