mirror of
https://github.com/sgjzfzzf/triton-tvm-ffi.git
synced 2026-07-01 08:51:56 +08:00
fix bugs on illegal memory access on Release
Signed-off-by: Jinjie Liu <jjliu@baai.ac.cn>
This commit is contained in:
+26
-6
@@ -4,6 +4,7 @@
|
||||
#include <cstdint>
|
||||
#include <tvm/ffi/object.h>
|
||||
#include <tvm/ffi/string.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace triton_tvm_ffi {
|
||||
|
||||
@@ -23,14 +24,14 @@ namespace triton_tvm_ffi {
|
||||
V(FP16, "fp16", double) \
|
||||
V(BF16, "bf16", double) \
|
||||
V(FP32, "f32", double) \
|
||||
V(FP64, "fp64", double)
|
||||
V(FP64, "fp64", double) \
|
||||
V(PTR, "*?", void *) \
|
||||
V(CONSTEXPR, "constexpr", void)
|
||||
|
||||
enum class Type : int64_t {
|
||||
#define DEFINE_ENUM(type, str, ctype) type,
|
||||
TYPE_TABLE(DEFINE_ENUM)
|
||||
#undef DEFINE_ENUM
|
||||
PTR,
|
||||
CONSTEXPR,
|
||||
};
|
||||
|
||||
const char *TypeToString(Type type);
|
||||
@@ -41,11 +42,30 @@ template <Type T> struct type_to_ctype;
|
||||
template <> struct type_to_ctype<Type::type> { using t = ctype; };
|
||||
TYPE_TABLE(DEFINE_TYPE_TO_CTYPE)
|
||||
#undef DEFINE_TYPE_TO_CTYPE
|
||||
template <> struct type_to_ctype<Type::PTR> { using t = void *; };
|
||||
// TODO: check whether CUtensorMap* is correct
|
||||
template <> struct type_to_ctype<Type::CONSTEXPR> { using t = void; };
|
||||
template <Type T> using type_to_ctype_t = typename type_to_ctype<T>::t;
|
||||
|
||||
template <typename T, typename = void> struct type_size {
|
||||
static constexpr size_t value = 0;
|
||||
};
|
||||
template <typename T>
|
||||
struct type_size<T, std::enable_if_t<!std::is_void_v<decltype(sizeof(T))>>> {
|
||||
static constexpr size_t value = sizeof(T);
|
||||
};
|
||||
template <typename T> constexpr size_t type_size_v = type_size<T>::value;
|
||||
|
||||
template <size_t... Ns> struct max;
|
||||
template <size_t... Ns> constexpr size_t max_v = max<Ns...>::value;
|
||||
template <size_t N> struct max<N> { static constexpr size_t value = N; };
|
||||
template <size_t N, size_t... Ns> struct max<N, Ns...> {
|
||||
static constexpr size_t value = N > max_v<Ns...> ? N : max_v<Ns...>;
|
||||
};
|
||||
|
||||
static constexpr size_t kMaxOpaqueSize = max_v<
|
||||
#define DEFINE_TYPE_SIZE(type, str, ctype) type_size_v<ctype>,
|
||||
TYPE_TABLE(DEFINE_TYPE_SIZE)
|
||||
#undef DEFINE_TYPE_SIZE
|
||||
0>;
|
||||
|
||||
// --------------- Implementations --------------- //
|
||||
|
||||
} // namespace triton_tvm_ffi
|
||||
|
||||
Reference in New Issue
Block a user