HIP: Heterogenous-computing Interface for Portability
hiprtc.h
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 #pragma once
23 
24 #include <cstddef>
25 #include <string>
26 
27 enum hiprtcResult {
28  HIPRTC_SUCCESS = 0,
29  HIPRTC_ERROR_OUT_OF_MEMORY = 1,
30  HIPRTC_ERROR_PROGRAM_CREATION_FAILURE = 2,
31  HIPRTC_ERROR_INVALID_INPUT = 3,
32  HIPRTC_ERROR_INVALID_PROGRAM = 4,
33  HIPRTC_ERROR_INVALID_OPTION = 5,
34  HIPRTC_ERROR_COMPILATION = 6,
35  HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE = 7,
36  HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION = 8,
37  HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION = 9,
38  HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID = 10,
39  HIPRTC_ERROR_INTERNAL_ERROR = 11
40 };
41 
42 const char* hiprtcGetErrorString(hiprtcResult result);
43 
44 inline
45 hiprtcResult hiprtcVersion(int* major, int* minor) noexcept
46 { // TODO: NVRTC versioning is somewhat unclear.
47  if (!major || !minor) return HIPRTC_ERROR_INVALID_INPUT;
48 
49  // TODO: this should be generic / set by the build infrastructure.
50  *major = 9;
51  *minor = 0;
52 
53  return HIPRTC_SUCCESS;
54 }
55 
56 struct _hiprtcProgram;
58 
59 hiprtcResult hiprtcAddNameExpression(hiprtcProgram prog,
60  const char* name_expression);
61 
62 hiprtcResult hiprtcCompileProgram(hiprtcProgram prog, int numOptions,
63  const char** options);
64 
65 hiprtcResult hiprtcCreateProgram(hiprtcProgram* prog, const char* src,
66  const char* name, int numHeaders,
67  const char** headers,
68  const char** includeNames);
69 
70 hiprtcResult hiprtcDestroyProgram(hiprtcProgram* prog);
71 
72 hiprtcResult hiprtcGetLoweredName(hiprtcProgram prog,
73  const char* name_expression,
74  const char** lowered_name);
75 
76 hiprtcResult hiprtcGetProgramLog(hiprtcProgram prog, char* log);
77 
78 hiprtcResult hiprtcGetProgramLogSize(hiprtcProgram prog,
79  std::size_t* logSizeRet);
80 
81 hiprtcResult hiprtcGetCode(hiprtcProgram prog, char* code);
82 
83 hiprtcResult hiprtcGetCodeSize(hiprtcProgram prog, std::size_t* codeSizeRet);
84 
85 namespace hip_impl
86 {
87  std::string demangle(const char* mangled_expression);
88 }
89 
90 #if defined(HIPRTC_GET_TYPE_NAME)
91  #include <typeinfo>
92 
93  #if defined(_WIN32)
94  #include <dbghelp.h>
95 
96  template<typename>
97  hiprtcResult hiprtcGetTypeName(std::string*) = delete;
98  #else
99  template<typename T>
100  inline
101  hiprtcResult hiprtcGetTypeName(std::string* result)
102  {
103  if (!result) return HIPRTC_ERROR_INVALID_INPUT;
104 
105  *result = hip_impl::demangle(typeid(T).name());
106 
107  return (result->empty()) ? HIPRTC_ERROR_INTERNAL_ERROR :
108  HIPRTC_SUCCESS;
109  }
110  #endif
111 #endif
Definition: hiprtc.cpp:108
Definition: hip_runtime_api.h:82