mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
This reverts commit 515c19a3856e953c0fe23a0ed4fa844f8eea34d8. Reverted https://github.com/pytorch/pytorch/pull/154165 on behalf of https://github.com/seemethere due to This is failing when attempting to test against executorch main internally, author has acknowledged that this should be reverted ([comment](https://github.com/pytorch/pytorch/pull/154165#issuecomment-2931489616))
73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
#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
|