HIP: Heterogenous-computing Interface for Portability
program_state.hpp
1 /*
2 Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 
23 #pragma once
24 
25 #include <hsa/amd_hsa_kernel_code.h>
26 #include <hsa/hsa.h>
27 #include <hsa/hsa_ext_amd.h>
28 #include <hsa/hsa_ven_amd_loader.h>
29 
30 #include <cstddef>
31 #include <cstdint>
32 #include <cstdlib>
33 
34 #include <hip/hip_common.h>
35 
36 struct ihipModuleSymbol_t;
37 using hipFunction_t = ihipModuleSymbol_t*;
38 
39 namespace hip_impl {
40 
41 // This section contains internal APIs that
42 // needs to be exported
43 #ifdef __GNUC__
44 #pragma GCC visibility push (default)
45 #endif
46 
47 struct kernarg_impl;
48 class kernarg {
49 public:
50  kernarg();
51  kernarg(kernarg&&);
52  ~kernarg();
53  std::uint8_t* data();
54  std::size_t size();
55  void reserve(std::size_t);
56  void resize(std::size_t);
57 private:
58  kernarg_impl* impl;
59 };
60 
62 class program_state_impl;
64 public:
65  program_state();
66  ~program_state();
67  program_state(const program_state&) = delete;
68 
69  hipFunction_t kernel_descriptor(std::uintptr_t,
70  hsa_agent_t);
71 
72  kernargs_size_align get_kernargs_size_align(std::uintptr_t);
73  hsa_executable_t load_executable(const char*, const size_t,
74  hsa_executable_t,
75  hsa_agent_t);
76  hsa_executable_t load_executable_no_copy(const char*, const size_t,
77  hsa_executable_t,
78  hsa_agent_t);
79 
80  void* global_addr_by_name(const char* name);
81 
82 private:
83  friend class agent_globals_impl;
84  program_state_impl* impl;
85 };
86 
88 public:
89  std::size_t size(std::size_t n) const;
90  std::size_t alignment(std::size_t n) const;
91  const void* getHandle() const {return handle;};
92 private:
93  const void* handle;
94  friend kernargs_size_align program_state::get_kernargs_size_align(std::uintptr_t);
95 };
96 
97 #ifdef __GNUC__
98 #pragma GCC visibility pop
99 #endif
100 
101 inline
102 __attribute__((visibility("hidden")))
103 program_state& get_program_state() {
104  static program_state ps;
105  return ps;
106 }
107 } // Namespace hip_impl.
hip_impl::kernargs_size_align
Definition: program_state.hpp:87
hip_impl::kernarg
Definition: program_state.hpp:48
hip_impl::program_state
Definition: program_state.hpp:63