1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#pragma once
#include <cstring>
#include <functional>
#include <map>
#include "Evalue.h"
#include "kernel_runtime_context.h"
#include <c10/util/ArrayRef.h>
namespace torch {
namespace executor {
using KernelFunction = std::function<void(KernelRuntimeContext&, EValue**)>;
template<typename T>
using ArrayRef = at::ArrayRef<T>;
#define EXECUTORCH_SCOPE_PROF(x)
struct Kernel {
const char* name_;
KernelFunction kernel_;
Kernel() = default;
/**
* We are doing a copy of the string pointer instead of duplicating the string
* itself, we require the lifetime of the kernel name to be at least as long
* as the kernel registry.
*/
explicit Kernel(const char* name, KernelFunction func)
: name_(name), kernel_(func) {}
};
/**
* See KernelRegistry::hasKernelFn()
*/
bool hasKernelFn(const char* name);
/**
* See KernelRegistry::getKernelFn()
*/
KernelFunction& getKernelFn(const char* name);
[[nodiscard]] bool register_kernels(const ArrayRef<Kernel>&);
struct KernelRegistry {
public:
KernelRegistry() : kernelRegSize_(0) {}
bool register_kernels(const ArrayRef<Kernel>&);
/**
* Checks whether an kernel with a given name is registered
*/
bool hasKernelFn(const char* name);
/**
* Checks whether an kernel with a given name is registered
*/
KernelFunction& getKernelFn(const char* name);
private:
std::map<const char*, KernelFunction> kernels_map_;
uint32_t kernelRegSize_;
};
} // namespace executor
} // namespace torch
|