1 //===--- amdgpu/impl/rt.h ----------------------------------------- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef SRC_RUNTIME_INCLUDE_RT_H_
9 #define SRC_RUNTIME_INCLUDE_RT_H_
10 
11 #include "atmi_runtime.h"
12 #include "hsa_api.h"
13 #include <string>
14 
15 namespace core {
16 
17 #define DEFAULT_MAX_QUEUE_SIZE 4096
18 #define DEFAULT_DEBUG_MODE 0
19 class Environment {
20 public:
21   Environment()
22       : max_queue_size_(DEFAULT_MAX_QUEUE_SIZE),
23         debug_mode_(DEFAULT_DEBUG_MODE) {
24     GetEnvAll();
25   }
26 
27   void GetEnvAll();
28 
29   int getMaxQueueSize() const { return max_queue_size_; }
30   int getDebugMode() const { return debug_mode_; }
31 
32 private:
33   std::string GetEnv(const char *name) {
34     char *env = getenv(name);
35     std::string ret;
36     if (env) {
37       ret = env;
38     }
39     return ret;
40   }
41 
42   int max_queue_size_;
43   int debug_mode_;
44 };
45 
46 class Runtime final {
47 public:
48   static Runtime &getInstance() {
49     static Runtime instance;
50     return instance;
51   }
52 
53   // modules
54   static hsa_status_t RegisterModuleFromMemory(
55       void *, size_t, hsa_agent_t agent,
56       hsa_status_t (*on_deserialized_data)(void *data, size_t size,
57                                            void *cb_state),
58       void *cb_state, std::vector<hsa_executable_t> &HSAExecutables);
59 
60   // data
61   static hsa_status_t Memcpy(hsa_signal_t, void *, const void *, size_t);
62   static hsa_status_t Memfree(void *);
63   static hsa_status_t HostMalloc(void **ptr, size_t size,
64                                  hsa_amd_memory_pool_t MemoryPool);
65 
66   int getMaxQueueSize() const { return env_.getMaxQueueSize(); }
67   int getDebugMode() const { return env_.getDebugMode(); }
68 
69 protected:
70   Runtime() = default;
71   ~Runtime() = default;
72   Runtime(const Runtime &) = delete;
73   Runtime &operator=(const Runtime &) = delete;
74 
75 protected:
76   // variable to track environment variables
77   Environment env_;
78 };
79 
80 } // namespace core
81 
82 #endif // SRC_RUNTIME_INCLUDE_RT_H_
83