Initial import: grid-bot — grid trading bot for BTC-USDT on Cifra Markets
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,180 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2022 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// C common API
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_COMMON_H
|
||||
#define ONEAPI_DNNL_DNNL_COMMON_H
|
||||
|
||||
#include "oneapi/dnnl/dnnl_common_types.h"
|
||||
#include "oneapi/dnnl/dnnl_config.h"
|
||||
#include "oneapi/dnnl/dnnl_version.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api oneDNN API
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_common Common API
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_engine Engine
|
||||
/// @{
|
||||
|
||||
/// Returns the number of engines of a particular kind.
|
||||
///
|
||||
/// @param kind Kind of engines to count.
|
||||
/// @returns Count of the engines.
|
||||
size_t DNNL_API dnnl_engine_get_count(dnnl_engine_kind_t kind);
|
||||
|
||||
/// Creates an engine.
|
||||
///
|
||||
/// @param engine Output engine.
|
||||
/// @param kind Engine kind.
|
||||
/// @param index Engine index that should be between 0 and the count of
|
||||
/// engines of the requested kind.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_engine_create(
|
||||
dnnl_engine_t *engine, dnnl_engine_kind_t kind, size_t index);
|
||||
|
||||
/// Returns the kind of an engine.
|
||||
///
|
||||
/// @param engine Engine to query.
|
||||
/// @param kind Output engine kind.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_engine_get_kind(
|
||||
dnnl_engine_t engine, dnnl_engine_kind_t *kind);
|
||||
|
||||
/// Destroys an engine.
|
||||
///
|
||||
/// @param engine Engine to destroy.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_engine_destroy(dnnl_engine_t engine);
|
||||
|
||||
/// @} dnnl_api_engine
|
||||
|
||||
/// @addtogroup dnnl_api_stream Stream
|
||||
/// @{
|
||||
|
||||
/// Creates an execution stream.
|
||||
///
|
||||
/// @param stream Output execution stream.
|
||||
/// @param engine Engine to create the execution stream on.
|
||||
/// @param flags Stream behavior flags (@sa dnnl_stream_flags_t).
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_stream_create(
|
||||
dnnl_stream_t *stream, dnnl_engine_t engine, unsigned flags);
|
||||
|
||||
/// Returns the engine of a stream object.
|
||||
///
|
||||
/// @param stream Stream object.
|
||||
/// @param engine Output engine on which the stream is created.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_stream_get_engine(
|
||||
const_dnnl_stream_t stream, dnnl_engine_t *engine);
|
||||
|
||||
/// Waits for all primitives in the execution stream to finish computations.
|
||||
///
|
||||
/// @param stream Execution stream.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_stream_wait(dnnl_stream_t stream);
|
||||
|
||||
/// Destroys an execution stream.
|
||||
///
|
||||
/// @param stream Execution stream to destroy.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_stream_destroy(dnnl_stream_t stream);
|
||||
|
||||
/// @} dnnl_api_stream
|
||||
|
||||
/// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
|
||||
/// @{
|
||||
|
||||
/// Returns the floating-point math mode that will be used by default
|
||||
/// for all subsequently created primitives.
|
||||
///
|
||||
/// @param mode Output FP math mode.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_get_default_fpmath_mode(dnnl_fpmath_mode_t *mode);
|
||||
|
||||
/// Sets the floating-point math mode that will be used by default
|
||||
/// for all subsequently created primitives.
|
||||
///
|
||||
/// @param mode FP math mode. The possible values are:
|
||||
/// #dnnl_fpmath_mode_strict,
|
||||
/// #dnnl_fpmath_mode_bf16,
|
||||
/// #dnnl_fpmath_mode_f16,
|
||||
/// #dnnl_fpmath_mode_tf32,
|
||||
/// #dnnl_fpmath_mode_any.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_set_default_fpmath_mode(dnnl_fpmath_mode_t mode);
|
||||
|
||||
/// @} dnnl_api_fpmath_mode
|
||||
|
||||
/// @addtogroup dnnl_api_service
|
||||
/// @{
|
||||
|
||||
/// Configures verbose output to stdout.
|
||||
///
|
||||
/// @note
|
||||
/// Enabling verbose output affects performance.
|
||||
/// This setting overrides the ONEDNN_VERBOSE environment variable.
|
||||
///
|
||||
/// @param level Verbosity level:
|
||||
/// - 0: no verbose output (default),
|
||||
/// - 1: primitive and graph information at execution,
|
||||
/// - 2: primitive and graph information at creation/compilation and execution.
|
||||
/// @returns #dnnl_invalid_arguments/#dnnl::status::invalid_arguments if the
|
||||
/// @p level value is invalid, and #dnnl_success/#dnnl::status::success on
|
||||
/// success.
|
||||
dnnl_status_t DNNL_API dnnl_set_verbose(int level);
|
||||
|
||||
/// Returns library version information.
|
||||
/// @returns Pointer to a constant structure containing
|
||||
/// - major: major version number,
|
||||
/// - minor: minor version number,
|
||||
/// - patch: patch release number,
|
||||
/// - hash: git commit hash.
|
||||
const dnnl_version_t DNNL_API *dnnl_version(void);
|
||||
|
||||
/// @} dnnl_api_service
|
||||
|
||||
/// @} dnnl_api_common
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ONEAPI_DNNL_DNNL_COMMON_H */
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,486 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2022 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// C++ common API
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_COMMON_HPP
|
||||
#define ONEAPI_DNNL_DNNL_COMMON_HPP
|
||||
// NOLINTBEGIN(readability-identifier-naming)
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "oneapi/dnnl/dnnl_common.h"
|
||||
/// @endcond
|
||||
|
||||
// If exceptions are enabled:
|
||||
// - gcc < 5 only define __EXCEPTIONS
|
||||
// - MSVC and Clang only define __cpp_exceptions
|
||||
// - new gcc and icx/icpx define both
|
||||
#ifndef DNNL_ENABLE_EXCEPTIONS
|
||||
#if defined(__EXCEPTIONS) || defined(__cpp_exceptions)
|
||||
#define DNNL_ENABLE_EXCEPTIONS 1
|
||||
#else
|
||||
#define DNNL_ENABLE_EXCEPTIONS 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define DNNL_TRAP() __builtin_trap()
|
||||
#elif defined(__INTEL_COMPILER) || defined(_MSC_VER)
|
||||
#define DNNL_TRAP() __debugbreak()
|
||||
#else
|
||||
#error "unknown compiler"
|
||||
#endif
|
||||
|
||||
#if DNNL_ENABLE_EXCEPTIONS
|
||||
#define DNNL_THROW_ERROR(status, msg) throw error(status, msg)
|
||||
#else
|
||||
#include <cstdio>
|
||||
#define DNNL_THROW_ERROR(status, msg) \
|
||||
do { \
|
||||
fputs(msg, stderr); \
|
||||
DNNL_TRAP(); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api oneDNN API
|
||||
/// @{
|
||||
|
||||
/// oneDNN namespace
|
||||
namespace dnnl {
|
||||
|
||||
/// @addtogroup dnnl_api_common Common API
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_utils Utilities
|
||||
/// Utility types and definitions.
|
||||
/// @{
|
||||
|
||||
/// oneDNN exception class.
|
||||
///
|
||||
/// This class captures the status returned by a failed C API function and
|
||||
/// the error message from the call site.
|
||||
struct error : public std::exception {
|
||||
dnnl_status_t status;
|
||||
const char *message;
|
||||
|
||||
/// Constructs an instance of an exception class.
|
||||
///
|
||||
/// @param status The error status returned by a C API function.
|
||||
/// @param message The error message.
|
||||
error(dnnl_status_t status, const char *message)
|
||||
: status(status), message(message) {}
|
||||
|
||||
/// Returns the explanatory string.
|
||||
const char *what() const noexcept override { return message; }
|
||||
|
||||
/// A convenience function for wrapping calls to C API functions. Checks
|
||||
/// the return status and throws an dnnl::error in case of failure.
|
||||
///
|
||||
/// @param status The error status returned by a C API function.
|
||||
/// @param message The error message.
|
||||
static void wrap_c_api(dnnl_status_t status, const char *message) {
|
||||
if (status != dnnl_success) DNNL_THROW_ERROR(status, message);
|
||||
}
|
||||
};
|
||||
|
||||
/// A class that provides the destructor for a oneDNN C API handle.
|
||||
template <typename T>
|
||||
struct handle_traits {};
|
||||
|
||||
/// oneDNN C API handle wrapper class.
|
||||
///
|
||||
/// This class is used as the base class for primitive (dnnl::primitive),
|
||||
/// engine (dnnl::engine), and stream (dnnl::stream) classes, as well as
|
||||
/// others. An object of the dnnl::handle class can be passed by value.
|
||||
///
|
||||
/// A handle can be weak, in which case it follows std::weak_ptr semantics.
|
||||
/// Otherwise, it follows `std::shared_ptr` semantics.
|
||||
///
|
||||
/// @note
|
||||
/// The implementation stores oneDNN C API handles in a `std::shared_ptr`
|
||||
/// with deleter set to a dummy function in the weak mode.
|
||||
///
|
||||
template <typename T, typename traits = handle_traits<T>>
|
||||
struct handle {
|
||||
private:
|
||||
static dnnl_status_t dummy_destructor(T) { return dnnl_success; }
|
||||
std::shared_ptr<typename std::remove_pointer<T>::type> data_ {nullptr};
|
||||
|
||||
protected:
|
||||
bool operator==(const T other) const { return other == data_.get(); }
|
||||
bool operator!=(const T other) const { return !(*this == other); }
|
||||
|
||||
public:
|
||||
/// Constructs an empty handle object.
|
||||
///
|
||||
/// @warning
|
||||
/// Uninitialized object cannot be used in most library calls and is
|
||||
/// equivalent to a null pointer. Any attempt to use its methods, or
|
||||
/// passing it to the other library function, will cause an exception
|
||||
/// to be thrown.
|
||||
handle() = default;
|
||||
|
||||
/// Copy constructor.
|
||||
handle(const handle<T, traits> &) = default;
|
||||
/// Assignment operator.
|
||||
handle<T, traits> &operator=(const handle<T, traits> &) = default;
|
||||
/// Move constructor.
|
||||
handle(handle<T, traits> &&) = default;
|
||||
/// Move assignment operator.
|
||||
handle<T, traits> &operator=(handle<T, traits> &&) = default;
|
||||
|
||||
/// Constructs a handle wrapper object from a C API handle.
|
||||
///
|
||||
/// @param t The C API handle to wrap.
|
||||
/// @param weak A flag specifying whether to construct a weak wrapper;
|
||||
/// defaults to @c false.
|
||||
explicit handle(T t, bool weak = false) { reset(t, weak); }
|
||||
|
||||
/// Resets the handle wrapper objects to wrap a new C API handle.
|
||||
///
|
||||
/// @param t The new value of the C API handle.
|
||||
/// @param weak A flag specifying whether the wrapper should be weak;
|
||||
/// defaults to @c false.
|
||||
void reset(T t, bool weak = false) {
|
||||
data_.reset(t, weak ? &dummy_destructor : traits::destructor);
|
||||
}
|
||||
|
||||
/// Returns the underlying C API handle.
|
||||
///
|
||||
/// @param allow_empty A flag signifying whether the method is allowed to
|
||||
/// return an empty (null) object without throwing an exception.
|
||||
/// @returns The underlying C API handle.
|
||||
T get(bool allow_empty = false) const {
|
||||
T result = data_.get();
|
||||
if (allow_empty == false && result == nullptr)
|
||||
DNNL_THROW_ERROR(
|
||||
dnnl_invalid_arguments, "object is not initialized");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Converts a handle to the underlying C API handle type. Does not throw
|
||||
/// and returns `nullptr` if the object is empty.
|
||||
///
|
||||
/// @returns The underlying C API handle.
|
||||
explicit operator T() const { return get(true); }
|
||||
|
||||
/// Checks whether the object is not empty.
|
||||
///
|
||||
/// @returns Whether the object is not empty.
|
||||
explicit operator bool() const { return get(true) != nullptr; }
|
||||
|
||||
/// Equality operator.
|
||||
///
|
||||
/// @param other Another handle wrapper.
|
||||
/// @returns @c true if this and the other handle wrapper manage the same
|
||||
/// underlying C API handle, and @c false otherwise. Empty handle
|
||||
/// objects are considered to be equal.
|
||||
bool operator==(const handle<T, traits> &other) const {
|
||||
return other.data_.get() == data_.get();
|
||||
}
|
||||
|
||||
/// Inequality operator.
|
||||
///
|
||||
/// @param other Another handle wrapper.
|
||||
/// @returns @c true if this and the other handle wrapper manage different
|
||||
/// underlying C API handles, and @c false otherwise. Empty handle
|
||||
/// objects are considered to be equal.
|
||||
bool operator!=(const handle &other) const { return !(*this == other); }
|
||||
};
|
||||
|
||||
/// @} dnnl_api_utils
|
||||
|
||||
/// @addtogroup dnnl_api_engine Engine
|
||||
///
|
||||
/// An abstraction of a computational device: a CPU, a specific GPU
|
||||
/// card in the system, etc. Most primitives are created to execute
|
||||
/// computations on one specific engine. The only exceptions are reorder
|
||||
/// primitives that transfer data between two different engines.
|
||||
///
|
||||
/// @sa @ref dev_guide_basic_concepts
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
template <>
|
||||
struct handle_traits<dnnl_engine_t> {
|
||||
static dnnl_status_t destructor(dnnl_engine_t p) {
|
||||
return dnnl_engine_destroy(p);
|
||||
}
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
/// An execution engine.
|
||||
struct engine : public handle<dnnl_engine_t> {
|
||||
friend struct primitive;
|
||||
friend struct reorder;
|
||||
|
||||
/// Kinds of engines.
|
||||
enum class kind {
|
||||
/// An unspecified engine
|
||||
any = dnnl_any_engine,
|
||||
/// CPU engine
|
||||
cpu = dnnl_cpu,
|
||||
/// GPU engine
|
||||
gpu = dnnl_gpu,
|
||||
};
|
||||
|
||||
using handle::handle;
|
||||
|
||||
/// Constructs an empty engine. An empty engine cannot be used in any
|
||||
/// operations.
|
||||
engine() = default;
|
||||
|
||||
/// Returns the number of engines of a certain kind.
|
||||
///
|
||||
/// @param akind The kind of engines to count.
|
||||
/// @returns The number of engines of the specified kind.
|
||||
static size_t get_count(kind akind) {
|
||||
return dnnl_engine_get_count(convert_to_c(akind));
|
||||
}
|
||||
|
||||
/// Constructs an engine.
|
||||
///
|
||||
/// @param akind The kind of engine to construct.
|
||||
/// @param index The index of the engine. Must be less than the value
|
||||
/// returned by #get_count() for this particular kind of engine.
|
||||
engine(kind akind, size_t index) {
|
||||
dnnl_engine_t engine;
|
||||
error::wrap_c_api(
|
||||
dnnl_engine_create(&engine, convert_to_c(akind), index),
|
||||
"could not create an engine");
|
||||
reset(engine);
|
||||
}
|
||||
|
||||
/// Returns the kind of the engine.
|
||||
/// @returns The kind of the engine.
|
||||
kind get_kind() const {
|
||||
dnnl_engine_kind_t kind;
|
||||
error::wrap_c_api(dnnl_engine_get_kind(get(), &kind),
|
||||
"could not get kind of an engine");
|
||||
return static_cast<engine::kind>(kind);
|
||||
}
|
||||
|
||||
private:
|
||||
static dnnl_engine_kind_t convert_to_c(kind akind) {
|
||||
return static_cast<dnnl_engine_kind_t>(akind);
|
||||
}
|
||||
};
|
||||
|
||||
/// Converts engine kind enum value from C++ API to C API type.
|
||||
///
|
||||
/// @param akind C++ API engine kind enum value.
|
||||
/// @returns Corresponding C API engine kind enum value.
|
||||
inline dnnl_engine_kind_t convert_to_c(engine::kind akind) {
|
||||
return static_cast<dnnl_engine_kind_t>(akind);
|
||||
}
|
||||
|
||||
/// @} dnnl_api_engine
|
||||
|
||||
/// @addtogroup dnnl_api_stream Stream
|
||||
///
|
||||
/// An encapsulation of execution context tied to a particular engine.
|
||||
///
|
||||
/// @sa @ref dev_guide_basic_concepts
|
||||
///
|
||||
/// @{
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
template <>
|
||||
struct handle_traits<dnnl_stream_t> {
|
||||
static dnnl_status_t destructor(dnnl_stream_t p) {
|
||||
return dnnl_stream_destroy(p);
|
||||
}
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
/// An execution stream.
|
||||
struct stream : public handle<dnnl_stream_t> {
|
||||
using handle::handle;
|
||||
|
||||
/// Stream flags. Can be combined using the bitwise OR operator.
|
||||
enum class flags : unsigned {
|
||||
/// In-order execution.
|
||||
in_order = dnnl_stream_in_order,
|
||||
/// Out-of-order execution.
|
||||
out_of_order = dnnl_stream_out_of_order,
|
||||
/// Default stream configuration.
|
||||
default_flags = dnnl_stream_default_flags,
|
||||
#ifdef DNNL_EXPERIMENTAL_PROFILING
|
||||
/// Enables profiling capabilities.
|
||||
profiling = dnnl_stream_profiling,
|
||||
#endif
|
||||
};
|
||||
|
||||
/// Constructs an empty stream. An empty stream cannot be used in any
|
||||
/// operations.
|
||||
stream() = default;
|
||||
|
||||
/// Constructs a stream for the specified engine and with behavior
|
||||
/// controlled by the specified flags.
|
||||
///
|
||||
/// @param aengine Engine to create the stream on.
|
||||
/// @param aflags Flags controlling stream behavior.
|
||||
explicit stream(
|
||||
const engine &aengine, flags aflags = flags::default_flags) {
|
||||
dnnl_stream_t stream;
|
||||
error::wrap_c_api(dnnl_stream_create(&stream, aengine.get(),
|
||||
static_cast<dnnl_stream_flags_t>(aflags)),
|
||||
"could not create a stream");
|
||||
reset(stream);
|
||||
}
|
||||
|
||||
/// Returns the associated engine.
|
||||
engine get_engine() const {
|
||||
dnnl_engine_t c_engine;
|
||||
error::wrap_c_api(dnnl_stream_get_engine(get(), &c_engine),
|
||||
"could not get an engine from a stream object");
|
||||
return engine(c_engine, true);
|
||||
}
|
||||
|
||||
/// Waits for all primitives executing in the stream to finish.
|
||||
/// @returns The stream itself.
|
||||
stream &wait() {
|
||||
error::wrap_c_api(
|
||||
dnnl_stream_wait(get()), "could not wait on a stream");
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
//NOLINTBEGIN(bugprone-macro-parentheses)
|
||||
#define DNNL_DEFINE_BITMASK_OPS(enum_name) \
|
||||
inline enum_name operator|(enum_name lhs, enum_name rhs) { \
|
||||
return static_cast<enum_name>( \
|
||||
static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); \
|
||||
} \
|
||||
\
|
||||
inline enum_name operator&(enum_name lhs, enum_name rhs) { \
|
||||
return static_cast<enum_name>( \
|
||||
static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); \
|
||||
} \
|
||||
\
|
||||
inline enum_name operator^(enum_name lhs, enum_name rhs) { \
|
||||
return static_cast<enum_name>( \
|
||||
static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); \
|
||||
} \
|
||||
\
|
||||
inline enum_name &operator|=(enum_name &lhs, enum_name rhs) { \
|
||||
lhs = static_cast<enum_name>( \
|
||||
static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
\
|
||||
inline enum_name &operator&=(enum_name &lhs, enum_name rhs) { \
|
||||
lhs = static_cast<enum_name>( \
|
||||
static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
\
|
||||
inline enum_name &operator^=(enum_name &lhs, enum_name rhs) { \
|
||||
lhs = static_cast<enum_name>( \
|
||||
static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
\
|
||||
inline enum_name operator~(enum_name rhs) { \
|
||||
return static_cast<enum_name>(~static_cast<unsigned>(rhs)); \
|
||||
}
|
||||
//NOLINTEND(bugprone-macro-parentheses)
|
||||
|
||||
DNNL_DEFINE_BITMASK_OPS(stream::flags)
|
||||
|
||||
/// @} dnnl_api_stream
|
||||
|
||||
/// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
|
||||
/// @{
|
||||
|
||||
/// Floating-point math mode
|
||||
enum class fpmath_mode {
|
||||
/// Default behavior, no downconversions allowed
|
||||
strict = dnnl_fpmath_mode_strict,
|
||||
/// Implicit f32->bf16 conversions allowed
|
||||
bf16 = dnnl_fpmath_mode_bf16,
|
||||
/// Implicit f32->f16 conversions allowed
|
||||
f16 = dnnl_fpmath_mode_f16,
|
||||
/// Implicit f32->tf32 conversions allowed
|
||||
tf32 = dnnl_fpmath_mode_tf32,
|
||||
/// Implicit f32->f16, f32->tf32 or f32->bf16 conversions allowed
|
||||
any = dnnl_fpmath_mode_any
|
||||
};
|
||||
|
||||
/// Converts an fpmath mode enum value from C++ API to C API type.
|
||||
///
|
||||
/// @param mode C++ API fpmath mode enum value.
|
||||
/// @returns Corresponding C API fpmath mode enum value.
|
||||
inline dnnl_fpmath_mode_t convert_to_c(fpmath_mode mode) {
|
||||
return static_cast<dnnl_fpmath_mode_t>(mode);
|
||||
}
|
||||
|
||||
/// @} dnnl_api_fpmath_mode
|
||||
|
||||
/// @addtogroup dnnl_api_accumulation_mode Accumulation Mode
|
||||
/// @{
|
||||
|
||||
/// Accumulation mode
|
||||
enum class accumulation_mode {
|
||||
/// Default behavior, f32 for floating point computation, s32 for integer
|
||||
strict = dnnl_accumulation_mode_strict,
|
||||
/// same as strict except some partial accumulators can be rounded to
|
||||
/// src/dst datatype in memory.
|
||||
relaxed = dnnl_accumulation_mode_relaxed,
|
||||
/// uses fastest implementation, could use src/dst datatype or
|
||||
/// wider datatype for accumulators
|
||||
any = dnnl_accumulation_mode_any,
|
||||
/// use s32 accumulators during computation
|
||||
s32 = dnnl_accumulation_mode_s32,
|
||||
/// use f32 accumulators during computation
|
||||
f32 = dnnl_accumulation_mode_f32,
|
||||
/// use f16 accumulators during computation
|
||||
f16 = dnnl_accumulation_mode_f16
|
||||
};
|
||||
|
||||
/// Converts an accumulation mode enum value from C++ API to C API type.
|
||||
///
|
||||
/// @param mode C++ API accumulation mode enum value.
|
||||
/// @returns Corresponding C API accumulation mode enum value.
|
||||
inline dnnl_accumulation_mode_t convert_to_c(accumulation_mode mode) {
|
||||
return static_cast<dnnl_accumulation_mode_t>(mode);
|
||||
}
|
||||
|
||||
/// @} dnnl_api_accumulation_mode
|
||||
|
||||
/// @} dnnl_api_common
|
||||
|
||||
} // namespace dnnl
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
// NOLINTEND(readability-identifier-naming)
|
||||
#endif /* ONEAPI_DNNL_DNNL_COMMON_HPP */
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
+272
@@ -0,0 +1,272 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2022 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// C API common types definitions
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_COMMON_TYPES_H
|
||||
#define ONEAPI_DNNL_DNNL_COMMON_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "oneapi/dnnl/dnnl_config.h"
|
||||
|
||||
/// @endcond
|
||||
|
||||
/// @addtogroup dnnl_api oneDNN API
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_common Common API
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_utils
|
||||
/// @{
|
||||
|
||||
/// Status values returned by the library functions.
|
||||
typedef enum {
|
||||
/// The operation was successful
|
||||
dnnl_success = 0,
|
||||
/// The operation failed due to an out-of-memory condition
|
||||
dnnl_out_of_memory = 1,
|
||||
/// The operation failed because of incorrect function arguments
|
||||
dnnl_invalid_arguments = 2,
|
||||
/// The operation failed because requested functionality is not implemented
|
||||
dnnl_unimplemented = 3,
|
||||
/// The last available implementation is reached
|
||||
dnnl_last_impl_reached = 4,
|
||||
/// Primitive or engine failed on execution
|
||||
dnnl_runtime_error = 5,
|
||||
/// Queried element is not required for given primitive
|
||||
dnnl_not_required = 6,
|
||||
/// The graph is not legitimate
|
||||
dnnl_invalid_graph = 7,
|
||||
/// The operation is not legitimate according to op schema
|
||||
dnnl_invalid_graph_op = 8,
|
||||
/// The shape cannot be inferred or compiled
|
||||
dnnl_invalid_shape = 9,
|
||||
/// The data type cannot be inferred or compiled
|
||||
dnnl_invalid_data_type = 10,
|
||||
} dnnl_status_t;
|
||||
|
||||
/// @} dnnl_api_utils
|
||||
|
||||
/// @addtogroup dnnl_api_data_types Data types
|
||||
/// @{
|
||||
|
||||
/// Data type specification
|
||||
typedef enum {
|
||||
/// Undefined data type, used for empty memory descriptors.
|
||||
dnnl_data_type_undef = 0,
|
||||
/// 16-bit/half-precision floating point.
|
||||
dnnl_f16 = 1,
|
||||
/// non-standard 16-bit (bfloat16 w/ 7 bit mantissa) floating point.
|
||||
dnnl_bf16 = 2,
|
||||
/// 32-bit/single-precision floating point.
|
||||
dnnl_f32 = 3,
|
||||
/// 32-bit signed integer.
|
||||
dnnl_s32 = 4,
|
||||
/// 8-bit signed integer.
|
||||
dnnl_s8 = 5,
|
||||
/// 8-bit unsigned integer.
|
||||
dnnl_u8 = 6,
|
||||
/// 64-bit/double-precision floating point.
|
||||
dnnl_f64 = 7,
|
||||
/// Boolean data type. Size is C++ implementation defined.
|
||||
dnnl_boolean = 8,
|
||||
/// [OFP8 standard 8-bit floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
|
||||
/// with a 5-bit exponent and a 2-bit mantissa.
|
||||
dnnl_f8_e5m2 = 9,
|
||||
/// [OFP8 standard 8-bit floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
|
||||
/// with a 4-bit exponent and a 3-bit mantissa.
|
||||
dnnl_f8_e4m3 = 10,
|
||||
/// 4-bit signed integer.
|
||||
dnnl_s4 = 11,
|
||||
/// 4-bit unsigned integer.
|
||||
dnnl_u4 = 12,
|
||||
/// [MX-compliant 8-bit compliant scale data type](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf) with 8-bit exponent.
|
||||
dnnl_e8m0 = 13,
|
||||
/// [MX-compliant 4-bit float data type](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf) with 2-bit exponent and 1 bit mantissa.
|
||||
dnnl_f4_e2m1 = 14,
|
||||
/// 4-bit float data type with 3-bit exponent and 0 bit mantissa.
|
||||
dnnl_f4_e3m0 = 15,
|
||||
/// 64-bit signed integer
|
||||
dnnl_s64 = 16,
|
||||
|
||||
// Max value to prevent UB for internal-use-only values.
|
||||
dnnl_data_type_max = 0x7fff,
|
||||
} dnnl_data_type_t;
|
||||
|
||||
/// Maximum number of dimensions a tensor can have. Only restricts the amount
|
||||
/// of space used for the tensor description. Individual computational
|
||||
/// primitives may support only tensors of certain dimensions.
|
||||
#define DNNL_MAX_NDIMS 12
|
||||
|
||||
/// A type to describe tensor dimension.
|
||||
typedef int64_t dnnl_dim_t;
|
||||
|
||||
/// A type to describe tensor dimensions.
|
||||
typedef dnnl_dim_t dnnl_dims_t[DNNL_MAX_NDIMS];
|
||||
|
||||
/// @} dnnl_api_data_types
|
||||
|
||||
/// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
|
||||
/// @{
|
||||
|
||||
/// Floating-point math mode
|
||||
typedef enum {
|
||||
/// Default behavior, no downconversions allowed
|
||||
dnnl_fpmath_mode_strict,
|
||||
/// Implicit f32->bf16 conversions allowed
|
||||
dnnl_fpmath_mode_bf16,
|
||||
/// Implicit f32->f16 conversions allowed
|
||||
dnnl_fpmath_mode_f16,
|
||||
/// Implicit f32->f16, f32->tf32 or f32->bf16 conversions allowed
|
||||
dnnl_fpmath_mode_any,
|
||||
/// Implicit f32->tf32 conversions allowed
|
||||
dnnl_fpmath_mode_tf32,
|
||||
} dnnl_fpmath_mode_t;
|
||||
|
||||
/// @} dnnl_api_fpmath_mode
|
||||
|
||||
/// @addtogroup dnnl_api_accumulation_mode Accumulation Mode
|
||||
/// @{
|
||||
|
||||
/// Accumulation mode
|
||||
typedef enum {
|
||||
/// Default behavior, f32/f64 for floating point computation, s32
|
||||
/// for integer
|
||||
dnnl_accumulation_mode_strict,
|
||||
/// Same as strict but allows some partial accumulators to be
|
||||
/// rounded to src/dst datatype in memory.
|
||||
dnnl_accumulation_mode_relaxed,
|
||||
/// uses fastest implementation, could use src/dst datatype or
|
||||
/// wider datatype for accumulators
|
||||
dnnl_accumulation_mode_any,
|
||||
/// use s32 accumulators during computation
|
||||
dnnl_accumulation_mode_s32,
|
||||
/// use f32 accumulators during computation
|
||||
dnnl_accumulation_mode_f32,
|
||||
/// use f16 accumulators during computation
|
||||
dnnl_accumulation_mode_f16
|
||||
} dnnl_accumulation_mode_t;
|
||||
|
||||
/// @} dnnl_api_accumulation_mode
|
||||
|
||||
/// @addtogroup dnnl_api_engine Engine
|
||||
/// @{
|
||||
|
||||
/// @brief Kinds of engines.
|
||||
typedef enum {
|
||||
/// An unspecified engine.
|
||||
dnnl_any_engine,
|
||||
/// CPU engine.
|
||||
dnnl_cpu,
|
||||
/// GPU engine.
|
||||
dnnl_gpu,
|
||||
} dnnl_engine_kind_t;
|
||||
|
||||
/// @struct dnnl_engine
|
||||
/// @brief An opaque structure to describe an engine.
|
||||
struct dnnl_engine;
|
||||
/// @brief An engine handle.
|
||||
typedef struct dnnl_engine *dnnl_engine_t;
|
||||
#if 0
|
||||
// FIXME: looks like this never happens
|
||||
/// @brief A constant engine handle.
|
||||
typedef const struct dnnl_engine *const_dnnl_engine_t;
|
||||
#endif
|
||||
|
||||
/// @} dnnl_api_engine
|
||||
|
||||
/// @addtogroup dnnl_api_stream Stream
|
||||
/// @{
|
||||
|
||||
/// @brief Stream flags.
|
||||
typedef enum {
|
||||
// In-order execution.
|
||||
dnnl_stream_in_order = 0x1U,
|
||||
/// Out-of-order execution.
|
||||
dnnl_stream_out_of_order = 0x2U,
|
||||
/// Default stream configuration.
|
||||
dnnl_stream_default_flags = dnnl_stream_in_order,
|
||||
#ifdef DNNL_EXPERIMENTAL_PROFILING
|
||||
/// Enables profiling capabilities.
|
||||
dnnl_stream_profiling = 0x4U,
|
||||
#endif
|
||||
|
||||
// Max value to prevent UB for internal-use-only values.
|
||||
dnnl_stream_flags_max = 0x7fff,
|
||||
} dnnl_stream_flags_t;
|
||||
|
||||
/// @struct dnnl_stream
|
||||
/// An opaque structure to describe an execution stream.
|
||||
struct dnnl_stream;
|
||||
/// An execution stream handle.
|
||||
typedef struct dnnl_stream *dnnl_stream_t;
|
||||
/// A constant execution stream handle.
|
||||
typedef const struct dnnl_stream *const_dnnl_stream_t;
|
||||
|
||||
/// @} dnnl_api_stream
|
||||
|
||||
/// @addtogroup dnnl_api_service
|
||||
/// @{
|
||||
|
||||
/// Structure containing version information as per [Semantic
|
||||
/// Versioning](https://semver.org)
|
||||
typedef struct {
|
||||
int major; ///< Major version
|
||||
int minor; ///< Minor version
|
||||
int patch; ///< Patch version
|
||||
const char *hash; ///< Git hash of the sources (may be absent)
|
||||
unsigned cpu_runtime; ///< CPU runtime
|
||||
unsigned gpu_runtime; ///< GPU runtime
|
||||
} dnnl_version_t;
|
||||
|
||||
/// @} dnnl_api_service
|
||||
|
||||
/// @addtogroup dnnl_api_memory
|
||||
/// @{
|
||||
|
||||
/// Special pointer value that indicates that a memory object should not have
|
||||
/// an underlying buffer.
|
||||
#define DNNL_MEMORY_NONE (NULL)
|
||||
|
||||
/// Special pointer value that indicates that the library needs to allocate an
|
||||
/// underlying buffer for a memory object.
|
||||
#define DNNL_MEMORY_ALLOCATE ((void *)(size_t) - 1)
|
||||
|
||||
/// @} dnnl_api_memory
|
||||
|
||||
/// @} dnnl_api_common
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,240 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2019 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_CONFIG_H
|
||||
#define ONEAPI_DNNL_DNNL_CONFIG_H
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
|
||||
// All symbols shall be internal unless marked as DNNL_API
|
||||
#if defined _WIN32 || defined __CYGWIN__
|
||||
#define DNNL_HELPER_DLL_IMPORT __declspec(dllimport)
|
||||
#define DNNL_HELPER_DLL_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#if __GNUC__ >= 4
|
||||
#define DNNL_HELPER_DLL_IMPORT __attribute__((visibility("default")))
|
||||
#define DNNL_HELPER_DLL_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define DNNL_HELPER_DLL_IMPORT
|
||||
#define DNNL_HELPER_DLL_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DNNL_DLL
|
||||
#ifdef DNNL_DLL_EXPORTS
|
||||
#define DNNL_API DNNL_HELPER_DLL_EXPORT
|
||||
#else
|
||||
#define DNNL_API DNNL_HELPER_DLL_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#define DNNL_API
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define DNNL_DEPRECATED __attribute__((deprecated))
|
||||
#elif defined(_MSC_VER)
|
||||
#define DNNL_DEPRECATED __declspec(deprecated)
|
||||
#else
|
||||
#define DNNL_DEPRECATED
|
||||
#endif
|
||||
|
||||
/// @endcond
|
||||
|
||||
// clang-format off
|
||||
|
||||
/// @addtogroup dnnl_api_service
|
||||
/// @{
|
||||
|
||||
/// No runtime (disabled)
|
||||
#define DNNL_RUNTIME_NONE 0u
|
||||
|
||||
/// Sequential runtime (CPU only)
|
||||
#define DNNL_RUNTIME_SEQ 1u
|
||||
|
||||
/// OpenMP runtime (CPU only)
|
||||
#define DNNL_RUNTIME_OMP 2u
|
||||
|
||||
/// TBB runtime (CPU only)
|
||||
#define DNNL_RUNTIME_TBB 4u
|
||||
|
||||
/// Threadpool runtime (CPU only)
|
||||
#define DNNL_RUNTIME_THREADPOOL 8u
|
||||
|
||||
/// OpenCL runtime
|
||||
#define DNNL_RUNTIME_OCL 256u
|
||||
|
||||
/// SYCL runtime
|
||||
#define DNNL_RUNTIME_SYCL 512u
|
||||
|
||||
/// DPC++ runtime
|
||||
#define DNNL_RUNTIME_DPCPP DNNL_RUNTIME_SYCL
|
||||
|
||||
/// No vendor (corresponding runtime is disabled)
|
||||
#define DNNL_VENDOR_NONE 0u
|
||||
|
||||
/// Intel vendor
|
||||
#define DNNL_VENDOR_INTEL 1u
|
||||
|
||||
/// NVIDIA vendor
|
||||
#define DNNL_VENDOR_NVIDIA 2u
|
||||
|
||||
/// AMD vendor
|
||||
#define DNNL_VENDOR_AMD 4u
|
||||
|
||||
/// Generic vendor
|
||||
#define DNNL_VENDOR_GENERIC 8u
|
||||
|
||||
/// @} dnnl_api_service
|
||||
|
||||
// oneDNN CPU threading runtime
|
||||
#define DNNL_CPU_THREADING_RUNTIME DNNL_RUNTIME_OMP
|
||||
|
||||
// oneDNN CPU engine runtime
|
||||
#define DNNL_CPU_RUNTIME DNNL_RUNTIME_OMP
|
||||
|
||||
// oneDNN GPU engine runtime
|
||||
#define DNNL_GPU_RUNTIME DNNL_RUNTIME_NONE
|
||||
|
||||
// oneDNN GPU vendor
|
||||
#define DNNL_GPU_VENDOR DNNL_VENDOR_NONE
|
||||
|
||||
// clang-format on
|
||||
|
||||
#if defined(DNNL_CPU_RUNTIME) && defined(DNNL_GPU_RUNTIME)
|
||||
#if (DNNL_CPU_RUNTIME == DNNL_RUNTIME_OCL)
|
||||
#error "Unexpected DNNL_CPU_RUNTIME"
|
||||
#endif
|
||||
#if (DNNL_GPU_RUNTIME != DNNL_RUNTIME_NONE) \
|
||||
&& (DNNL_GPU_RUNTIME != DNNL_RUNTIME_OCL) \
|
||||
&& (DNNL_GPU_RUNTIME != DNNL_RUNTIME_SYCL)
|
||||
#error "Unexpected DNNL_GPU_RUNTIME"
|
||||
#endif
|
||||
#if (DNNL_CPU_RUNTIME == DNNL_RUNTIME_NONE \
|
||||
&& DNNL_GPU_RUNTIME == DNNL_RUNTIME_NONE)
|
||||
#error "At least one runtime must be specified"
|
||||
#endif
|
||||
#else
|
||||
#error "BOTH DNNL_CPU_RUNTIME and DNNL_GPU_RUNTIME must be defined"
|
||||
#endif
|
||||
|
||||
// For SYCL CPU, a primitive may be created and executed in different threads
|
||||
// hence the global scratchpad does not work. This enables concurrent execution
|
||||
// when CPU runtime is SYCL to avoid the issue.
|
||||
#if DNNL_CPU_RUNTIME == DNNL_RUNTIME_SYCL
|
||||
#ifndef DNNL_ENABLE_CONCURRENT_EXEC
|
||||
#define DNNL_ENABLE_CONCURRENT_EXEC
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// When defined, primitive cache stores runtime objects.
|
||||
/* #undef DNNL_USE_RT_OBJECTS_IN_PRIMITIVE_CACHE */
|
||||
|
||||
// When defined, DPCPP is supported.
|
||||
/* #undef DNNL_WITH_SYCL */
|
||||
|
||||
// When defined, Level Zero is supported.
|
||||
/* #undef DNNL_WITH_LEVEL_ZERO */
|
||||
|
||||
// When defined, SYCL CUDA backend is used.
|
||||
/* #undef DNNL_SYCL_CUDA */
|
||||
|
||||
// When defined, SYCL HIP backend is used.
|
||||
/* #undef DNNL_SYCL_HIP */
|
||||
|
||||
// When defined, SYCL Generic backend is used.
|
||||
/* #undef DNNL_SYCL_GENERIC */
|
||||
|
||||
// When defined, stack checker is enabled.
|
||||
/* #undef DNNL_ENABLE_STACK_CHECKER */
|
||||
|
||||
// When defined, experimental features are enabled.
|
||||
/* #undef DNNL_EXPERIMENTAL */
|
||||
|
||||
// When defined, experimental functionality for ukernels is enabled.
|
||||
#define DNNL_EXPERIMENTAL_UKERNEL
|
||||
|
||||
// When defined, graph component is enabled.
|
||||
#define ONEDNN_BUILD_GRAPH
|
||||
|
||||
// When defined, experimental profiling capabilities are enabled.
|
||||
/* #undef DNNL_EXPERIMENTAL_PROFILING */
|
||||
|
||||
// When defined, experimental logging capabilities are enabled.
|
||||
/* #undef DNNL_EXPERIMENTAL_LOGGING */
|
||||
|
||||
// When defined, RBP register is untouchable in JIT kernels
|
||||
// to allow stack unwind
|
||||
/* #undef DNNL_SAFE_RBP */
|
||||
|
||||
// When defined, experimental SYCL capabilities are enabled.
|
||||
/* #undef DNNL_EXPERIMENTAL_SYCL_KERNEL_COMPILER */
|
||||
|
||||
// When defined, it disables GPU compute reference kernels.
|
||||
/* #undef DNNL_DISABLE_GPU_REF_KERNELS */
|
||||
|
||||
// List of configurating build controls
|
||||
// Workload controls
|
||||
#define BUILD_TRAINING 1
|
||||
#define BUILD_INFERENCE 0
|
||||
// Primitive controls
|
||||
#define BUILD_PRIMITIVE_ALL 1
|
||||
#define BUILD_BATCH_NORMALIZATION 0
|
||||
#define BUILD_BINARY 0
|
||||
#define BUILD_CONCAT 0
|
||||
#define BUILD_CONVOLUTION 0
|
||||
#define BUILD_DECONVOLUTION 0
|
||||
#define BUILD_ELTWISE 0
|
||||
#define BUILD_GROUP_NORMALIZATION 0
|
||||
#define BUILD_INNER_PRODUCT 0
|
||||
#define BUILD_LAYER_NORMALIZATION 0
|
||||
#define BUILD_LRN 0
|
||||
#define BUILD_MATMUL 0
|
||||
#define BUILD_POOLING 0
|
||||
#define BUILD_PRELU 0
|
||||
#define BUILD_REDUCTION 0
|
||||
#define BUILD_REORDER 0
|
||||
#define BUILD_RESAMPLING 0
|
||||
#define BUILD_RNN 0
|
||||
#define BUILD_SDPA 0
|
||||
#define BUILD_SHUFFLE 0
|
||||
#define BUILD_SOFTMAX 0
|
||||
#define BUILD_SUM 0
|
||||
// Primitives CPU ISA controls
|
||||
#define BUILD_PRIMITIVE_CPU_ISA_ALL 1
|
||||
#define BUILD_SSE41 0
|
||||
#define BUILD_AVX2 0
|
||||
#define BUILD_AVX512 0
|
||||
#define BUILD_AMX 0
|
||||
// Primitives GPU ISA controls
|
||||
#define BUILD_PRIMITIVE_GPU_ISA_ALL 1
|
||||
#define BUILD_XELP 0
|
||||
#define BUILD_XEHP 0
|
||||
#define BUILD_XEHPG 0
|
||||
#define BUILD_XEHPC 0
|
||||
#define BUILD_XE2 0
|
||||
#define BUILD_XE3 0
|
||||
// GeMM kernels ISA controls
|
||||
#define BUILD_GEMM_KERNELS_ALL 1
|
||||
#define BUILD_GEMM_KERNELS_NONE 0
|
||||
#define BUILD_GEMM_SSE41 0
|
||||
#define BUILD_GEMM_AVX2 0
|
||||
#define BUILD_GEMM_AVX512 0
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,65 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2018 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
// DO NOT EDIT, AUTO-GENERATED
|
||||
// Use this script to update the file: scripts/generate_dnnl_debug.py
|
||||
|
||||
// clang-format off
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_DEBUG_H
|
||||
#define ONEAPI_DNNL_DNNL_DEBUG_H
|
||||
|
||||
/// @file
|
||||
/// Debug capabilities
|
||||
|
||||
#include "oneapi/dnnl/dnnl_config.h"
|
||||
#include "oneapi/dnnl/dnnl_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char DNNL_API *dnnl_status2str(dnnl_status_t v);
|
||||
const char DNNL_API *dnnl_dt2str(dnnl_data_type_t v);
|
||||
const char DNNL_API *dnnl_fpmath_mode2str(dnnl_fpmath_mode_t v);
|
||||
const char DNNL_API *dnnl_accumulation_mode2str(dnnl_accumulation_mode_t v);
|
||||
const char DNNL_API *dnnl_engine_kind2str(dnnl_engine_kind_t v);
|
||||
const char DNNL_API *dnnl_sparse_encoding2str(dnnl_sparse_encoding_t v);
|
||||
const char DNNL_API *dnnl_fmt_tag2str(dnnl_format_tag_t v);
|
||||
const char DNNL_API *dnnl_prop_kind2str(dnnl_prop_kind_t v);
|
||||
const char DNNL_API *dnnl_prim_kind2str(dnnl_primitive_kind_t v);
|
||||
const char DNNL_API *dnnl_alg_kind2str(dnnl_alg_kind_t v);
|
||||
const char DNNL_API *dnnl_rnn_flags2str(dnnl_rnn_flags_t v);
|
||||
const char DNNL_API *dnnl_rnn_direction2str(dnnl_rnn_direction_t v);
|
||||
const char DNNL_API *dnnl_scratchpad_mode2str(dnnl_scratchpad_mode_t v);
|
||||
const char DNNL_API *dnnl_rounding_mode2str(dnnl_rounding_mode_t v);
|
||||
const char DNNL_API *dnnl_quantization_mode2str(dnnl_quantization_mode_t v);
|
||||
const char DNNL_API *dnnl_cpu_isa2str(dnnl_cpu_isa_t v);
|
||||
const char DNNL_API *dnnl_cpu_isa_hints2str(dnnl_cpu_isa_hints_t v);
|
||||
|
||||
const char DNNL_API *dnnl_runtime2str(unsigned v);
|
||||
const char DNNL_API *dnnl_fmt_kind2str(dnnl_format_kind_t v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,814 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// Graph C API
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_GRAPH_H
|
||||
#define ONEAPI_DNNL_DNNL_GRAPH_H
|
||||
|
||||
#include "oneapi/dnnl/dnnl_common.h"
|
||||
#include "oneapi/dnnl/dnnl_config.h"
|
||||
#include "oneapi/dnnl/dnnl_graph_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api_allocator
|
||||
/// @{
|
||||
|
||||
/// Creates a host allocator with the given allocation and deallocation
|
||||
/// call-back function pointers.
|
||||
///
|
||||
/// @param allocator Output allocator.
|
||||
/// @param host_malloc A pointer to malloc function for host.
|
||||
/// @param host_free A pointer to free function for host.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_allocator_create(
|
||||
dnnl_graph_allocator_t *allocator,
|
||||
dnnl_graph_host_allocate_f host_malloc,
|
||||
dnnl_graph_host_deallocate_f host_free);
|
||||
|
||||
/// Destroys an allocator.
|
||||
///
|
||||
/// @param allocator The allocator to be destroyed.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_allocator_destroy(
|
||||
dnnl_graph_allocator_t allocator);
|
||||
|
||||
/// @} dnnl_graph_api_allocator
|
||||
|
||||
/// @addtogroup dnnl_graph_api_engine
|
||||
/// @{
|
||||
|
||||
/// This API is a supplement for existing onednn engine API.
|
||||
dnnl_status_t DNNL_API dnnl_graph_make_engine_with_allocator(
|
||||
dnnl_engine_t *engine, dnnl_engine_kind_t kind, size_t index,
|
||||
const_dnnl_graph_allocator_t alloc);
|
||||
|
||||
/// @} dnnl_graph_api_engine
|
||||
|
||||
/// @addtogroup dnnl_graph_api_logical_tensor
|
||||
/// @{
|
||||
|
||||
/// Initializes a logical tensor with id, data type, number of dimensions,
|
||||
/// layout type, and property. The logical tensor's dims are unknown with this
|
||||
/// interface.
|
||||
///
|
||||
/// @param logical_tensor Output logical tensor.
|
||||
/// @param tid The unique id of the output logical tensor.
|
||||
/// @param dtype Elements data type.
|
||||
/// @param ndims Number of dimensions.
|
||||
/// @param ltype Layout type of the underlying tensor buffer.
|
||||
/// @param ptype Tensor property type.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_logical_tensor_init(
|
||||
dnnl_graph_logical_tensor_t *logical_tensor, size_t tid,
|
||||
dnnl_data_type_t dtype, int32_t ndims, dnnl_graph_layout_type_t ltype,
|
||||
dnnl_graph_tensor_property_t ptype);
|
||||
|
||||
/// Initializes a logical tensor with basic information and dims. The logical
|
||||
/// tensor's dimensions and layout will be initialized according to the input
|
||||
/// arguments.
|
||||
///
|
||||
/// @note
|
||||
/// If dims contains all valid values and layout type is
|
||||
/// #dnnl_graph_layout_type_strided. The strides field in
|
||||
/// #dnnl_graph_logical_tensor_t will be calculated in a row major and
|
||||
/// contiguous way. Otherwise, Accessing the strides field is an undefined
|
||||
/// behavior.
|
||||
///
|
||||
/// Eg. dims (2, 3, 4, 5) will get strides (60, 20, 5, 1)
|
||||
///
|
||||
/// @param logical_tensor Output logical tensor.
|
||||
/// @param tid The unique id of output logical tensor.
|
||||
/// @param dtype Elements data type.
|
||||
/// @param ndims Number of dimensions.
|
||||
/// @param dims Array of dimensions.
|
||||
/// @param ltype Layout type of the underlying tensor memory.
|
||||
/// @param ptype Tensor property type.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_logical_tensor_init_with_dims(
|
||||
dnnl_graph_logical_tensor_t *logical_tensor, size_t tid,
|
||||
dnnl_data_type_t dtype, int32_t ndims, const dnnl_dims_t dims,
|
||||
dnnl_graph_layout_type_t ltype, dnnl_graph_tensor_property_t ptype);
|
||||
|
||||
/// Initializes a logical tensor with dimensions and strides provided by user.
|
||||
///
|
||||
/// @note
|
||||
/// Once strides are explicitly provided through the API, the `layout_type`
|
||||
/// in #dnnl_graph_logical_tensor_t can only be
|
||||
/// #dnnl_graph_layout_type_strided or #dnnl_graph_layout_type_any.
|
||||
///
|
||||
/// @param logical_tensor Output logical tensor.
|
||||
/// @param tid The unique id of output logical tensor.
|
||||
/// @param dtype Elements data type.
|
||||
/// @param ndims Number of dimensions.
|
||||
/// @param dims Array of dimensions.
|
||||
/// @param strides Array of strides.
|
||||
/// @param ptype Tensor property type.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_logical_tensor_init_with_strides(
|
||||
dnnl_graph_logical_tensor_t *logical_tensor, size_t tid,
|
||||
dnnl_data_type_t dtype, int32_t ndims, const dnnl_dims_t dims,
|
||||
const dnnl_dims_t strides, dnnl_graph_tensor_property_t ptype);
|
||||
|
||||
/// Returns the memory size described by the logical tensor. If it's a strided
|
||||
/// layout, the size will be calculated by `dims` and `strides`. If it's an
|
||||
/// opaque layout, the size will be decided by `layout_id`.
|
||||
///
|
||||
/// @param logical_tensor Logical tensor.
|
||||
/// @param size Output memory size in bytes.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_logical_tensor_get_mem_size(
|
||||
const dnnl_graph_logical_tensor_t *logical_tensor, size_t *size);
|
||||
|
||||
/// Compares if two logical tenors are equal. Users can decide accordingly
|
||||
/// if layout reordering is needed for two logical tensors. The method will
|
||||
/// return true for below two circumstances:
|
||||
///
|
||||
/// 1. the two logical tensors are equal regarding each field in the struct,
|
||||
/// eg. id, ndims, dims, layout type, property, etc.
|
||||
/// 2. If all other fields are equal but the layout types in two logical
|
||||
/// tensors are different, the method will return true when the underlying
|
||||
/// memory layout is the same. For example, one logical tensor has strided
|
||||
/// layout type while the other one has opaque layout type, but underneath,
|
||||
/// both layouts are NHWC, the method will still return true for this case.
|
||||
///
|
||||
/// @param lt1 The handle of first logical tensor.
|
||||
/// @param lt2 The handle of second logical tensor.
|
||||
/// @param is_equal 1 if these two logical tensors are equal, 0 otherwise.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_logical_tensor_is_equal(
|
||||
const dnnl_graph_logical_tensor_t *lt1,
|
||||
const dnnl_graph_logical_tensor_t *lt2, uint8_t *is_equal);
|
||||
|
||||
/// @} dnnl_graph_api_logical_tensor
|
||||
|
||||
/// @addtogroup dnnl_graph_api_tensor
|
||||
/// @{
|
||||
|
||||
/// Creates a tensor with logical tensor, engine, and data handle.
|
||||
///
|
||||
/// @param tensor Output tensor.
|
||||
/// @param logical_tensor Description for this tensor.
|
||||
/// @param engine Engine to use.
|
||||
/// @param handle Handle of the memory buffer to use as an underlying storage.
|
||||
/// - A pointer to the user-allocated buffer. In this case the library
|
||||
/// doesn't own the buffer.
|
||||
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
|
||||
/// allocate the buffer for the tensor. In this case the library
|
||||
/// owns the buffer.
|
||||
/// - DNNL_MEMORY_NONE to create tensor without an underlying buffer.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_tensor_create(dnnl_graph_tensor_t *tensor,
|
||||
const dnnl_graph_logical_tensor_t *logical_tensor, dnnl_engine_t engine,
|
||||
void *handle);
|
||||
|
||||
/// Creates a scalar tensor with logical tensor and scalar data handle.
|
||||
///
|
||||
/// @param tensor Output scalar tensor.
|
||||
/// @param logical_tensor Description for this tensor.
|
||||
/// @param handle Handle of the memory buffer to use as an underlying storage.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_tensor_create_scalar(
|
||||
dnnl_graph_tensor_t *tensor,
|
||||
const dnnl_graph_logical_tensor_t *logical_tensor, void *handle);
|
||||
|
||||
/// Destroys a tensor.
|
||||
///
|
||||
/// @param tensor The tensor to be destroyed.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_tensor_destroy(dnnl_graph_tensor_t tensor);
|
||||
|
||||
/// Gets the data handle of a tensor.
|
||||
///
|
||||
/// @param tensor The input tensor.
|
||||
/// @param handle Pointer to the data of input tensor.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_tensor_get_data_handle(
|
||||
const_dnnl_graph_tensor_t tensor, void **handle);
|
||||
|
||||
/// Set data handle for a tensor.
|
||||
///
|
||||
/// @param tensor The input tensor.
|
||||
/// @param handle New data handle for tensor.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_tensor_set_data_handle(
|
||||
dnnl_graph_tensor_t tensor, void *handle);
|
||||
|
||||
/// Returns the engine of a tensor object.
|
||||
///
|
||||
/// @param tensor The input tensor.
|
||||
/// @param engine Output engine on which the tensor is located.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_tensor_get_engine(
|
||||
const_dnnl_graph_tensor_t tensor, dnnl_engine_t *engine);
|
||||
|
||||
/// Returns the logical tensor of a tensor object.
|
||||
///
|
||||
/// @param tensor The input tensor.
|
||||
/// @param logical_tensor Output logical tensor of the tensor object.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_tensor_get_logical_tensor(
|
||||
const_dnnl_graph_tensor_t tensor,
|
||||
dnnl_graph_logical_tensor_t *logical_tensor);
|
||||
|
||||
/// @} dnnl_graph_api_tensor
|
||||
|
||||
/// @addtogroup dnnl_graph_api_op
|
||||
/// @{
|
||||
|
||||
/// Initializes an op with unique id, kind, and name.
|
||||
///
|
||||
/// @param op Output op
|
||||
/// @param id The unique id of the output op.
|
||||
/// @param kind The op kind.
|
||||
/// @param verbose_name The string added as the op name.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_create(dnnl_graph_op_t *op, size_t id,
|
||||
dnnl_graph_op_kind_t kind, const char *verbose_name);
|
||||
|
||||
/// Destroys an op.
|
||||
///
|
||||
/// @param op The op to be destroyed.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_destroy(dnnl_graph_op_t op);
|
||||
|
||||
/// Adds input logical tensor to the op.
|
||||
///
|
||||
/// @param op Input op.
|
||||
/// @param input The input logical tensor to be added.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_add_input(
|
||||
dnnl_graph_op_t op, const dnnl_graph_logical_tensor_t *input);
|
||||
|
||||
/// Adds output logical tensor to the op.
|
||||
///
|
||||
/// @param op Input op.
|
||||
/// @param output The output logical tensor to be added.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_add_output(
|
||||
dnnl_graph_op_t op, const dnnl_graph_logical_tensor_t *output);
|
||||
|
||||
/// Sets floating point attribute to an op.
|
||||
///
|
||||
/// @param op Input op.
|
||||
/// @param name The attribute's name.
|
||||
/// @param value The attribute's value.
|
||||
/// @param value_len The number of value element.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_set_attr_f32(dnnl_graph_op_t op,
|
||||
dnnl_graph_op_attr_t name, const float *value, size_t value_len);
|
||||
|
||||
/// Sets boolean attribute to an op.
|
||||
///
|
||||
/// @param op Input op.
|
||||
/// @param name The attribute's name.
|
||||
/// @param value The attribute's value.
|
||||
/// @param value_len The number of value element.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_set_attr_bool(dnnl_graph_op_t op,
|
||||
dnnl_graph_op_attr_t name, const uint8_t *value, size_t value_len);
|
||||
|
||||
/// Sets integer attribute to an op.
|
||||
///
|
||||
/// @param op Input op.
|
||||
/// @param name The attribute's name.
|
||||
/// @param value The attribute's value.
|
||||
/// @param value_len The number of value element.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_set_attr_s64(dnnl_graph_op_t op,
|
||||
dnnl_graph_op_attr_t name, const int64_t *value, size_t value_len);
|
||||
|
||||
/// Sets string attribute to an op.
|
||||
///
|
||||
/// @param op Input op.
|
||||
/// @param name The attribute's name.
|
||||
/// @param value The attribute's value.
|
||||
/// @param value_len The length of the string value.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_set_attr_str(dnnl_graph_op_t op,
|
||||
dnnl_graph_op_attr_t name, const char *value, size_t value_len);
|
||||
|
||||
/// Returns the unique id of an op.
|
||||
///
|
||||
/// @param op Input op.
|
||||
/// @param id Output the unique id.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_get_id(
|
||||
const_dnnl_graph_op_t op, size_t *id);
|
||||
|
||||
/// Returns the kind of an op.
|
||||
///
|
||||
/// @param op Input op.
|
||||
/// @param kind Output op kind.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_op_get_kind(
|
||||
const_dnnl_graph_op_t op, dnnl_graph_op_kind_t *kind);
|
||||
|
||||
/// @} dnnl_graph_api_op
|
||||
|
||||
/// @addtogroup dnnl_graph_api_partition
|
||||
/// @{
|
||||
|
||||
/// Creates a new partition with a given operator and engine kind. The API is
|
||||
/// used to create a partition from an operation directly without creating the
|
||||
/// graph and calling `get_partitions()`. The output partition contains only one
|
||||
/// operation specified by the parameter. The output partition instance should
|
||||
/// be destroyed via #dnnl_graph_partition_destroy after use.
|
||||
///
|
||||
/// @param partition The handle of output partition.
|
||||
/// @param op The operation used to create partition.
|
||||
/// @param ekind The engine kind used to create partition.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_create_with_op(
|
||||
dnnl_graph_partition_t *partition, const_dnnl_graph_op_t op,
|
||||
dnnl_engine_kind_t ekind);
|
||||
|
||||
/// Destroys a partition.
|
||||
///
|
||||
/// @param partition The partition to be destroyed.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_destroy(
|
||||
dnnl_graph_partition_t partition);
|
||||
|
||||
/// Returns the number of operations in a partition.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param num Output the number of operations.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_get_op_num(
|
||||
const_dnnl_graph_partition_t partition, size_t *num);
|
||||
|
||||
/// Returns the list of op IDs of the partition.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param num The number of ops.
|
||||
/// @param ids Output the op IDs.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_get_ops(
|
||||
dnnl_graph_partition_t partition, size_t num, size_t *ids);
|
||||
|
||||
/// Returns the ID of a partition.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param id Output the ID of the partition.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_get_id(
|
||||
const_dnnl_graph_partition_t partition, size_t *id);
|
||||
|
||||
/// Compiles a partition with given input and output logical tensors. The output
|
||||
/// logical tensors can contain unknown dimensions. For this case, the
|
||||
/// compilation will deduce the output shapes according to input shapes. The
|
||||
/// output logical tensors can also have layout type `any`. The compilation will
|
||||
/// choose the optimal layout for output tensors. The optimal layout will be
|
||||
/// represented as an opaque layout ID saved in the output logical tensor.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param compiled_partition Output compiled partition.
|
||||
/// @param in_num The number of input logical tensors.
|
||||
/// @param inputs A list of input logical tensors.
|
||||
/// @param out_num The number of output logical tensors.
|
||||
/// @param outputs A list of output logical tensors.
|
||||
/// @param engine The target engine of the compilation.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_compile(
|
||||
dnnl_graph_partition_t partition,
|
||||
dnnl_graph_compiled_partition_t compiled_partition, size_t in_num,
|
||||
const dnnl_graph_logical_tensor_t **inputs, size_t out_num,
|
||||
const dnnl_graph_logical_tensor_t **outputs, dnnl_engine_t engine);
|
||||
|
||||
/// Returns the number of input logical tensors of a partition.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param num Output the number of input logical tensors.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_get_input_ports_num(
|
||||
const_dnnl_graph_partition_t partition, size_t *num);
|
||||
|
||||
/// Returns a list of input logical tensors from a partition.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param num The number of input logical tensors.
|
||||
/// @param inputs The list of input logical tensors.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_get_input_ports(
|
||||
const_dnnl_graph_partition_t partition, size_t num,
|
||||
dnnl_graph_logical_tensor_t *inputs);
|
||||
|
||||
/// Returns the number of output logical tensors of a partition.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param num Output the number of output logical tensors.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_get_output_ports_num(
|
||||
const_dnnl_graph_partition_t partition, size_t *num);
|
||||
|
||||
/// Returns a list of output logical tensors from a partition.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param num The number of output logical tensors.
|
||||
/// @param outputs The list of output logical tensors.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_get_output_ports(
|
||||
const_dnnl_graph_partition_t partition, size_t num,
|
||||
dnnl_graph_logical_tensor_t *outputs);
|
||||
|
||||
/// Returns the supporting status of a partition. Some operations may not be
|
||||
/// supported by the library under certain circumstances. During partitioning
|
||||
/// stage, unsupported partitions will be returned to users with each containing
|
||||
/// an unsupported operation. Users should check the supporting status of a
|
||||
/// partition before transforming the computation graph or compiling the
|
||||
/// partition.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param is_supported Output flag to indicate the supporting status. 0 means
|
||||
/// unsupported while 1 means supported.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_is_supported(
|
||||
const_dnnl_graph_partition_t partition, uint8_t *is_supported);
|
||||
|
||||
/// Returns the engine kind of a partition.
|
||||
///
|
||||
/// @param partition The target partition.
|
||||
/// @param kind The output engine kind.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_partition_get_engine_kind(
|
||||
const_dnnl_graph_partition_t partition, dnnl_engine_kind_t *kind);
|
||||
|
||||
/// @} dnnl_graph_api_partition
|
||||
|
||||
/// @addtogroup dnnl_graph_api_compiled_partition
|
||||
/// @{
|
||||
|
||||
/// Creates a new compiled partition handle.
|
||||
///
|
||||
/// @param compiled_partition The handle of output compiled partition.
|
||||
/// @param partition The handle of input partition.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_compiled_partition_create(
|
||||
dnnl_graph_compiled_partition_t *compiled_partition,
|
||||
dnnl_graph_partition_t partition);
|
||||
|
||||
/// Executes a compiled partition.
|
||||
///
|
||||
/// @param compiled_partition The handle of target compiled partition.
|
||||
/// @param stream The stream used for execution.
|
||||
/// @param num_inputs The number of input tensors.
|
||||
/// @param inputs A list of input tensors.
|
||||
/// @param num_outputs The number of output tensors.
|
||||
/// @param outputs A non-empty list of output tensors.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_compiled_partition_execute(
|
||||
const_dnnl_graph_compiled_partition_t compiled_partition,
|
||||
dnnl_stream_t stream, size_t num_inputs,
|
||||
const_dnnl_graph_tensor_t *inputs, size_t num_outputs,
|
||||
const_dnnl_graph_tensor_t *outputs);
|
||||
|
||||
/// Destroys a compiled partition.
|
||||
///
|
||||
/// @param compiled_partition The compiled partition to be destroyed.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_compiled_partition_destroy(
|
||||
dnnl_graph_compiled_partition_t compiled_partition);
|
||||
|
||||
/// Queries an input or output logical tensor according to tensor ID. If the
|
||||
/// tensor ID doesn't belong to any input or output of the compiled partition,
|
||||
/// an error status #dnnl_invalid_arguments will be returned by the API.
|
||||
///
|
||||
/// @param compiled_partition The handle of target compiled_partition.
|
||||
/// @param tid The unique id of required tensor.
|
||||
/// @param lt The output logical tensor.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_compiled_partition_query_logical_tensor(
|
||||
const_dnnl_graph_compiled_partition_t compiled_partition, size_t tid,
|
||||
dnnl_graph_logical_tensor_t *lt);
|
||||
|
||||
/// Returns the hint of in-place pairs from a compiled partition. It indicates
|
||||
/// that an input and an output of the partition can share the same memory
|
||||
/// buffer for computation. In-place computation helps to reduce the memory
|
||||
/// footprint and improves cache locality. But since the library may not have a
|
||||
/// global view of user's application, it's possible that the tensor with
|
||||
/// `input_id` is used at other places in user's computation graph. In this
|
||||
/// case, the user should take the in-place pair as a hint and pass a different
|
||||
/// memory buffer for output tensor to avoid overwriting the input memory buffer
|
||||
/// which will probably cause unexpected incorrect results.
|
||||
///
|
||||
/// @param compiled_partition The handle of target compiled_partition.
|
||||
/// @param num_inplace_pairs The number of in-place pairs.
|
||||
/// @param inplace_pairs The handle of in-place pairs.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_compiled_partition_get_inplace_ports(
|
||||
const_dnnl_graph_compiled_partition_t compiled_partition,
|
||||
size_t *num_inplace_pairs,
|
||||
const dnnl_graph_inplace_pair_t **inplace_pairs);
|
||||
|
||||
/// @} dnnl_graph_api_compiled_partition
|
||||
|
||||
/// @addtogroup dnnl_graph_api_graph
|
||||
/// @{
|
||||
|
||||
/// Creates a new empty graph. A graph is associated to a specific engine kind.
|
||||
/// The partitions returned from the graph will inherit the engine kind of the
|
||||
/// graph.
|
||||
///
|
||||
/// @param graph The handle of output graph.
|
||||
/// @param engine_kind The target engine kind.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_create(
|
||||
dnnl_graph_graph_t *graph, dnnl_engine_kind_t engine_kind);
|
||||
|
||||
/// Creates a new empty graph with an engine kind and a floating-point math
|
||||
/// mode. All partitions returned from the graph will inherit the engine kind
|
||||
/// and floating-point math mode.
|
||||
///
|
||||
/// @param graph The handle of output graph.
|
||||
/// @param engine_kind The kind for engine.
|
||||
/// @param mode The floating-point math mode.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_create_with_fpmath_mode(
|
||||
dnnl_graph_graph_t *graph, dnnl_engine_kind_t engine_kind,
|
||||
dnnl_fpmath_mode_t mode);
|
||||
|
||||
/// Destroys a graph.
|
||||
///
|
||||
/// @param graph The graph to be destroyed.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_destroy(dnnl_graph_graph_t graph);
|
||||
|
||||
/// Set the floating point math mode for a graph.
|
||||
///
|
||||
/// @param graph The target graph.
|
||||
/// @param mode The floating-point math mode.
|
||||
/// @param apply_to_int The flag that controls whether to use floating-point
|
||||
/// arithmetic for integral operations.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_set_fpmath_mode(
|
||||
dnnl_graph_graph_t graph, dnnl_fpmath_mode_t mode, int apply_to_int);
|
||||
|
||||
/// Get the floating point math mode for a graph.
|
||||
///
|
||||
/// @param graph The target graph.
|
||||
/// @param mode The floating-point math mode.
|
||||
/// @param apply_to_int The flag that controls whether to use floating-point
|
||||
/// arithmetic for integral operations.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_get_fpmath_mode(
|
||||
dnnl_graph_graph_t graph, dnnl_fpmath_mode_t *mode, int *apply_to_int);
|
||||
|
||||
/// Adds an operation into a graph. The API will return failure if the operator
|
||||
/// has already been added to the graph or the operation cannot pass the schema
|
||||
/// check in the library (eg. input and output numbers and data types, the
|
||||
/// attributes of the operation, etc.).
|
||||
///
|
||||
/// @param graph The target graph.
|
||||
/// @param op The operation to be added.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_add_op(
|
||||
dnnl_graph_graph_t graph, dnnl_graph_op_t op);
|
||||
|
||||
/// Finalizes a graph. It means users have finished adding operations into the
|
||||
/// graph and the graph is ready for partitioning. Adding a new operation into a
|
||||
/// finalized graph will return failures. Similarly, partitioning on a
|
||||
/// un-finalized graph will also return failures.
|
||||
///
|
||||
/// @param graph The target graph to be finalized.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_finalize(dnnl_graph_graph_t graph);
|
||||
|
||||
/// Checks if a graph is finalized.
|
||||
///
|
||||
/// @param graph The target graph to be finalized.
|
||||
/// @param finalized Output the finalization status. 0 means then graph is not
|
||||
/// finalized. Other values means the graph is finalized.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_is_finalized(
|
||||
dnnl_graph_graph_t graph, uint8_t *finalized);
|
||||
|
||||
/// Filters a graph. Partitions will be claimed internally according to the
|
||||
/// capability of the library, the engine kind, and the policy.
|
||||
///
|
||||
/// @param graph The target graph.
|
||||
/// @param policy The partition policy.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_filter(
|
||||
dnnl_graph_graph_t graph, dnnl_graph_partition_policy_t policy);
|
||||
|
||||
/// Returns the number of partitions of a graph. The API should be called after
|
||||
/// a partition is already filtered. Otherwise, the output number is zero.
|
||||
///
|
||||
/// @param graph The graph.
|
||||
/// @param num Output the number of partitions.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_get_partition_num(
|
||||
const_dnnl_graph_graph_t graph, size_t *num);
|
||||
|
||||
/// Returns the partitions from a filtered graph. Output partition instances
|
||||
/// will be written into the parameter `partitions`. Users need to make sure
|
||||
/// `partitions` is valid and has enough space to accept the partition
|
||||
/// instances. Each output partition instance should be destroyed via
|
||||
/// #dnnl_graph_partition_destroy explicitly after use.
|
||||
///
|
||||
/// @param graph The target graph.
|
||||
/// @param num The number of partitions.
|
||||
/// @param partitions Output the partitions.
|
||||
/// @returns #dnnl_success on success or a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_graph_get_partitions(dnnl_graph_graph_t graph,
|
||||
size_t num, dnnl_graph_partition_t *partitions);
|
||||
|
||||
/// @} dnnl_graph_api_graph
|
||||
|
||||
/// @addtogroup dnnl_graph_api_compiled_partition_cache
|
||||
/// @{
|
||||
|
||||
/// Returns the number of compiled partitions that can be held in the compiled
|
||||
/// partition cache at the same time.
|
||||
///
|
||||
/// @param capacity Compiled partition cache capacity to query. Concurrently
|
||||
/// accessing @p capacity is safe.
|
||||
/// @returns #dnnl_invalid_arguments if the @p capacity value
|
||||
/// is invalid, and #dnnl_success on success.
|
||||
dnnl_status_t DNNL_API dnnl_graph_get_compiled_partition_cache_capacity(
|
||||
int *capacity);
|
||||
|
||||
/// Sets a number of compiled partitions that can be held in the compiled
|
||||
/// partition cache at the same time. The default capacity of compiled partition
|
||||
/// cache is 1024.
|
||||
///
|
||||
/// @param capacity Compiled partition cache capacity to set. The default cache
|
||||
/// capacity is 1024. If a new @p capacity is less than a number of compiled
|
||||
/// partition that the compiled partition cache already has, then the excess
|
||||
/// entries will be evicted. Setting the @p capacity to 0 clears the compiled
|
||||
/// partition cache and disables it. Concurrently modifying @p capacity is safe.
|
||||
/// @returns #dnnl_invalid_arguments if the @p capacity value
|
||||
/// is invalid, and #dnnl_success on success.
|
||||
dnnl_status_t DNNL_API dnnl_graph_set_compiled_partition_cache_capacity(
|
||||
int capacity);
|
||||
|
||||
/// @} dnnl_graph_api_compiled_partition_cache
|
||||
|
||||
/// @addtogroup dnnl_graph_api_constant_tensor_cache
|
||||
/// @{
|
||||
|
||||
/// Control the enabling or disabling of constant tensor cache. This API must
|
||||
/// be called once before compilation stage. By default, constant tensor cache is
|
||||
/// disabled in the library.
|
||||
///
|
||||
/// @param flag Set to positive value to enable the cache and set to 0 to
|
||||
/// disable the cache. Negative values are invalid.
|
||||
/// @returns #dnnl_invalid_arguments if the @p flag value is
|
||||
/// invalid, and #dnnl_success on success.
|
||||
/// @note This API is deprecated and will be removed in future release, please
|
||||
/// use the dnnl_graph_set_constant_tensor_cache_capacity API to disable
|
||||
/// constant tensor cache by setting it's capacity to zero.
|
||||
dnnl_status_t DNNL_API dnnl_graph_set_constant_tensor_cache(int flag);
|
||||
|
||||
/// Return the enabling or disabling status of constant tensor cache.
|
||||
///
|
||||
/// @param flag The constant tensor cache enabling status to query.
|
||||
/// @returns #dnnl_invalid_arguments if the @p flag value is
|
||||
/// nullptr, and #dnnl_success on success.
|
||||
/// @note This API is deprecated and will be removed in future release, please
|
||||
/// use the dnnl_graph_get_constant_tensor_cache_capacity API to check the
|
||||
/// enabling status by checking it's capacity.
|
||||
dnnl_status_t DNNL_API dnnl_graph_get_constant_tensor_cache(int *flag);
|
||||
|
||||
/// Control the capacity for the constant tensor cache that used for specific
|
||||
/// engine kind. This API is thread safe and can be called multiple times at
|
||||
/// runtime. The capacity is set to zero by default which means the cache is
|
||||
/// disabled. When calling this API, the corresponding cache will be flushed.
|
||||
/// Setting capacity to 0 means to clear all cached tensors and disable cache.
|
||||
/// Once the capacity limit is reached, no new tensors will be cached. If there
|
||||
/// are multiple devices for an engine kind, the capacity set here is for each
|
||||
/// device.
|
||||
///
|
||||
/// @param eng_kind The engine kind that the constant tensor cache used for.
|
||||
/// @param size The constant tensor cache capacity size to set.
|
||||
/// @returns #dnnl_invalid_arguments if the @p eng_kind value is invalid, and
|
||||
/// #dnnl_success on success.
|
||||
dnnl_status_t DNNL_API dnnl_graph_set_constant_tensor_cache_capacity(
|
||||
dnnl_engine_kind_t eng_kind, size_t size);
|
||||
|
||||
/// Return the current capacity of constant tensor cache.
|
||||
///
|
||||
/// @param eng_kind The engine kind that the constant tensor cache used for.
|
||||
/// @param size The constant tensor cache capacity size to query.
|
||||
/// @returns #dnnl_invalid_arguments if the @p eng_kind value is
|
||||
/// nullptr or the @p size is nullptr, and #dnnl_success on success.
|
||||
dnnl_status_t DNNL_API dnnl_graph_get_constant_tensor_cache_capacity(
|
||||
dnnl_engine_kind_t eng_kind, size_t *size);
|
||||
|
||||
/// @} dnnl_graph_api_constant_tensor_cache
|
||||
|
||||
/// @addtogroup dnnl_graph_api_dump_mode
|
||||
/// @{
|
||||
|
||||
/// Configures graph dump modes at runtime.
|
||||
///
|
||||
/// @note
|
||||
/// Enabling graph dump affects performance.
|
||||
/// This setting overrides the ONEDNN_GRAPH_DUMP environment variable.
|
||||
///
|
||||
/// @param modes Bitmask composed of values from #dnnl_graph_dump_mode_t.
|
||||
/// Accepted values:
|
||||
/// - #dnnl_graph_dump_mode_graph: dump the full graph prior to
|
||||
/// partitioning.
|
||||
/// - #dnnl_graph_dump_mode_subgraph: dump each partitioned subgraph.
|
||||
/// - #dnnl_graph_dump_mode_none: disable all graph dumping.
|
||||
///
|
||||
/// Bitmask combinations using bitwise operators are supported. For
|
||||
/// instance, `graph | subgraph` enables both modes, `none | graph`
|
||||
/// behaves like `graph`, and `none & graph` behaves like `none`.
|
||||
/// @returns #dnnl_invalid_arguments if the
|
||||
/// @p modes value contains unsupported bits or graph dump is disabled,
|
||||
/// and #dnnl_success on success.
|
||||
dnnl_status_t DNNL_API dnnl_graph_set_dump_mode(dnnl_graph_dump_mode_t modes);
|
||||
|
||||
/// @} dnnl_graph_api_dump_mode
|
||||
|
||||
/// @} dnnl_graph_api
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,149 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2024 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_GRAPH_OCL_H
|
||||
#define ONEAPI_DNNL_DNNL_GRAPH_OCL_H
|
||||
|
||||
#include "oneapi/dnnl/dnnl_graph.h"
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
#include <CL/cl.h>
|
||||
/// @endcond
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api_ocl_interop
|
||||
/// @{
|
||||
|
||||
/// Allocation call-back function interface for OpenCL. OpenCL allocator should
|
||||
/// be used for OpenCL GPU runtime. The call-back should return a USM device
|
||||
/// memory pointer.
|
||||
///
|
||||
/// @param size Memory size in bytes for requested allocation
|
||||
/// @param alignment The minimum alignment in bytes for the requested allocation
|
||||
/// @param device A valid OpenCL device used to allocate
|
||||
/// @param context A valid OpenCL context used to allocate
|
||||
/// @returns The memory address of the requested USM allocation.
|
||||
typedef void *(*dnnl_graph_ocl_allocate_f)(
|
||||
size_t size, size_t alignment, cl_device_id device, cl_context context);
|
||||
|
||||
/// Deallocation call-back function interface for OpenCL. OpenCL allocator
|
||||
/// should be used for OpenCL runtime. The call-back should deallocate a USM
|
||||
/// device memory returned by #dnnl_graph_ocl_allocate_f. The event should be
|
||||
/// completed before deallocate the USM.
|
||||
///
|
||||
/// @param buf The USM allocation to be released
|
||||
/// @param device A valid OpenCL device the USM associated with
|
||||
/// @param context A valid OpenCL context used to free the USM allocation
|
||||
/// @param event A event which the USM deallocation depends on
|
||||
typedef void (*dnnl_graph_ocl_deallocate_f)(
|
||||
void *buf, cl_device_id device, cl_context context, cl_event event);
|
||||
|
||||
/// Creates an allocator with the given allocation and deallocation call-back
|
||||
/// function pointers.
|
||||
///
|
||||
/// @param allocator Output allocator
|
||||
/// @param ocl_malloc A pointer to OpenCL malloc function
|
||||
/// @param ocl_free A pointer to OpenCL free function
|
||||
/// @returns #dnnl_success on success and a status describing the
|
||||
/// error otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_ocl_interop_allocator_create(
|
||||
dnnl_graph_allocator_t *allocator, dnnl_graph_ocl_allocate_f ocl_malloc,
|
||||
dnnl_graph_ocl_deallocate_f ocl_free);
|
||||
|
||||
/// This API is a supplement for existing oneDNN engine API:
|
||||
/// dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create(
|
||||
/// dnnl_engine_t *engine, cl_device_id device, cl_context context);
|
||||
///
|
||||
/// @param engine Output engine.
|
||||
/// @param device Underlying OpenCL device to use for the engine.
|
||||
/// @param context Underlying OpenCL context to use for the engine.
|
||||
/// @param alloc Underlying allocator to use for the engine.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_ocl_interop_make_engine_with_allocator(
|
||||
dnnl_engine_t *engine, cl_device_id device, cl_context context,
|
||||
const_dnnl_graph_allocator_t alloc);
|
||||
|
||||
/// This API is a supplement for existing oneDNN engine API:
|
||||
/// dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create_from_cache_blob(
|
||||
/// dnnl_engine_t *engine, cl_device_id device, cl_context context,
|
||||
/// size_t size, const uint8_t *cache_blob);
|
||||
///
|
||||
/// @param engine Output engine.
|
||||
/// @param device The OpenCL device that this engine will encapsulate.
|
||||
/// @param context The OpenCL context (containing the device) that this
|
||||
/// engine will use for all operations.
|
||||
/// @param alloc Underlying allocator to use for the engine.
|
||||
/// @param size Size of the cache blob in bytes.
|
||||
/// @param cache_blob Cache blob of size @p size.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API
|
||||
dnnl_graph_ocl_interop_make_engine_from_cache_blob_with_allocator(
|
||||
dnnl_engine_t *engine, cl_device_id device, cl_context context,
|
||||
const_dnnl_graph_allocator_t alloc, size_t size,
|
||||
const uint8_t *cache_blob);
|
||||
|
||||
/// Execute a compiled partition with OpenCL runtime.
|
||||
///
|
||||
/// @param compiled_partition The handle of target compiled_partition.
|
||||
/// @param stream The stream used for execution
|
||||
/// @param num_inputs The number of input tensors
|
||||
/// @param inputs A list of input tensors
|
||||
/// @param num_outputs The number of output tensors
|
||||
/// @param outputs A non-empty list of output tensors
|
||||
/// @param deps Optional handle of list with `cl_event` dependencies.
|
||||
/// @param ndeps Number of dependencies.
|
||||
/// @param return_event The handle of cl_event.
|
||||
/// @returns #dnnl_success on success and a status describing the
|
||||
/// error otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_ocl_interop_compiled_partition_execute(
|
||||
const_dnnl_graph_compiled_partition_t compiled_partition,
|
||||
dnnl_stream_t stream, size_t num_inputs,
|
||||
const_dnnl_graph_tensor_t *inputs, size_t num_outputs,
|
||||
const_dnnl_graph_tensor_t *outputs, const cl_event *deps, int ndeps,
|
||||
cl_event *return_event);
|
||||
|
||||
/// @} dnnl_graph_api_ocl_interop
|
||||
|
||||
/// @} dnnl_graph_api_interop
|
||||
|
||||
/// @} dnnl_graph_api
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2024 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// Graph OpenCL interop API
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_GRAPH_OCL_HPP
|
||||
#define ONEAPI_DNNL_DNNL_GRAPH_OCL_HPP
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
#include <vector>
|
||||
|
||||
#include <CL/cl.h>
|
||||
|
||||
#include "oneapi/dnnl/dnnl_graph.hpp"
|
||||
#include "oneapi/dnnl/dnnl_graph_ocl.h"
|
||||
#include "oneapi/dnnl/dnnl_ocl.hpp"
|
||||
/// @endcond
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
namespace dnnl {
|
||||
|
||||
/// @addtogroup dnnl_graph_api
|
||||
/// @{
|
||||
|
||||
namespace graph {
|
||||
|
||||
/// @addtogroup dnnl_graph_api_interop Runtime interoperability API
|
||||
/// API extensions to interact with the underlying run-time.
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api_ocl_interop OpenCL interoperability API
|
||||
/// API extensions to interact with the underlying OpenCL run-time.
|
||||
/// @{
|
||||
|
||||
/// OpenCL interoperability namespace
|
||||
namespace ocl_interop {
|
||||
|
||||
/// Constructs an allocator from OpenCL malloc and free function pointer. OpenCL
|
||||
/// allocator should be used for OpenCL GPU runtime. Currently, only device USM
|
||||
/// allocator is supported.
|
||||
///
|
||||
/// @param ocl_malloc The pointer to OpenCL malloc function
|
||||
/// @param ocl_free The pointer to OpenCL free function
|
||||
/// @returns Created allocator
|
||||
inline allocator make_allocator(dnnl_graph_ocl_allocate_f ocl_malloc,
|
||||
dnnl_graph_ocl_deallocate_f ocl_free) {
|
||||
dnnl_graph_allocator_t c_allocator = nullptr;
|
||||
error::wrap_c_api(dnnl_graph_ocl_interop_allocator_create(
|
||||
&c_allocator, ocl_malloc, ocl_free),
|
||||
"could not create allocator for opencl device");
|
||||
return allocator(c_allocator);
|
||||
}
|
||||
|
||||
/// Constructs an engine from an OpenCL device, an OpenCL context, and an
|
||||
/// allocator.
|
||||
///
|
||||
/// @param device A valid OpenCL device to construct the engine
|
||||
/// @param context A valid OpenCL context to construct the engine
|
||||
/// @param alloc An allocator to associate with the engine
|
||||
/// @returns Created engine
|
||||
inline engine make_engine_with_allocator(
|
||||
cl_device_id device, cl_context context, const allocator &alloc) {
|
||||
dnnl_engine_t c_engine;
|
||||
error::wrap_c_api(dnnl_graph_ocl_interop_make_engine_with_allocator(
|
||||
&c_engine, device, context, alloc.get()),
|
||||
"could not make an engine with allocator");
|
||||
return engine(c_engine);
|
||||
}
|
||||
|
||||
/// Constructs an engine from an OpenCL device, an OpenCL context, an
|
||||
/// allocator, and a serialized engine cache blob.
|
||||
///
|
||||
/// @param device A valid OpenCL device to construct the engine
|
||||
/// @param context A valid OpenCL context to construct the engine
|
||||
/// @param alloc An allocator to associate with the engine
|
||||
/// @param cache_blob Cache blob serialized beforehand
|
||||
/// @returns Created engine
|
||||
inline engine make_engine_with_allocator(cl_device_id device,
|
||||
cl_context context, const allocator &alloc,
|
||||
const std::vector<uint8_t> &cache_blob) {
|
||||
dnnl_engine_t c_engine;
|
||||
error::wrap_c_api(
|
||||
dnnl_graph_ocl_interop_make_engine_from_cache_blob_with_allocator(
|
||||
&c_engine, device, context, alloc.get(), cache_blob.size(),
|
||||
cache_blob.data()),
|
||||
"could not make an engine with allocator from cache blob");
|
||||
return engine(c_engine);
|
||||
}
|
||||
|
||||
/// Executes a compiled partition in a specified stream and returns a OpenCL
|
||||
/// event.
|
||||
///
|
||||
/// @param c_partition Compiled partition to execute.
|
||||
/// @param astream Stream object to run over
|
||||
/// @param inputs Arguments map.
|
||||
/// @param outputs Arguments map.
|
||||
/// @param deps Optional vector with `cl_event` dependencies.
|
||||
/// @returns Output event.
|
||||
inline cl_event execute(compiled_partition &c_partition, stream &astream,
|
||||
const std::vector<tensor> &inputs, std::vector<tensor> &outputs,
|
||||
const std::vector<cl_event> &deps = {}) {
|
||||
std::vector<const_dnnl_graph_tensor_t> c_inputs;
|
||||
c_inputs.reserve(inputs.size());
|
||||
for (auto &in : inputs) {
|
||||
c_inputs.push_back(in.get());
|
||||
}
|
||||
std::vector<const_dnnl_graph_tensor_t> c_outputs;
|
||||
c_outputs.reserve(outputs.size());
|
||||
for (auto &out : outputs) {
|
||||
c_outputs.push_back(out.get());
|
||||
}
|
||||
|
||||
const cl_event *c_deps = deps.empty() ? nullptr : deps.data();
|
||||
|
||||
cl_event ocl_event;
|
||||
error::wrap_c_api(
|
||||
dnnl_graph_ocl_interop_compiled_partition_execute(c_partition.get(),
|
||||
astream.get(), c_inputs.size(), c_inputs.data(),
|
||||
c_outputs.size(), c_outputs.data(), c_deps,
|
||||
(int)deps.size(), &ocl_event),
|
||||
"could not execute the compiled_partition on a specified opencl "
|
||||
"stream");
|
||||
return ocl_event;
|
||||
}
|
||||
|
||||
} // namespace ocl_interop
|
||||
|
||||
/// @} dnnl_graph_api_ocl_interop
|
||||
|
||||
/// @} dnnl_graph_api_interop
|
||||
|
||||
} // namespace graph
|
||||
|
||||
/// @} dnnl_graph_api
|
||||
|
||||
} // namespace dnnl
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,104 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_GRAPH_SYCL_H
|
||||
#define ONEAPI_DNNL_DNNL_GRAPH_SYCL_H
|
||||
|
||||
#include "oneapi/dnnl/dnnl_graph.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api_sycl_interop
|
||||
/// @{
|
||||
|
||||
/// Allocation call-back function interface for SYCL. SYCL allocator should be
|
||||
/// used for SYCL runtime and host allocator should be used for non-SYCL. The
|
||||
/// call-back should return a USM device memory pointer.
|
||||
typedef void *(*dnnl_graph_sycl_allocate_f)(
|
||||
size_t size, size_t alignment, const void *dev, const void *context);
|
||||
|
||||
/// Deallocation call-back function interface for SYCL. SYCL allocator should be
|
||||
/// used for SYCL runtime and host allocator should be used for non-SYCL. The
|
||||
/// call-back should deallocate a USM device memory returned by
|
||||
/// #dnnl_graph_sycl_allocate_f.
|
||||
typedef void (*dnnl_graph_sycl_deallocate_f)(
|
||||
void *buf, const void *dev, const void *context, void *event);
|
||||
|
||||
/// Creates an allocator with the given allocation and deallocation call-back
|
||||
/// function pointers.
|
||||
///
|
||||
/// @param allocator Output allocator
|
||||
/// @param sycl_malloc A pointer to SYCL malloc function
|
||||
/// @param sycl_free A pointer to SYCL free function
|
||||
/// @returns #dnnl_success on success and a status describing the
|
||||
/// error otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_sycl_interop_allocator_create(
|
||||
dnnl_graph_allocator_t *allocator,
|
||||
dnnl_graph_sycl_allocate_f sycl_malloc,
|
||||
dnnl_graph_sycl_deallocate_f sycl_free);
|
||||
|
||||
/// This API is a supplement for existing onednn engine API.
|
||||
dnnl_status_t DNNL_API dnnl_graph_sycl_interop_make_engine_with_allocator(
|
||||
dnnl_engine_t *engine, const void *device, const void *context,
|
||||
const_dnnl_graph_allocator_t alloc);
|
||||
|
||||
/// Execute a compiled partition with sycl runtime.
|
||||
///
|
||||
/// @param compiled_partition The handle of target compiled_partition.
|
||||
/// @param stream The stream used for execution
|
||||
/// @param num_inputs The number of input tensors
|
||||
/// @param inputs A list of input tensors
|
||||
/// @param num_outputs The number of output tensors
|
||||
/// @param outputs A non-empty list of output tensors
|
||||
/// @param deps Optional handle of list with `sycl::event` dependencies.
|
||||
/// @param sycl_event The handle of sycl event.
|
||||
/// @returns #dnnl_success on success and a status describing the
|
||||
/// error otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_graph_sycl_interop_compiled_partition_execute(
|
||||
const_dnnl_graph_compiled_partition_t compiled_partition,
|
||||
dnnl_stream_t stream, size_t num_inputs,
|
||||
const_dnnl_graph_tensor_t *inputs, size_t num_outputs,
|
||||
const_dnnl_graph_tensor_t *outputs, const void *deps, void *sycl_event);
|
||||
|
||||
/// @} dnnl_graph_api_sycl_interop
|
||||
|
||||
/// @} dnnl_graph_api_interop
|
||||
|
||||
/// @} dnnl_graph_api
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// Graph SYCL interop API
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_GRAPH_SYCL_HPP
|
||||
#define ONEAPI_DNNL_DNNL_GRAPH_SYCL_HPP
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
#include <vector>
|
||||
|
||||
#if __has_include(<sycl/sycl.hpp>)
|
||||
#include <sycl/sycl.hpp>
|
||||
#else
|
||||
#error "Unsupported compiler"
|
||||
#endif
|
||||
|
||||
#include "oneapi/dnnl/dnnl_graph.hpp"
|
||||
#include "oneapi/dnnl/dnnl_graph_sycl.h"
|
||||
/// @endcond
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
namespace dnnl {
|
||||
|
||||
/// @addtogroup dnnl_graph_api
|
||||
/// @{
|
||||
|
||||
namespace graph {
|
||||
|
||||
/// @addtogroup dnnl_graph_api_interop Runtime interoperability API
|
||||
/// API extensions to interact with the underlying run-time.
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api_sycl_interop SYCL interoperability API
|
||||
/// API extensions to interact with the underlying SYCL run-time.
|
||||
/// @{
|
||||
|
||||
/// SYCL interoperability namespace
|
||||
namespace sycl_interop {
|
||||
|
||||
/// Constructs an allocator from SYCL malloc and free function pointer. SYCL
|
||||
/// allocator should be used for SYCL runtime and host allocator should be used
|
||||
/// for non-SYCL. Currently, only device USM allocator is supported.
|
||||
///
|
||||
/// @param sycl_malloc The pointer to SYCL malloc function
|
||||
/// @param sycl_free The pointer to SYCL free function
|
||||
/// @returns Created allocator
|
||||
inline allocator make_allocator(dnnl_graph_sycl_allocate_f sycl_malloc,
|
||||
dnnl_graph_sycl_deallocate_f sycl_free) {
|
||||
dnnl_graph_allocator_t c_allocator = nullptr;
|
||||
error::wrap_c_api(dnnl_graph_sycl_interop_allocator_create(
|
||||
&c_allocator, sycl_malloc, sycl_free),
|
||||
"could not create allocator for sycl device");
|
||||
return allocator(c_allocator);
|
||||
}
|
||||
|
||||
inline engine make_engine_with_allocator(const sycl::device &adevice,
|
||||
const sycl::context &acontext, const allocator &alloc) {
|
||||
dnnl_engine_t c_engine;
|
||||
error::wrap_c_api(
|
||||
dnnl_graph_sycl_interop_make_engine_with_allocator(&c_engine,
|
||||
static_cast<const void *>(&adevice),
|
||||
static_cast<const void *>(&acontext), alloc.get()),
|
||||
"could not make an engine with allocator");
|
||||
return engine(c_engine);
|
||||
}
|
||||
|
||||
/// Executes a compiled partition in a specified stream and returns a SYCL
|
||||
/// event.
|
||||
///
|
||||
/// @param c_partition Compiled partition to execute.
|
||||
/// @param astream Stream object to run over
|
||||
/// @param inputs Arguments map.
|
||||
/// @param outputs Arguments map.
|
||||
/// @param deps Optional vector with `sycl::event` dependencies.
|
||||
/// @returns Output event.
|
||||
inline sycl::event execute(compiled_partition &c_partition, stream &astream,
|
||||
const std::vector<tensor> &inputs, std::vector<tensor> &outputs,
|
||||
const std::vector<sycl::event> &deps = {}) {
|
||||
std::vector<const_dnnl_graph_tensor_t> c_inputs;
|
||||
c_inputs.reserve(inputs.size());
|
||||
for (auto &in : inputs) {
|
||||
c_inputs.push_back(in.get());
|
||||
}
|
||||
std::vector<const_dnnl_graph_tensor_t> c_outputs;
|
||||
c_outputs.reserve(outputs.size());
|
||||
for (auto &out : outputs) {
|
||||
c_outputs.push_back(out.get());
|
||||
}
|
||||
|
||||
sycl::event sycl_event;
|
||||
error::wrap_c_api(dnnl_graph_sycl_interop_compiled_partition_execute(
|
||||
c_partition.get(), astream.get(), c_inputs.size(),
|
||||
c_inputs.data(), c_outputs.size(),
|
||||
c_outputs.data(), &deps, &sycl_event),
|
||||
"could not execute the compiled_partition on a specified sycl "
|
||||
"stream");
|
||||
return sycl_event;
|
||||
}
|
||||
|
||||
} // namespace sycl_interop
|
||||
|
||||
/// @} dnnl_graph_api_sycl_interop
|
||||
|
||||
/// @} dnnl_graph_api_interop
|
||||
|
||||
} // namespace graph
|
||||
|
||||
/// @} dnnl_graph_api
|
||||
|
||||
} // namespace dnnl
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
+503
@@ -0,0 +1,503 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// C API definitions
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_GRAPH_TYPES_H
|
||||
#define ONEAPI_DNNL_DNNL_GRAPH_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "oneapi/dnnl/dnnl_common_types.h"
|
||||
/// @endcond
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_graph_api_logical_tensor
|
||||
/// @{
|
||||
|
||||
/// A wildcard value for number of dimensions which is unknown at a tensor or
|
||||
/// operation creation time.
|
||||
#define DNNL_GRAPH_UNKNOWN_NDIMS -1
|
||||
|
||||
/// A wildcard value for dimensions that are unknown at a tensor or operation
|
||||
/// creation time.
|
||||
#define DNNL_GRAPH_UNKNOWN_DIM INT64_MIN
|
||||
|
||||
/// Layout type specification
|
||||
typedef enum {
|
||||
/// Undefined layout type
|
||||
dnnl_graph_layout_type_undef = 0,
|
||||
/// Any means to let the library to decide the layout for a tensor during
|
||||
/// partition compilation.
|
||||
dnnl_graph_layout_type_any = 1,
|
||||
/// Strided means that the layout of a tensor is determined by the strides
|
||||
/// field in the logical tensor.
|
||||
dnnl_graph_layout_type_strided = 2,
|
||||
/// Opaque means that the layout of a tensor is the library specific.
|
||||
/// Usually, an opaque layout is generated by a partition which is compiled
|
||||
/// with layout type any.
|
||||
dnnl_graph_layout_type_opaque = 3,
|
||||
} dnnl_graph_layout_type_t;
|
||||
|
||||
/// Logical tensor property
|
||||
typedef enum {
|
||||
/// Undefined tensor property
|
||||
dnnl_graph_tensor_property_undef = 0,
|
||||
/// Variable means the tensor may be changed during computation or between
|
||||
/// different iterations.
|
||||
dnnl_graph_tensor_property_variable = 1,
|
||||
/// Constant means the tensor will keep unchanged during computation and
|
||||
/// between different iterations. It's useful for the library to apply
|
||||
/// optimizations for constant tensors or cache constant tensors inside the
|
||||
/// library. For example, constant weight tensors in inference scenarios.
|
||||
dnnl_graph_tensor_property_constant = 2,
|
||||
/// Host scalar means the tensor will be a 0-D scalar tensor on host.
|
||||
/// It should be used with a CPU engine when creating the tensor.
|
||||
dnnl_graph_tensor_property_host_scalar = 3,
|
||||
} dnnl_graph_tensor_property_t;
|
||||
|
||||
/// Logical tensor. It is based on an ID, a number of dimensions, dimensions
|
||||
/// themselves, element data type, tensor property and tensor memory layout.
|
||||
typedef struct {
|
||||
/// Unique id of each logical tensor. The library uses logical tensor IDs to
|
||||
/// build up the connections between operations if the output of one
|
||||
/// operation has the same ID as the input of another operation.
|
||||
size_t id;
|
||||
|
||||
/// Number of dimensions. -1 means unknown (DNNL_GRAPH_UNKNOWN_NDIMS). 0 is
|
||||
/// used to define scalar tensor.
|
||||
int ndims;
|
||||
|
||||
/// Size of each dimension. #DNNL_GRAPH_UNKNOWN_DIM means the size of that
|
||||
/// dimension is unknown. 0 is used to define zero-dimension tensor. The
|
||||
/// library supports to deduce output shapes according to input shapes
|
||||
/// during compilation. Unlike memory descriptor in oneDNN primitive API,
|
||||
/// the order of dimensions is not defined in logical tensor. It is defined
|
||||
/// by the operations which respect the order through the attributes
|
||||
/// #dnnl_graph_op_attr_data_format or #dnnl_graph_op_attr_weights_format.
|
||||
/// For example, for a Convolution with `data_format=NXC`, it means the
|
||||
/// first element of dims of activation tensor is mini-batch size, the last
|
||||
/// effective element of dims is channel size, and other elements between
|
||||
/// them are spatial dimensions.
|
||||
dnnl_dims_t dims;
|
||||
|
||||
/// Data type of the tensor elements.
|
||||
dnnl_data_type_t data_type;
|
||||
|
||||
/// Property type of the tensor.
|
||||
dnnl_graph_tensor_property_t property;
|
||||
|
||||
/// Layout type of the tensor.
|
||||
dnnl_graph_layout_type_t layout_type;
|
||||
union {
|
||||
/// The field is valid when `layout_type` is
|
||||
/// #dnnl_graph_layout_type_strided. #DNNL_GRAPH_UNKNOWN_DIM means the
|
||||
/// stride of the dimension is unknown. The library currently doesn't
|
||||
/// support other negative stride values.
|
||||
dnnl_dims_t strides;
|
||||
|
||||
/// The field is valid when `layout_type` is
|
||||
/// #dnnl_graph_layout_type_opaque. An opaque layout ID is usually
|
||||
/// generated by a partition which is compiled with layout type any.
|
||||
size_t layout_id;
|
||||
} layout;
|
||||
} dnnl_graph_logical_tensor_t;
|
||||
|
||||
/// @} dnnl_graph_api_logical_tensor
|
||||
|
||||
/// @addtogroup dnnl_graph_api_partition
|
||||
/// @{
|
||||
|
||||
/// Policy specifications for partitioning
|
||||
typedef enum {
|
||||
/// Fusion policy returns partitions with typical post-op fusions, eg.
|
||||
/// Convolution + ReLU or other element-wise operations or a chian of
|
||||
/// post-ops.
|
||||
dnnl_graph_partition_policy_fusion = 1,
|
||||
/// Debug policy doesn't not apply any fusions. It returns partitions with
|
||||
/// single operation in each partition. The policy is useful when users
|
||||
/// notice any bug or correctness issue in fusion policy.
|
||||
dnnl_graph_partition_policy_debug = 2,
|
||||
} dnnl_graph_partition_policy_t;
|
||||
|
||||
/// An opaque structure to describe a partition.
|
||||
struct dnnl_graph_partition;
|
||||
|
||||
/// A partition handle.
|
||||
typedef struct dnnl_graph_partition *dnnl_graph_partition_t;
|
||||
|
||||
/// A constant partition handle.
|
||||
typedef const struct dnnl_graph_partition *const_dnnl_graph_partition_t;
|
||||
|
||||
/// @} dnnl_graph_api_partition
|
||||
|
||||
/// @addtogroup dnnl_graph_api_graph
|
||||
/// @{
|
||||
|
||||
/// An opaque structure to describe a graph.
|
||||
struct dnnl_graph_graph;
|
||||
|
||||
/// A graph handle.
|
||||
typedef struct dnnl_graph_graph *dnnl_graph_graph_t;
|
||||
|
||||
/// A constant graph handle.
|
||||
typedef const struct dnnl_graph_graph *const_dnnl_graph_graph_t;
|
||||
|
||||
/// @} dnnl_graph_api_graph
|
||||
|
||||
/// @addtogroup dnnl_graph_api_dump_mode
|
||||
/// @{
|
||||
|
||||
/// Dump mode bitmask for graph debugging utilities.
|
||||
typedef enum {
|
||||
/// Disable all graph dumps.
|
||||
dnnl_graph_dump_mode_none = 0x0U,
|
||||
/// Dump subgraphs extracted during partitioning.
|
||||
dnnl_graph_dump_mode_subgraph = 0x1U,
|
||||
/// Dump the full graph prior to partitioning.
|
||||
dnnl_graph_dump_mode_graph = 0x2U,
|
||||
} dnnl_graph_dump_mode_t;
|
||||
|
||||
/// @} dnnl_graph_api_dump_mode
|
||||
|
||||
/// @addtogroup dnnl_graph_api_op
|
||||
/// @{
|
||||
|
||||
/// Kinds of operations
|
||||
typedef enum {
|
||||
dnnl_graph_op_abs,
|
||||
dnnl_graph_op_abs_backward,
|
||||
dnnl_graph_op_add,
|
||||
dnnl_graph_op_avg_pool,
|
||||
dnnl_graph_op_avg_pool_backward,
|
||||
dnnl_graph_op_batch_norm_backward,
|
||||
dnnl_graph_op_batch_norm_forward_training,
|
||||
dnnl_graph_op_batch_norm_inference,
|
||||
dnnl_graph_op_bias_add,
|
||||
dnnl_graph_op_bias_add_backward,
|
||||
dnnl_graph_op_clamp,
|
||||
dnnl_graph_op_clamp_backward,
|
||||
dnnl_graph_op_concat,
|
||||
dnnl_graph_op_convolution,
|
||||
dnnl_graph_op_convolution_backward_data,
|
||||
dnnl_graph_op_convolution_backward_weights,
|
||||
dnnl_graph_op_conv_transpose,
|
||||
dnnl_graph_op_conv_transpose_backward_data,
|
||||
dnnl_graph_op_conv_transpose_backward_weights,
|
||||
dnnl_graph_op_dequantize,
|
||||
dnnl_graph_op_divide,
|
||||
dnnl_graph_op_dynamic_dequantize,
|
||||
dnnl_graph_op_dynamic_quantize,
|
||||
dnnl_graph_op_elu,
|
||||
dnnl_graph_op_elu_backward,
|
||||
dnnl_graph_op_end,
|
||||
dnnl_graph_op_exp,
|
||||
dnnl_graph_op_gelu,
|
||||
dnnl_graph_op_gelu_backward,
|
||||
dnnl_graph_op_hard_swish,
|
||||
dnnl_graph_op_hard_swish_backward,
|
||||
dnnl_graph_op_interpolate,
|
||||
dnnl_graph_op_interpolate_backward,
|
||||
dnnl_graph_op_layer_norm,
|
||||
dnnl_graph_op_layer_norm_backward,
|
||||
dnnl_graph_op_leaky_relu,
|
||||
dnnl_graph_op_log,
|
||||
dnnl_graph_op_log_softmax,
|
||||
dnnl_graph_op_log_softmax_backward,
|
||||
dnnl_graph_op_matmul,
|
||||
dnnl_graph_op_maximum,
|
||||
dnnl_graph_op_max_pool,
|
||||
dnnl_graph_op_max_pool_backward,
|
||||
dnnl_graph_op_minimum,
|
||||
dnnl_graph_op_mish,
|
||||
dnnl_graph_op_mish_backward,
|
||||
dnnl_graph_op_multiply,
|
||||
dnnl_graph_op_prelu,
|
||||
dnnl_graph_op_prelu_backward,
|
||||
dnnl_graph_op_quantize,
|
||||
dnnl_graph_op_reciprocal,
|
||||
dnnl_graph_op_reduce_l1,
|
||||
dnnl_graph_op_reduce_l2,
|
||||
dnnl_graph_op_reduce_max,
|
||||
dnnl_graph_op_reduce_mean,
|
||||
dnnl_graph_op_reduce_min,
|
||||
dnnl_graph_op_reduce_prod,
|
||||
dnnl_graph_op_reduce_sum,
|
||||
dnnl_graph_op_relu,
|
||||
dnnl_graph_op_relu_backward,
|
||||
dnnl_graph_op_reorder,
|
||||
dnnl_graph_op_round,
|
||||
dnnl_graph_op_sigmoid,
|
||||
dnnl_graph_op_sigmoid_backward,
|
||||
dnnl_graph_op_softmax,
|
||||
dnnl_graph_op_softmax_backward,
|
||||
dnnl_graph_op_softplus,
|
||||
dnnl_graph_op_softplus_backward,
|
||||
dnnl_graph_op_sqrt,
|
||||
dnnl_graph_op_sqrt_backward,
|
||||
dnnl_graph_op_square,
|
||||
dnnl_graph_op_squared_difference,
|
||||
dnnl_graph_op_static_reshape,
|
||||
dnnl_graph_op_static_transpose,
|
||||
dnnl_graph_op_subtract,
|
||||
dnnl_graph_op_tanh,
|
||||
dnnl_graph_op_tanh_backward,
|
||||
dnnl_graph_op_type_cast,
|
||||
dnnl_graph_op_wildcard,
|
||||
dnnl_graph_op_hard_sigmoid,
|
||||
dnnl_graph_op_hard_sigmoid_backward,
|
||||
dnnl_graph_op_select,
|
||||
dnnl_graph_op_pow,
|
||||
dnnl_graph_op_group_norm,
|
||||
dnnl_graph_op_gen_index,
|
||||
dnnl_graph_op_greater_equal,
|
||||
dnnl_graph_op_rms_norm,
|
||||
dnnl_graph_op_last_symbol,
|
||||
} dnnl_graph_op_kind_t;
|
||||
|
||||
/// Attributes of operations
|
||||
typedef enum {
|
||||
/// Undefined op attribute.
|
||||
dnnl_graph_op_attr_undef = 0,
|
||||
|
||||
// float32 attributes. The value of these attributes can be any single
|
||||
// float32 number.
|
||||
|
||||
/// Specifies an alpha attribute to an op.
|
||||
dnnl_graph_op_attr_alpha = 0x1,
|
||||
/// Specifies an beta attribute to an op.
|
||||
dnnl_graph_op_attr_beta,
|
||||
/// Specifies an epsilon attribute to an op.
|
||||
dnnl_graph_op_attr_epsilon,
|
||||
/// Specifies a max attribute to an op.
|
||||
dnnl_graph_op_attr_max,
|
||||
///Specifies a min attribute to an op.
|
||||
dnnl_graph_op_attr_min,
|
||||
/// Specifies a momentum attribute to an op.
|
||||
dnnl_graph_op_attr_momentum,
|
||||
|
||||
// float32 vector attributes. The value of these attributes can be a vector
|
||||
// of float32 numbers.
|
||||
|
||||
/// Specifies a scales attribute to an op.
|
||||
dnnl_graph_op_attr_scales = 0x20,
|
||||
|
||||
// int64_t attributes. The value of these attributes can be any single int64
|
||||
// number.
|
||||
|
||||
/// Specifies an axis attribute to an op.
|
||||
dnnl_graph_op_attr_axis = 0x30,
|
||||
/// Specifies a begin_norm_axis attribute to an op.
|
||||
dnnl_graph_op_attr_begin_norm_axis,
|
||||
/// Specifies a groups attribute to an op.
|
||||
dnnl_graph_op_attr_groups,
|
||||
|
||||
// int64_t vector attributes. The value of these attributes can be a vector
|
||||
// of int64 numbers.
|
||||
|
||||
/// Specifies an axes attribute to an op.
|
||||
dnnl_graph_op_attr_axes = 0x40,
|
||||
/// Specifies a dilations attribute to an op.
|
||||
dnnl_graph_op_attr_dilations,
|
||||
/// Specifies an dst_shape attribute to an op.
|
||||
dnnl_graph_op_attr_dst_shape,
|
||||
/// Specifies a kernel attribute to an op.
|
||||
dnnl_graph_op_attr_kernel,
|
||||
/// Specifies an order attribute to an op.
|
||||
dnnl_graph_op_attr_order,
|
||||
/// Specifies an output_padding attribute to an op.
|
||||
dnnl_graph_op_attr_output_padding,
|
||||
/// Specifies a pads_begin attribute to an op.
|
||||
dnnl_graph_op_attr_pads_begin,
|
||||
/// Specifies a pads_end attribute to an op.
|
||||
dnnl_graph_op_attr_pads_end,
|
||||
/// Specifies a shape attribute to an op.
|
||||
dnnl_graph_op_attr_shape,
|
||||
/// Specifies a sizes attribute to an op.
|
||||
dnnl_graph_op_attr_sizes,
|
||||
/// Specifies a input_shape attribute to an op.
|
||||
dnnl_graph_op_attr_src_shape,
|
||||
/// Specifies a strides attribute to an op.
|
||||
dnnl_graph_op_attr_strides,
|
||||
/// Specifies a weight_shape attribute to an op.
|
||||
dnnl_graph_op_attr_weights_shape,
|
||||
/// Specifies a zps attribute to an op.
|
||||
dnnl_graph_op_attr_zps,
|
||||
/// Specifies a group shape attribute to an op.
|
||||
dnnl_graph_op_attr_group_shape,
|
||||
|
||||
// bool attributes. The value of these attributes can be any single bool
|
||||
// value.
|
||||
|
||||
/// Specifies an exclude_pad attribute to an op.
|
||||
dnnl_graph_op_attr_exclude_pad = 0x60,
|
||||
/// Specifies a keep_dims attribute to an op.
|
||||
dnnl_graph_op_attr_keep_dims,
|
||||
/// Specifies a keep_stats attribute to an op.
|
||||
dnnl_graph_op_attr_keep_stats,
|
||||
/// Specifies a per_channel_broadcast attribute to an op.
|
||||
dnnl_graph_op_attr_per_channel_broadcast,
|
||||
/// Specifies a special_zero attribute to an op.
|
||||
dnnl_graph_op_attr_special_zero,
|
||||
/// Specifies a transpose_a attribute to an op.
|
||||
dnnl_graph_op_attr_transpose_a,
|
||||
/// Specifies a transpose_b attribute to an op.
|
||||
dnnl_graph_op_attr_transpose_b,
|
||||
/// Specifies an use_affine attribute to an op.
|
||||
dnnl_graph_op_attr_use_affine,
|
||||
/// Specifies an use_dst attribute to an op.
|
||||
dnnl_graph_op_attr_use_dst,
|
||||
|
||||
// string attributes. The value of these attributes can be a string.
|
||||
|
||||
/// Specifies an auto_broadcast attribute to an op. The value can be "none"
|
||||
/// or "numpy".
|
||||
dnnl_graph_op_attr_auto_broadcast = 0x80,
|
||||
/// Specifies an auto_pad attribute to an op. The value can be "none",
|
||||
/// "same_upper", "same_lower", or "valid".
|
||||
dnnl_graph_op_attr_auto_pad,
|
||||
/// Specifies an coordinate_transformation_mode attribute to an op. The
|
||||
/// value can be "half_pixel" or "align_corners". The attribute is defined
|
||||
/// for Interpolate operations.
|
||||
dnnl_graph_op_attr_coordinate_transformation_mode,
|
||||
/// Specifies a data_format of an op. The value can be "NCX" or "NXC".
|
||||
dnnl_graph_op_attr_data_format,
|
||||
/// Specifies a mode attribute of an op.
|
||||
/// Interpolate: "nearest", "linear", "bilinear", or "trilinear".
|
||||
/// SoftMax: "none", "inf_as_zero".
|
||||
/// GELU/GELUBackward: "gelu_erf", "gelu_tanh".
|
||||
dnnl_graph_op_attr_mode,
|
||||
/// Specifies a qtype attribute to an op. The value can be "per_channel" or
|
||||
/// "per_tensor". The attribute is defined for quantization operations.
|
||||
dnnl_graph_op_attr_qtype,
|
||||
/// Specifies a rounding_type attribute to an op. The value can be "ceil" or
|
||||
/// "floor".
|
||||
dnnl_graph_op_attr_rounding_type,
|
||||
/// Specifies a weights_format of an op. The value can be "OIX", "XIO",
|
||||
/// "IOX", or "XOI". Different operations may support different values.
|
||||
dnnl_graph_op_attr_weights_format,
|
||||
/// Specifies an accumulation_mode attribute to an op. The value can be
|
||||
/// "strict", "relaxed", "any", "f32", "s32", or "f16".
|
||||
dnnl_graph_op_attr_accumulation_mode,
|
||||
|
||||
/// Specifies the end of all above exteral attributes for check.
|
||||
dnnl_graph_op_attr_end = 0xFF,
|
||||
} dnnl_graph_op_attr_t;
|
||||
|
||||
/// An opaque structure to describe an operation.
|
||||
struct dnnl_graph_op;
|
||||
|
||||
/// An operation handle.
|
||||
typedef struct dnnl_graph_op *dnnl_graph_op_t;
|
||||
|
||||
/// A constant operation handle.
|
||||
typedef const struct dnnl_graph_op *const_dnnl_graph_op_t;
|
||||
|
||||
/// @} dnnl_graph_api_op
|
||||
|
||||
/// @addtogroup dnnl_graph_api_allocator
|
||||
/// @{
|
||||
|
||||
/// Allocation call-back function interface for host. For SYCL allocator, see
|
||||
/// #dnnl_graph_sycl_allocate_f.
|
||||
typedef void *(*dnnl_graph_host_allocate_f)(size_t size, size_t alignment);
|
||||
|
||||
/// Deallocation call-back function interface for host. For SYCL allocator, see
|
||||
/// #dnnl_graph_sycl_deallocate_f.
|
||||
typedef void (*dnnl_graph_host_deallocate_f)(void *);
|
||||
|
||||
/// An opaque structure to describe an allocator.
|
||||
struct dnnl_graph_allocator;
|
||||
|
||||
/// An allocator handle.
|
||||
typedef struct dnnl_graph_allocator *dnnl_graph_allocator_t;
|
||||
|
||||
/// A constant allocator handle.
|
||||
typedef const struct dnnl_graph_allocator *const_dnnl_graph_allocator_t;
|
||||
|
||||
/// @} dnnl_graph_api_allocator
|
||||
|
||||
/// @addtogroup dnnl_graph_api_compiled_partition
|
||||
/// @{
|
||||
|
||||
/// In-place pair definition. It can queried from a compiled partition
|
||||
/// indicating that an input and an output of the partition can share the same
|
||||
/// memory buffer for computation. In-place computation helps to reduce the
|
||||
/// memory footprint and improves cache locality. But since the library may not
|
||||
/// have a global view of user's application, it's possible that the tensor with
|
||||
/// `input_id` is used at other places in user's computation graph. In this
|
||||
/// case, the user should take the in-place pair as a hint and pass a different
|
||||
/// memory buffer for output tensor to avoid overwriting the input memory buffer
|
||||
/// which will probably cause unexpected incorrect results.
|
||||
typedef struct {
|
||||
/// The id of input tensor
|
||||
size_t input_id;
|
||||
|
||||
/// The id of output tensor
|
||||
size_t output_id;
|
||||
} dnnl_graph_inplace_pair_t;
|
||||
|
||||
/// An opaque structure to describe a compiled partition.
|
||||
struct dnnl_graph_compiled_partition;
|
||||
|
||||
/// A compiled partition handle.
|
||||
typedef struct dnnl_graph_compiled_partition *dnnl_graph_compiled_partition_t;
|
||||
|
||||
/// A constant compiled partition handle.
|
||||
typedef const struct dnnl_graph_compiled_partition
|
||||
*const_dnnl_graph_compiled_partition_t;
|
||||
|
||||
/// @} dnnl_graph_api_compiled_partition
|
||||
|
||||
/// @addtogroup dnnl_graph_api_tensor
|
||||
/// @{
|
||||
|
||||
/// An opaque structure to describe a tensor.
|
||||
struct dnnl_graph_tensor;
|
||||
|
||||
/// A tensor handle.
|
||||
typedef struct dnnl_graph_tensor *dnnl_graph_tensor_t;
|
||||
|
||||
/// A constant tensor handle.
|
||||
typedef const struct dnnl_graph_tensor *const_dnnl_graph_tensor_t;
|
||||
|
||||
/// @} dnnl_graph_api_tensor
|
||||
|
||||
/// @} dnnl_graph_api
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,273 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_OCL_H
|
||||
#define ONEAPI_DNNL_DNNL_OCL_H
|
||||
|
||||
#include "oneapi/dnnl/dnnl.h"
|
||||
|
||||
#include "oneapi/dnnl/dnnl_ocl_types.h"
|
||||
|
||||
#include <CL/cl.h>
|
||||
/// @endcond
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_ocl_interop
|
||||
/// @{
|
||||
|
||||
/// Creates a memory object.
|
||||
///
|
||||
/// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
|
||||
/// constructed memory object will have the underlying buffer set. In this
|
||||
/// case, the buffer will be initialized as if:
|
||||
/// - dnnl_memory_set_data_handle() has been called, if @p memory_kind is equal
|
||||
/// to dnnl_ocl_interop_usm, or
|
||||
/// - dnnl_ocl_interop_memory_set_mem_object() has been called, if @p memory_kind
|
||||
/// is equal to dnnl_ocl_interop_buffer.
|
||||
///
|
||||
/// @param memory Output memory object.
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param engine Engine to use.
|
||||
/// @param memory_kind Memory allocation kind to specify the type of handle.
|
||||
/// @param handle Handle of the memory buffer to use as an underlying storage.
|
||||
/// - A USM pointer to the user-allocated buffer. In this case the library
|
||||
/// doesn't own the buffer. Requires @p memory_kind to be equal to
|
||||
/// dnnl_ocl_interop_usm.
|
||||
/// - An OpenCL buffer. In this case the library doesn't own the buffer.
|
||||
/// Requires @p memory_kind be equal to be equal to dnnl_ocl_interop_buffer.
|
||||
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
|
||||
/// allocate the buffer that corresponds to the memory allocation kind
|
||||
/// @p memory_kind for the memory object. In this case the library
|
||||
/// owns the buffer.
|
||||
/// - The DNNL_MEMORY_NONE specific value. Instructs the library to
|
||||
/// create memory object without an underlying buffer.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_memory_create(dnnl_memory_t *memory,
|
||||
const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
|
||||
dnnl_ocl_interop_memory_kind_t memory_kind, void *handle);
|
||||
|
||||
/// Creates a memory object with multiple handles.
|
||||
///
|
||||
/// @param memory Output memory object.
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param engine Engine to use.
|
||||
/// @param memory_kind Memory allocation kind to specify the type of handles.
|
||||
/// @param nhandles Number of handles.
|
||||
/// @param handles Handles of the memory buffers to use as underlying storages.
|
||||
/// For each element of the @p handles array the following applies:
|
||||
/// - A USM pointer to the user-allocated buffer. In this case the library
|
||||
/// doesn't own the buffer. Requires @p memory_kind to be equal to
|
||||
/// dnnl_ocl_interop_usm.
|
||||
/// - An OpenCL buffer. In this case the library doesn't own the buffer.
|
||||
/// Requires @p memory_kind be equal to be equal to dnnl_ocl_interop_buffer.
|
||||
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
|
||||
/// allocate the buffer that corresponds to the memory allocation kind
|
||||
/// @p memory_kind for the memory object. In this case the library
|
||||
/// owns the buffer.
|
||||
/// - The DNNL_MEMORY_NONE specific value. Instructs the library to
|
||||
/// create memory object without an underlying buffer.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_memory_create_v2(dnnl_memory_t *memory,
|
||||
const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
|
||||
dnnl_ocl_interop_memory_kind_t memory_kind, int nhandles,
|
||||
void **handles);
|
||||
|
||||
/// Returns the memory allocation kind associated with a memory object.
|
||||
///
|
||||
/// @param memory Memory to query.
|
||||
/// @param memory_kind Output underlying memory allocation kind of the memory
|
||||
/// object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_memory_get_memory_kind(
|
||||
const_dnnl_memory_t memory,
|
||||
dnnl_ocl_interop_memory_kind_t *memory_kind);
|
||||
|
||||
/// Returns an OpenCL memory object associated with a memory object.
|
||||
///
|
||||
/// @param memory Memory object.
|
||||
/// @param mem_object Output OpenCL memory object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_memory_get_mem_object(
|
||||
const_dnnl_memory_t memory, cl_mem *mem_object);
|
||||
|
||||
/// Sets OpenCL memory object associated with a memory object.
|
||||
///
|
||||
/// For behavioral details, see dnnl_memory_set_data_handle().
|
||||
///
|
||||
/// @param memory Memory object.
|
||||
/// @param mem_object OpenCL memory object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_memory_set_mem_object(
|
||||
dnnl_memory_t memory, cl_mem mem_object);
|
||||
|
||||
/// Retrieves a cache blob ID for the OpenCL device.
|
||||
///
|
||||
/// @warning
|
||||
/// This API is intended to be used with
|
||||
/// #dnnl_ocl_interop_engine_get_cache_blob() and
|
||||
/// #dnnl_ocl_interop_engine_create_from_cache_blob(). The returned cache
|
||||
/// blob ID can only be used as an ID of the cache blob returned by
|
||||
/// #dnnl_ocl_interop_engine_get_cache_blob().
|
||||
///
|
||||
/// @note The cache blob ID can be empty (@p size will be 0 and
|
||||
/// @p cache_blob_id will be nullptr) if oneDNN doesn't have anything to
|
||||
/// put in the cache blob. (#dnnl_ocl_interop_engine_get_cache_blob will
|
||||
/// return an empty cache blob).
|
||||
///
|
||||
/// @param device An OpenCL device.
|
||||
/// @param size Size of the cache blob ID in bytes.
|
||||
/// @param cache_blob_id Cache blob id of size @p size. If
|
||||
/// the @p cache_blob_id is nullptr then the size of the cache blob ID is
|
||||
/// returned in @p size.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_engine_get_cache_blob_id(
|
||||
cl_device_id device, size_t *size, uint8_t *cache_blob_id);
|
||||
|
||||
/// Retrieves a cache blob associated with the given engine.
|
||||
///
|
||||
/// @note The cache blob can be empty (@p size will be 0 and @p cache_blob
|
||||
/// will be nullptr) if oneDNN doesn't have anything to put in the cache
|
||||
/// blob. It's the user's responsibility to check whether it's empty
|
||||
/// prior to passing it to
|
||||
/// #dnnl_ocl_interop_engine_create_from_cache_blob().
|
||||
///
|
||||
/// @param engine Engine to query for the cache blob.
|
||||
/// @param size Size of the cache blob in bytes.
|
||||
/// @param cache_blob Cache blob of size @p size. If the @p cache_blob is
|
||||
/// nullptr then the size of the cache blob is returned in @p size.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_engine_get_cache_blob(
|
||||
dnnl_engine_t engine, size_t *size, uint8_t *cache_blob);
|
||||
|
||||
/// Creates an engine from the given cache blob.
|
||||
///
|
||||
/// @param engine Output engine.
|
||||
/// @param device The OpenCL device that this engine will encapsulate.
|
||||
/// @param context The OpenCL context (containing the device) that this
|
||||
/// engine will use for all operations.
|
||||
/// @param size Size of the cache blob in bytes.
|
||||
/// @param cache_blob Cache blob of size @p size.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create_from_cache_blob(
|
||||
dnnl_engine_t *engine, cl_device_id device, cl_context context,
|
||||
size_t size, const uint8_t *cache_blob);
|
||||
|
||||
/// Creates an engine associated with an OpenCL device and an OpenCL context.
|
||||
///
|
||||
/// @param engine Output engine.
|
||||
/// @param device Underlying OpenCL device to use for the engine.
|
||||
/// @param context Underlying OpenCL context to use for the engine.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create(
|
||||
dnnl_engine_t *engine, cl_device_id device, cl_context context);
|
||||
|
||||
/// Returns the OpenCL context associated with an engine.
|
||||
///
|
||||
/// @param engine Engine to query.
|
||||
/// @param context Output underlying OpenCL context of the engine.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_engine_get_context(
|
||||
dnnl_engine_t engine, cl_context *context);
|
||||
|
||||
/// Returns the OpenCL device associated with an engine.
|
||||
///
|
||||
/// @param engine Engine to query.
|
||||
/// @param device Output underlying OpenCL device of the engine.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_get_device(
|
||||
dnnl_engine_t engine, cl_device_id *device);
|
||||
|
||||
/// Creates an execution stream for a given engine associated with
|
||||
/// an OpenCL command queue.
|
||||
///
|
||||
/// @param stream Output execution stream.
|
||||
/// @param engine Engine to create the execution stream on.
|
||||
/// @param queue OpenCL command queue to use.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_stream_create(
|
||||
dnnl_stream_t *stream, dnnl_engine_t engine, cl_command_queue queue);
|
||||
|
||||
/// Returns the OpenCL command queue associated with an execution stream.
|
||||
///
|
||||
/// @param stream Execution stream to query.
|
||||
/// @param queue Output OpenCL command queue.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_stream_get_command_queue(
|
||||
dnnl_stream_t stream, cl_command_queue *queue);
|
||||
|
||||
/// Executes computations specified by the primitive in a specified stream and
|
||||
/// returns an OpenCL event.
|
||||
///
|
||||
/// @param primitive Primitive to execute.
|
||||
/// @param stream Stream to use.
|
||||
/// @param nargs Number of arguments.
|
||||
/// @param args Array of arguments. Each argument is an
|
||||
/// <index, #dnnl_memory_t> pair. The index is one of the `DNNL_ARG_*`
|
||||
/// values such as `DNNL_ARG_SRC`. Unless runtime shapes are used (see
|
||||
/// #DNNL_RUNTIME_DIM_VAL), the memory object must have the same memory
|
||||
/// descriptor as that returned by
|
||||
/// #dnnl_primitive_desc_query_md(#dnnl_query_exec_arg_md, index).
|
||||
/// @param deps A pointer to a vector of size @p ndeps that contains
|
||||
/// dependencies.
|
||||
/// @param ndeps Number of dependencies.
|
||||
/// @param return_event Output event. It's the user's responsibility to
|
||||
/// manage lifetime of the event. Can be NULL. When @p stream is in-order
|
||||
/// NULL will be returned.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ocl_interop_primitive_execute(
|
||||
const_dnnl_primitive_t primitive, dnnl_stream_t stream, int nargs,
|
||||
const dnnl_exec_arg_t *args, const cl_event *deps, int ndeps,
|
||||
cl_event *return_event);
|
||||
|
||||
/// @} dnnl_api_ocl_interop
|
||||
|
||||
/// @} dnnl_api_interop
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,394 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_OCL_HPP
|
||||
#define ONEAPI_DNNL_DNNL_OCL_HPP
|
||||
|
||||
#include "oneapi/dnnl/dnnl.hpp"
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "oneapi/dnnl/dnnl_ocl.h"
|
||||
|
||||
#include <CL/cl.h>
|
||||
/// @endcond
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
namespace dnnl {
|
||||
|
||||
/// @addtogroup dnnl_api_interop Runtime interoperability API
|
||||
/// API extensions to interact with the underlying run-time.
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_ocl_interop OpenCL interoperability API
|
||||
/// API extensions to interact with the underlying OpenCL run-time.
|
||||
///
|
||||
/// @sa @ref dev_guide_opencl_interoperability in developer guide
|
||||
/// @{
|
||||
|
||||
/// OpenCL interoperability namespace
|
||||
namespace ocl_interop {
|
||||
|
||||
/// Memory allocation kind.
|
||||
enum class memory_kind {
|
||||
/// USM (device, shared, host, or unknown) memory allocation kind.
|
||||
usm = dnnl_ocl_interop_usm,
|
||||
/// Buffer memory allocation kind - default.
|
||||
buffer = dnnl_ocl_interop_buffer,
|
||||
};
|
||||
|
||||
/// Converts a memory allocation kind enum value from C++ API to C API type.
|
||||
///
|
||||
/// @param akind C++ API memory allocation kind enum value.
|
||||
/// @returns Corresponding C API memory allocation kind enum value.
|
||||
inline dnnl_ocl_interop_memory_kind_t convert_to_c(memory_kind akind) {
|
||||
return static_cast<dnnl_ocl_interop_memory_kind_t>(akind);
|
||||
}
|
||||
|
||||
/// Returns the cache blob ID of the OpenCL device.
|
||||
///
|
||||
/// @warning
|
||||
/// This API is intended to be used with
|
||||
/// #dnnl::ocl_interop::get_engine_cache_blob() and
|
||||
/// #dnnl::ocl_interop::make_engine(cl_device_id, cl_context, const std::vector<uint8_t> &).
|
||||
/// The returned cache blob ID can only be used as an ID of the cache blob
|
||||
/// returned by #dnnl::ocl_interop::get_engine_cache_blob().
|
||||
///
|
||||
/// @note The cache blob ID can be empty (@p size will be 0 and
|
||||
/// @p cache_blob_id will be nullptr) if oneDNN doesn't have anything to
|
||||
/// put in the cache blob. (#dnnl_ocl_interop_engine_get_cache_blob will
|
||||
/// return an empty cache blob).
|
||||
///
|
||||
/// @param device An OpenCL device.
|
||||
/// @returns A vector containing the cache blob ID.
|
||||
inline std::vector<uint8_t> get_engine_cache_blob_id(cl_device_id device) {
|
||||
size_t size = 0;
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_engine_get_cache_blob_id(device, &size, nullptr),
|
||||
"could not get an engine cache blob id size");
|
||||
|
||||
std::vector<uint8_t> cache_blob_id(size);
|
||||
error::wrap_c_api(dnnl_ocl_interop_engine_get_cache_blob_id(
|
||||
device, &size, cache_blob_id.data()),
|
||||
"could not get an engine cache blob id");
|
||||
return cache_blob_id;
|
||||
}
|
||||
|
||||
/// Returns a cache blob for the engine.
|
||||
///
|
||||
/// @note The cache blob vector can be empty if oneDNN doesn't have anything
|
||||
/// to put in the cache blob. It's the user's responsibility to check
|
||||
/// whether it's empty prior to passing it to
|
||||
/// #dnnl::ocl_interop::make_engine(cl_device_id, cl_context, const std::vector<uint8_t> &)
|
||||
///
|
||||
/// @param aengine Engine to query for the cache blob.
|
||||
/// @returns Vector containing the cache blob.
|
||||
inline std::vector<uint8_t> get_engine_cache_blob(const engine &aengine) {
|
||||
size_t size = 0;
|
||||
error::wrap_c_api(dnnl_ocl_interop_engine_get_cache_blob(
|
||||
aengine.get(), &size, nullptr),
|
||||
"could not get an engine cache blob size");
|
||||
|
||||
std::vector<uint8_t> cache_blob(size);
|
||||
error::wrap_c_api(dnnl_ocl_interop_engine_get_cache_blob(
|
||||
aengine.get(), &size, cache_blob.data()),
|
||||
"could not get an engine cache blob");
|
||||
return cache_blob;
|
||||
}
|
||||
|
||||
/// Constructs an engine from the given cache blob.
|
||||
///
|
||||
/// @param device The OpenCL device that this engine will encapsulate.
|
||||
/// @param context The OpenCL context (containing the device) that this
|
||||
/// engine will use for all operations.
|
||||
/// @param cache_blob Cache blob.
|
||||
/// @returns An engine.
|
||||
inline engine make_engine(cl_device_id device, cl_context context,
|
||||
const std::vector<uint8_t> &cache_blob) {
|
||||
dnnl_engine_t c_engine;
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_engine_create_from_cache_blob(&c_engine, device,
|
||||
context, cache_blob.size(), cache_blob.data()),
|
||||
"could not create an engine from cache blob");
|
||||
return engine(c_engine);
|
||||
}
|
||||
|
||||
/// Constructs an engine from OpenCL device and context objects.
|
||||
///
|
||||
/// @param device The OpenCL device that this engine will encapsulate.
|
||||
/// @param context The OpenCL context (containing the device) that this
|
||||
/// engine will use for all operations.
|
||||
/// @returns An engine.
|
||||
inline engine make_engine(cl_device_id device, cl_context context) {
|
||||
dnnl_engine_t c_engine;
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_engine_create(&c_engine, device, context),
|
||||
"could not create an engine");
|
||||
return engine(c_engine);
|
||||
}
|
||||
|
||||
/// Returns OpenCL context associated with the engine.
|
||||
///
|
||||
/// @param aengine An engine.
|
||||
/// @returns Underlying OpenCL context.
|
||||
inline cl_context get_context(const engine &aengine) {
|
||||
cl_context context = nullptr;
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_engine_get_context(aengine.get(), &context),
|
||||
"could not get an OpenCL context from an engine");
|
||||
return context;
|
||||
}
|
||||
|
||||
/// Returns OpenCL device associated with the engine.
|
||||
///
|
||||
/// @param aengine An engine.
|
||||
/// @returns Underlying OpenCL device.
|
||||
inline cl_device_id get_device(const engine &aengine) {
|
||||
cl_device_id device = nullptr;
|
||||
error::wrap_c_api(dnnl_ocl_interop_get_device(aengine.get(), &device),
|
||||
"could not get an OpenCL device from an engine");
|
||||
return device;
|
||||
}
|
||||
|
||||
/// Constructs an execution stream for the specified engine and OpenCL queue.
|
||||
///
|
||||
/// @param aengine Engine to create the stream on.
|
||||
/// @param queue OpenCL queue to use for the stream.
|
||||
/// @returns An execution stream.
|
||||
inline stream make_stream(const engine &aengine, cl_command_queue queue) {
|
||||
dnnl_stream_t c_stream;
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_stream_create(&c_stream, aengine.get(), queue),
|
||||
"could not create a stream");
|
||||
return stream(c_stream);
|
||||
}
|
||||
|
||||
/// Returns OpenCL queue object associated with the execution stream.
|
||||
///
|
||||
/// @param astream An execution stream.
|
||||
/// @returns Underlying OpenCL queue.
|
||||
inline cl_command_queue get_command_queue(const stream &astream) {
|
||||
cl_command_queue queue = nullptr;
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_stream_get_command_queue(astream.get(), &queue),
|
||||
"could not get an OpenCL command queue from a stream");
|
||||
return queue;
|
||||
}
|
||||
|
||||
/// Returns the OpenCL memory object associated with the memory object.
|
||||
///
|
||||
/// @param amemory A memory object.
|
||||
/// @returns Underlying OpenCL memory object.
|
||||
inline cl_mem get_mem_object(const memory &amemory) {
|
||||
cl_mem mem_object;
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_memory_get_mem_object(amemory.get(), &mem_object),
|
||||
"could not get OpenCL buffer object from a memory object");
|
||||
return mem_object;
|
||||
}
|
||||
|
||||
/// Sets the OpenCL memory object associated with the memory object.
|
||||
///
|
||||
/// For behavioral details see memory::set_data_handle().
|
||||
///
|
||||
/// @param amemory A memory object.
|
||||
/// @param mem_object OpenCL cl_mem object to use as the underlying
|
||||
/// storage. It must have at least get_desc().get_size() bytes
|
||||
/// allocated.
|
||||
inline void set_mem_object(memory &amemory, cl_mem mem_object) {
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_memory_set_mem_object(amemory.get(), mem_object),
|
||||
"could not set OpenCL buffer object from a memory object");
|
||||
}
|
||||
|
||||
/// Returns the memory allocation kind associated with a memory object.
|
||||
///
|
||||
/// @param amemory A memory object.
|
||||
///
|
||||
/// @returns The underlying memory allocation kind of the memory object.
|
||||
inline memory_kind get_memory_kind(const memory &amemory) {
|
||||
dnnl_ocl_interop_memory_kind_t ckind;
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_memory_get_memory_kind(amemory.get(), &ckind),
|
||||
"could not get memory kind");
|
||||
return static_cast<memory_kind>(ckind);
|
||||
}
|
||||
|
||||
/// Creates a memory object with multiple handles.
|
||||
///
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param aengine Engine to use.
|
||||
/// @param kind Memory allocation kind to specify the type of handles.
|
||||
/// @param handles Handles of the memory buffers to use as underlying storages.
|
||||
/// For each element of the @p handles array the following applies:
|
||||
/// - A USM pointer to the user-allocated buffer. In this case the library
|
||||
/// doesn't own the buffer. Requires @p memory_kind to be equal to
|
||||
/// dnnl_ocl_interop_usm.
|
||||
/// - An OpenCL buffer. In this case the library doesn't own the buffer.
|
||||
/// Requires @p memory_kind be equal to be equal to dnnl_ocl_interop_buffer.
|
||||
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
|
||||
/// allocate the buffer that corresponds to the memory allocation kind
|
||||
/// @p memory_kind for the memory object. In this case the library
|
||||
/// owns the buffer.
|
||||
/// - The DNNL_MEMORY_NONE specific value. Instructs the library to
|
||||
/// create memory object without an underlying buffer.
|
||||
///
|
||||
/// If the @p handles vector is not provided the library will allocate all
|
||||
/// buffers as if all handles have the special value DNNL_MEMORY_ALLOCATE.
|
||||
///
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
inline memory make_memory(const memory::desc &memory_desc,
|
||||
const engine &aengine, memory_kind kind,
|
||||
std::vector<void *> handles = {}) {
|
||||
if (handles.empty()) {
|
||||
const int nhandles = memory_desc.get_num_handles();
|
||||
handles.resize(nhandles, DNNL_MEMORY_ALLOCATE);
|
||||
}
|
||||
|
||||
dnnl_memory_t c_memory;
|
||||
error::wrap_c_api(
|
||||
dnnl_ocl_interop_memory_create_v2(&c_memory, memory_desc.get(),
|
||||
aengine.get(), convert_to_c(kind), (int)handles.size(),
|
||||
handles.data()),
|
||||
"could not create a memory");
|
||||
return memory(c_memory);
|
||||
}
|
||||
|
||||
/// Constructs a memory object with multiple OpenCL buffers.
|
||||
///
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param aengine Engine to use.
|
||||
/// @param mem_objects A vector of OpenCL buffers to use.
|
||||
///
|
||||
/// @returns Created memory object.
|
||||
inline memory make_memory(const memory::desc &memory_desc,
|
||||
const engine &aengine, std::vector<cl_mem> mem_objects) {
|
||||
const int nhandles = memory_desc.get_num_handles();
|
||||
std::vector<void *> handles(nhandles, DNNL_MEMORY_NONE);
|
||||
memory amemory(memory_desc, aengine, handles);
|
||||
for (int i = 0; i < nhandles; i++)
|
||||
amemory.set_data_handle(mem_objects[i], i);
|
||||
return amemory;
|
||||
}
|
||||
|
||||
/// Creates a memory object.
|
||||
///
|
||||
/// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
|
||||
/// constructed memory object will have the underlying buffer set. In this
|
||||
/// case, the buffer will be initialized as if:
|
||||
/// - dnnl::memory::set_data_handle() had been called, if @p memory_kind is
|
||||
/// equal to dnnl::ocl_interop::memory_kind::usm, or
|
||||
/// - dnnl::ocl_interop::set_mem_object() has been called, if @p memory_kind is
|
||||
/// equal to dnnl::ocl_interop::memory_kind::buffer.
|
||||
///
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param aengine Engine to use.
|
||||
/// @param kind Memory allocation kind to specify the type of handle.
|
||||
/// @param handle Handle of the memory buffer to use as an underlying storage.
|
||||
/// - A USM pointer to the user-allocated buffer. In this case the library
|
||||
/// doesn't own the buffer. Requires @p memory_kind to be equal to
|
||||
/// dnnl::ocl_interop::memory_kind::usm.
|
||||
/// - An OpenCL buffer. In this case the library doesn't own the buffer.
|
||||
/// Requires @p memory_kind be equal to be equal to
|
||||
/// dnnl::ocl_interop::memory_kind::buffer.
|
||||
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
|
||||
/// allocate the buffer that corresponds to the memory allocation kind
|
||||
/// @p memory_kind for the memory object. In this case the library
|
||||
/// owns the buffer.
|
||||
/// - The DNNL_MEMORY_NONE specific value. Instructs the library to
|
||||
/// create memory object without an underlying buffer.
|
||||
///
|
||||
/// @returns Created memory object.
|
||||
inline memory make_memory(const memory::desc &memory_desc,
|
||||
const engine &aengine, memory_kind kind, void *handle) {
|
||||
return make_memory(
|
||||
memory_desc, aengine, kind, std::vector<void *> {handle});
|
||||
}
|
||||
|
||||
/// Constructs a memory object from an OpenCL buffer.
|
||||
///
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param aengine Engine to use.
|
||||
/// @param mem_object An OpenCL buffer to use.
|
||||
///
|
||||
/// @returns Created memory object.
|
||||
inline memory make_memory(const memory::desc &memory_desc,
|
||||
const engine &aengine, cl_mem mem_object) {
|
||||
return make_memory(memory_desc, aengine, std::vector<cl_mem> {mem_object});
|
||||
}
|
||||
|
||||
/// Executes computations specified by the primitive in a specified stream and
|
||||
/// returns a SYCL event.
|
||||
///
|
||||
/// Arguments are passed via an arguments map containing
|
||||
/// <index, memory object> pairs. The index must be one of the `DNNL_ARG_*`
|
||||
/// values such as `DNNL_ARG_SRC`, and the memory must have a memory descriptor
|
||||
/// matching the one returned by
|
||||
/// #dnnl::primitive_desc::query_md(#query::exec_arg_md, index) unless using
|
||||
/// dynamic shapes (see #DNNL_RUNTIME_DIM_VAL).
|
||||
///
|
||||
/// @param aprimitive Primitive to execute.
|
||||
/// @param astream Stream object. The stream must belong to the same engine
|
||||
/// as the primitive.
|
||||
/// @param args Arguments map.
|
||||
/// @param deps Optional vector with `cl_event` dependencies.
|
||||
///
|
||||
/// @returns Output event. It's the user's responsibility to manage lifetime
|
||||
/// of the event.
|
||||
inline cl_event execute(const dnnl::primitive &aprimitive,
|
||||
const stream &astream, const std::unordered_map<int, memory> &args,
|
||||
const std::vector<cl_event> &deps = {}) {
|
||||
std::vector<dnnl_exec_arg_t> c_args;
|
||||
c_args.reserve(args.size());
|
||||
for (const auto &a : args)
|
||||
c_args.push_back({a.first, a.second.get()});
|
||||
|
||||
const cl_event *c_deps = deps.empty() ? nullptr : deps.data();
|
||||
|
||||
cl_event return_event;
|
||||
error::wrap_c_api(dnnl_ocl_interop_primitive_execute(aprimitive.get(),
|
||||
astream.get(), (int)c_args.size(), c_args.data(),
|
||||
c_deps, (int)deps.size(), &return_event),
|
||||
"could not execute a primitive");
|
||||
return return_event;
|
||||
}
|
||||
|
||||
} // namespace ocl_interop
|
||||
|
||||
/// @} dnnl_api_ocl_interop
|
||||
|
||||
/// @} dnnl_api_interop
|
||||
|
||||
} // namespace dnnl
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,56 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2021 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_OCL_TYPES_H
|
||||
#define ONEAPI_DNNL_DNNL_OCL_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_ocl_interop
|
||||
/// @{
|
||||
|
||||
/// Memory allocation kind.
|
||||
typedef enum {
|
||||
/// USM (device, shared, host, or unknown) memory allocation kind.
|
||||
dnnl_ocl_interop_usm,
|
||||
/// Buffer memory allocation kind - default.
|
||||
dnnl_ocl_interop_buffer,
|
||||
} dnnl_ocl_interop_memory_kind_t;
|
||||
|
||||
/// @} dnnl_api_ocl_interop
|
||||
|
||||
/// @} dnnl_api_interop
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,202 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_SYCL_H
|
||||
#define ONEAPI_DNNL_DNNL_SYCL_H
|
||||
|
||||
#include "oneapi/dnnl/dnnl.h"
|
||||
|
||||
#include "oneapi/dnnl/dnnl_sycl_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_sycl_interop
|
||||
/// @{
|
||||
|
||||
/// Creates an engine associated with a SYCL device and a SYCL context.
|
||||
///
|
||||
/// @param engine Output engine.
|
||||
/// @param device Pointer to the SYCL device to use for the engine.
|
||||
/// @param context Pointer to the SYCL context to use for the engine.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_engine_create(
|
||||
dnnl_engine_t *engine, const void *device, const void *context);
|
||||
|
||||
/// Returns the SYCL context associated with an engine.
|
||||
///
|
||||
/// @param engine Engine to query.
|
||||
/// @param context Pointer to the underlying SYCL context of the engine.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_engine_get_context(
|
||||
dnnl_engine_t engine, void **context);
|
||||
|
||||
/// Returns the SYCL device associated with an engine.
|
||||
///
|
||||
/// @param engine Engine to query.
|
||||
/// @param device Pointer to the underlying SYCL device of the engine.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_engine_get_device(
|
||||
dnnl_engine_t engine, void **device);
|
||||
|
||||
/// Creates a memory object.
|
||||
///
|
||||
/// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
|
||||
/// constructed memory object will have the underlying buffer set. In this
|
||||
/// case, the buffer will be initialized as if:
|
||||
/// - dnnl_memory_set_data_handle() had been called, if @p memory_kind is equal
|
||||
/// to dnnl_sycl_interop_usm, or
|
||||
/// - dnnl_sycl_interop_memory_set_buffer() has been called, if @p memory_kind
|
||||
/// is equal to dnnl_sycl_interop_buffer.
|
||||
///
|
||||
/// @param memory Output memory object.
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param engine Engine to use.
|
||||
/// @param memory_kind Memory allocation kind to specify the type of handle.
|
||||
/// @param handle Handle of the memory buffer to use as an underlying storage.
|
||||
/// - A USM pointer to the user-allocated buffer. In this case the library
|
||||
/// doesn't own the buffer. Requires @p memory_kind to be equal to
|
||||
/// dnnl_sycl_interop_usm.
|
||||
/// - A pointer to SYCL buffer. In this case the library doesn't own the
|
||||
/// buffer. Requires @p memory_kind be equal to be equal to
|
||||
/// dnnl_sycl_interop_buffer.
|
||||
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
|
||||
/// allocate the buffer that corresponds to the memory allocation kind
|
||||
/// @p memory_kind for the memory object. In this case the library
|
||||
/// owns the buffer.
|
||||
/// - The DNNL_MEMORY_NONE specific value. Instructs the library to
|
||||
/// create memory object without an underlying buffer.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_memory_create(dnnl_memory_t *memory,
|
||||
const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
|
||||
dnnl_sycl_interop_memory_kind_t memory_kind, void *handle);
|
||||
|
||||
/// Creates a memory object with multiple handles.
|
||||
///
|
||||
/// @param memory Output memory object.
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param engine Engine to use.
|
||||
/// @param memory_kind Memory allocation kind to specify the type of handles.
|
||||
/// @param nhandles Number of handles.
|
||||
/// @param handles Handles of the memory buffers to use as underlying storages.
|
||||
/// For each element of the @p handles array the following applies:
|
||||
/// - A USM pointer to the user-allocated buffer. In this case the library
|
||||
/// doesn't own the buffer. Requires @p memory_kind to be equal to
|
||||
/// dnnl_sycl_interop_usm.
|
||||
/// - A pointer to SYCL buffer. In this case the library doesn't own the
|
||||
/// buffer. Requires @p memory_kind be equal to be equal to
|
||||
/// dnnl_sycl_interop_buffer.
|
||||
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
|
||||
/// allocate the buffer that corresponds to the memory allocation kind
|
||||
/// @p memory_kind for the memory object. In this case the library
|
||||
/// owns the buffer.
|
||||
/// - The DNNL_MEMORY_NONE specific value. Instructs the library to
|
||||
/// create memory object without an underlying buffer.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_memory_create_v2(dnnl_memory_t *memory,
|
||||
const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
|
||||
dnnl_sycl_interop_memory_kind_t memory_kind, int nhandles,
|
||||
void **handles);
|
||||
|
||||
/// Returns the memory allocation kind associated with a memory object.
|
||||
///
|
||||
/// @param memory Memory to query.
|
||||
/// @param memory_kind Output underlying memory allocation kind of the memory
|
||||
/// object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_memory_get_memory_kind(
|
||||
const_dnnl_memory_t memory,
|
||||
dnnl_sycl_interop_memory_kind_t *memory_kind);
|
||||
|
||||
/// Sets a SYCL buffer for a memory object.
|
||||
///
|
||||
/// @param memory Memory object.
|
||||
/// @param buffer SYCL buffer to be set in the memory object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_memory_set_buffer(
|
||||
dnnl_memory_t memory, void *buffer);
|
||||
|
||||
/// Creates an execution stream for a given engine associated with a SYCL
|
||||
/// queue.
|
||||
///
|
||||
/// @param stream Output execution stream.
|
||||
/// @param engine Engine to create the execution stream on.
|
||||
/// @param queue SYCL queue to use.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_stream_create(
|
||||
dnnl_stream_t *stream, dnnl_engine_t engine, void *queue);
|
||||
|
||||
/// Returns the SYCL queue associated with an execution stream.
|
||||
///
|
||||
/// @param stream Execution stream to query.
|
||||
/// @param queue Output SYCL command queue.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_stream_get_queue(
|
||||
dnnl_stream_t stream, void **queue);
|
||||
|
||||
/// Executes computations specified by the primitive in a specified stream and
|
||||
/// returns a SYCL event.
|
||||
///
|
||||
/// @param primitive Primitive to execute.
|
||||
/// @param stream Stream to use.
|
||||
/// @param nargs Number of arguments.
|
||||
/// @param args Array of arguments. Each argument is an
|
||||
/// <index, #dnnl_memory_t> pair. The index is one of the `DNNL_ARG_*`
|
||||
/// values such as `DNNL_ARG_SRC`. Unless runtime shapes are used (see
|
||||
/// #DNNL_RUNTIME_DIM_VAL), the memory object must have the same memory
|
||||
/// descriptor as that returned by
|
||||
/// #dnnl_primitive_desc_query_md(#dnnl_query_exec_arg_md, index).
|
||||
/// @param deps A pointer to std::vector<sycl::event> that contains
|
||||
/// dependencies.
|
||||
/// @param return_event Output event.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_sycl_interop_primitive_execute(
|
||||
const_dnnl_primitive_t primitive, dnnl_stream_t stream, int nargs,
|
||||
const dnnl_exec_arg_t *args, const void *deps, void *return_event);
|
||||
|
||||
/// @} dnnl_api_sycl_interop
|
||||
|
||||
/// @} dnnl_api_interop
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,347 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_SYCL_HPP
|
||||
#define ONEAPI_DNNL_DNNL_SYCL_HPP
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#if __has_include(<sycl/sycl.hpp>)
|
||||
#include <sycl/sycl.hpp>
|
||||
#else
|
||||
#error "Unsupported compiler"
|
||||
#endif
|
||||
|
||||
#include "oneapi/dnnl/dnnl.hpp"
|
||||
#include "oneapi/dnnl/dnnl_sycl.h"
|
||||
|
||||
/// @endcond
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
namespace dnnl {
|
||||
|
||||
/// @addtogroup dnnl_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_sycl_interop SYCL interoperability API
|
||||
/// API extensions to interact with the underlying SYCL run-time.
|
||||
///
|
||||
/// @sa @ref dev_guide_dpcpp_interoperability in developer guide
|
||||
/// @{
|
||||
|
||||
/// SYCL interoperability namespace
|
||||
namespace sycl_interop {
|
||||
|
||||
/// Memory allocation kind.
|
||||
enum class memory_kind {
|
||||
/// USM (device, shared, host, or unknown) memory allocation kind - default.
|
||||
usm = dnnl_sycl_interop_usm,
|
||||
/// Buffer memory allocation kind.
|
||||
buffer = dnnl_sycl_interop_buffer,
|
||||
};
|
||||
|
||||
/// Converts a memory allocation kind enum value from C++ API to C API type.
|
||||
///
|
||||
/// @param akind C++ API memory allocation kind enum value.
|
||||
/// @returns Corresponding C API memory allocation kind enum value.
|
||||
inline dnnl_sycl_interop_memory_kind_t convert_to_c(memory_kind akind) {
|
||||
return static_cast<dnnl_sycl_interop_memory_kind_t>(akind);
|
||||
}
|
||||
|
||||
/// Constructs an engine from SYCL device and context objects.
|
||||
///
|
||||
/// @param adevice SYCL device.
|
||||
/// @param acontext SYCL context.
|
||||
///
|
||||
/// @returns Created engine.
|
||||
inline engine make_engine(
|
||||
const sycl::device &adevice, const sycl::context &acontext) {
|
||||
dnnl_engine_t aengine;
|
||||
error::wrap_c_api(dnnl_sycl_interop_engine_create(&aengine,
|
||||
static_cast<const void *>(&adevice),
|
||||
static_cast<const void *>(&acontext)),
|
||||
"could not create an engine");
|
||||
return engine(aengine);
|
||||
}
|
||||
|
||||
/// Returns the SYCL context associated with an engine.
|
||||
///
|
||||
/// @param aengine Engine to query.
|
||||
///
|
||||
/// @returns The underlying SYCL device of the engine.
|
||||
inline sycl::context get_context(const engine &aengine) {
|
||||
void *ctx_ptr;
|
||||
error::wrap_c_api(
|
||||
dnnl_sycl_interop_engine_get_context(aengine.get(), &ctx_ptr),
|
||||
"could not get a context handle");
|
||||
auto ctx = *static_cast<sycl::context *>(ctx_ptr);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/// Returns the SYCL device associated with an engine.
|
||||
///
|
||||
/// @param aengine Engine to query.
|
||||
///
|
||||
/// @returns The underlying SYCL context of the engine.
|
||||
inline sycl::device get_device(const engine &aengine) {
|
||||
void *dev_ptr;
|
||||
error::wrap_c_api(
|
||||
dnnl_sycl_interop_engine_get_device(aengine.get(), &dev_ptr),
|
||||
"could not get a device handle");
|
||||
auto dev = *static_cast<sycl::device *>(dev_ptr);
|
||||
return dev;
|
||||
}
|
||||
|
||||
/// Creates an execution stream for a given engine associated with a SYCL
|
||||
/// queue.
|
||||
///
|
||||
/// @param aengine Engine object to use for the stream.
|
||||
/// @param aqueue SYCL queue to use for the stream.
|
||||
///
|
||||
/// @returns An execution stream.
|
||||
inline stream make_stream(const engine &aengine, sycl::queue &aqueue) {
|
||||
dnnl_stream_t astream;
|
||||
error::wrap_c_api(
|
||||
dnnl_sycl_interop_stream_create(&astream, aengine.get(), &aqueue),
|
||||
"could not create a stream");
|
||||
return stream(astream);
|
||||
}
|
||||
|
||||
/// Returns the SYCL queue associated with an execution stream.
|
||||
///
|
||||
/// @param astream Execution stream to query.
|
||||
///
|
||||
/// @returns SYCL queue object.
|
||||
inline sycl::queue get_queue(const stream &astream) {
|
||||
void *queue_ptr;
|
||||
error::wrap_c_api(
|
||||
dnnl_sycl_interop_stream_get_queue(astream.get(), &queue_ptr),
|
||||
"could not get a stream handle");
|
||||
auto queue = *static_cast<sycl::queue *>(queue_ptr);
|
||||
return queue;
|
||||
}
|
||||
|
||||
/// Returns the SYCL buffer associated with a memory object.
|
||||
///
|
||||
/// Throws an exception if the memory allocation kind associated with the
|
||||
/// memory object is not equal to dnnl::sycl_interop::memory_kind::buffer.
|
||||
///
|
||||
/// @tparam T Type of the requested buffer.
|
||||
/// @tparam ndims Number of dimensions of the requested buffer.
|
||||
/// @param amemory Memory object.
|
||||
///
|
||||
/// @returns SYCL buffer associated with the memory object.
|
||||
template <typename T, int ndims = 1>
|
||||
sycl::buffer<T, ndims> get_buffer(const memory &amemory) {
|
||||
static_assert(ndims == 1, "only 1D buffers supported");
|
||||
|
||||
// XXX: workaround: when CPU runtime is not SYCL and amemory was created
|
||||
// for CPU engine `get_buffer` should return an error. Use interop API to
|
||||
// implement the check.
|
||||
dnnl_sycl_interop_memory_kind_t ckind;
|
||||
error::wrap_c_api(
|
||||
dnnl_sycl_interop_memory_get_memory_kind(amemory.get(), &ckind),
|
||||
"could not get SYCL buffer object");
|
||||
|
||||
void *handle_ptr;
|
||||
error::wrap_c_api(dnnl_memory_get_data_handle(amemory.get(), &handle_ptr),
|
||||
"could not get SYCL buffer object");
|
||||
|
||||
// XXX: workaround: zero-range buffer cannot be constructed.
|
||||
if (!handle_ptr) return sycl::buffer<T, ndims>(sycl::range<1>(1));
|
||||
|
||||
auto &buf_u8 = *static_cast<sycl::buffer<uint8_t, 1> *>(handle_ptr);
|
||||
|
||||
auto range = sycl::range<1>(buf_u8.byte_size() / sizeof(T));
|
||||
return buf_u8.reinterpret<T, 1>(range);
|
||||
}
|
||||
|
||||
/// Sets SYCL buffer associated with a memory object.
|
||||
///
|
||||
/// @tparam T Type of the buffer.
|
||||
/// @tparam ndims Number of dimensions of the buffer.
|
||||
/// @param amemory Memory object to change.
|
||||
/// @param abuffer SYCL buffer.
|
||||
template <typename T, int ndims>
|
||||
void set_buffer(memory &amemory, sycl::buffer<T, ndims> &abuffer) {
|
||||
auto range = sycl::range<1>(abuffer.byte_size());
|
||||
auto buf_u8 = abuffer.template reinterpret<uint8_t, 1>(range);
|
||||
error::wrap_c_api(dnnl_sycl_interop_memory_set_buffer(
|
||||
amemory.get(), static_cast<void *>(&buf_u8)),
|
||||
"could not set SYCL buffer object");
|
||||
}
|
||||
|
||||
/// Returns the memory allocation kind associated with a memory object.
|
||||
///
|
||||
/// @param amemory A memory object.
|
||||
///
|
||||
/// @returns The underlying memory allocation kind of the memory object.
|
||||
inline memory_kind get_memory_kind(const memory &amemory) {
|
||||
dnnl_sycl_interop_memory_kind_t ckind;
|
||||
error::wrap_c_api(
|
||||
dnnl_sycl_interop_memory_get_memory_kind(amemory.get(), &ckind),
|
||||
"could not get memory kind");
|
||||
return static_cast<memory_kind>(ckind);
|
||||
}
|
||||
|
||||
/// Creates a memory object with multiple handles.
|
||||
///
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param aengine Engine to use.
|
||||
/// @param kind Memory allocation kind to specify the type of handles.
|
||||
/// @param handles Handles of the memory buffers to use as underlying storages.
|
||||
/// For each element of the @p handles array the following applies:
|
||||
/// - A USM pointer to the user-allocated buffer. In this case the library
|
||||
/// doesn't own the buffer. Requires @p memory_kind to be equal to
|
||||
/// dnnl::sycl_interop::memory_kind::usm.
|
||||
/// - A pointer to SYCL buffer. In this case the library doesn't own the
|
||||
/// buffer. Requires @p memory_kind be equal to be equal to
|
||||
/// dnnl::sycl_interop::memory_kind::buffer.
|
||||
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
|
||||
/// allocate the buffer that corresponds to the memory allocation kind
|
||||
/// @p memory_kind for the memory object. In this case the library
|
||||
/// owns the buffer.
|
||||
/// - The DNNL_MEMORY_NONE specific value. Instructs the library to
|
||||
/// create memory object without an underlying buffer.
|
||||
///
|
||||
/// If the @p handles vector is not provided the library will allocate all
|
||||
/// buffers as if all handles have the special value DNNL_MEMORY_ALLOCATE.
|
||||
///
|
||||
/// @returns Created memory object.
|
||||
inline memory make_memory(const memory::desc &memory_desc,
|
||||
const engine &aengine, memory_kind kind,
|
||||
std::vector<void *> handles = {}) {
|
||||
if (handles.empty()) {
|
||||
const int nhandles = memory_desc.get_num_handles();
|
||||
handles.resize(nhandles, DNNL_MEMORY_ALLOCATE);
|
||||
}
|
||||
|
||||
dnnl_memory_t c_memory;
|
||||
error::wrap_c_api(
|
||||
dnnl_sycl_interop_memory_create_v2(&c_memory, memory_desc.get(),
|
||||
aengine.get(), convert_to_c(kind), (int)handles.size(),
|
||||
handles.data()),
|
||||
"could not create a memory");
|
||||
return memory(c_memory);
|
||||
}
|
||||
|
||||
/// Creates a memory object.
|
||||
///
|
||||
/// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
|
||||
/// constructed memory object will have the underlying buffer set. In this
|
||||
/// case, the buffer will be initialized as if:
|
||||
/// - dnnl::memory::set_data_handle() had been called, if @p memory_kind is
|
||||
/// equal to dnnl::sycl_interop::memory_kind::usm, or
|
||||
/// - dnnl::sycl_interop::set_buffer() has been called, if @p memory_kind is
|
||||
/// equal to dnnl::sycl_interop::memory_kind::buffer.
|
||||
///
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param aengine Engine to use.
|
||||
/// @param kind Memory allocation kind to specify the type of handle.
|
||||
/// @param handle Handle of the memory buffer to use as an underlying storage.
|
||||
/// - A USM pointer to the user-allocated buffer. In this case the library
|
||||
/// doesn't own the buffer. Requires @p memory_kind to be equal to
|
||||
/// dnnl::sycl_interop::memory_kind::usm.
|
||||
/// - A pointer to SYCL buffer. In this case the library doesn't own the
|
||||
/// buffer. Requires @p memory_kind be equal to be equal to
|
||||
/// dnnl::sycl_interop::memory_kind::buffer.
|
||||
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
|
||||
/// allocate the buffer that corresponds to the memory allocation kind
|
||||
/// @p memory_kind for the memory object. In this case the library
|
||||
/// owns the buffer.
|
||||
/// - The DNNL_MEMORY_NONE specific value. Instructs the library to
|
||||
/// create memory object without an underlying buffer.
|
||||
///
|
||||
/// @returns Created memory object.
|
||||
inline memory make_memory(const memory::desc &memory_desc,
|
||||
const engine &aengine, memory_kind kind, void *handle) {
|
||||
return make_memory(
|
||||
memory_desc, aengine, kind, std::vector<void *> {handle});
|
||||
}
|
||||
|
||||
/// Constructs a memory object from a SYCL buffer.
|
||||
///
|
||||
/// @param memory_desc Memory descriptor.
|
||||
/// @param aengine Engine to use.
|
||||
/// @param abuffer A SYCL buffer to use.
|
||||
///
|
||||
/// @returns Created memory object.
|
||||
template <typename T, int ndims = 1>
|
||||
memory make_memory(const memory::desc &memory_desc, const engine &aengine,
|
||||
sycl::buffer<T, ndims> &abuffer) {
|
||||
memory amemory(memory_desc, aengine, DNNL_MEMORY_NONE);
|
||||
set_buffer(amemory, abuffer);
|
||||
return amemory;
|
||||
}
|
||||
|
||||
/// Executes computations specified by the primitive in a specified stream and
|
||||
/// returns a SYCL event.
|
||||
///
|
||||
/// Arguments are passed via an arguments map containing
|
||||
/// <index, memory object> pairs. The index must be one of the `DNNL_ARG_*`
|
||||
/// values such as `DNNL_ARG_SRC`, and the memory must have a memory descriptor
|
||||
/// matching the one returned by
|
||||
/// #dnnl::primitive_desc::query_md(#query::exec_arg_md, index) unless using
|
||||
/// dynamic shapes (see #DNNL_RUNTIME_DIM_VAL).
|
||||
///
|
||||
/// @param aprimitive Primitive to execute.
|
||||
/// @param astream Stream object. The stream must belong to the same engine
|
||||
/// as the primitive.
|
||||
/// @param args Arguments map.
|
||||
/// @param deps Optional vector with `sycl::event` dependencies.
|
||||
///
|
||||
/// @returns Output event.
|
||||
inline sycl::event execute(const dnnl::primitive &aprimitive,
|
||||
const stream &astream, const std::unordered_map<int, memory> &args,
|
||||
const std::vector<sycl::event> &deps = {}) {
|
||||
std::vector<dnnl_exec_arg_t> c_args;
|
||||
c_args.reserve(args.size());
|
||||
for (const auto &a : args)
|
||||
c_args.push_back({a.first, a.second.get()});
|
||||
|
||||
sycl::event return_event;
|
||||
error::wrap_c_api(
|
||||
dnnl_sycl_interop_primitive_execute(aprimitive.get(), astream.get(),
|
||||
(int)c_args.size(), c_args.data(), &deps, &return_event),
|
||||
"could not execute a primitive");
|
||||
return return_event;
|
||||
}
|
||||
|
||||
} // namespace sycl_interop
|
||||
|
||||
/// @} dnnl_api_sycl_interop
|
||||
|
||||
/// @} dnnl_api_interop
|
||||
|
||||
} // namespace dnnl
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#endif // ONEAPI_DNNL_DNNL_SYCL_HPP
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,56 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_SYCL_TYPES_H
|
||||
#define ONEAPI_DNNL_DNNL_SYCL_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_sycl_interop
|
||||
/// @{
|
||||
|
||||
/// Memory allocation kind.
|
||||
typedef enum {
|
||||
/// USM (device, shared, host, or unknown) memory allocation kind - default.
|
||||
dnnl_sycl_interop_usm,
|
||||
/// Buffer memory allocation kind.
|
||||
dnnl_sycl_interop_buffer,
|
||||
} dnnl_sycl_interop_memory_kind_t;
|
||||
|
||||
/// @} dnnl_api_sycl_interop
|
||||
|
||||
/// @} dnnl_api_interop
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,123 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_THREADPOOL_H
|
||||
#define ONEAPI_DNNL_DNNL_THREADPOOL_H
|
||||
|
||||
#include "oneapi/dnnl/dnnl_config.h"
|
||||
#include "oneapi/dnnl/dnnl_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_threadpool_interop
|
||||
/// @{
|
||||
|
||||
/// Creates an execution stream with specified threadpool.
|
||||
///
|
||||
/// @sa @ref dev_guide_threadpool
|
||||
///
|
||||
/// @param stream Output execution stream.
|
||||
/// @param engine Engine to create the execution stream on.
|
||||
/// @param threadpool Pointer to an instance of a C++ class that implements
|
||||
/// dnnl::threapdool_iface interface.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_threadpool_interop_stream_create(
|
||||
dnnl_stream_t *stream, dnnl_engine_t engine, void *threadpool);
|
||||
|
||||
/// Returns a threadpool to be used by the execution stream.
|
||||
///
|
||||
/// @sa @ref dev_guide_threadpool
|
||||
///
|
||||
/// @param astream Execution stream.
|
||||
/// @param threadpool Output pointer to an instance of a C++ class that
|
||||
/// implements dnnl::threapdool_iface interface. Set to NULL if the
|
||||
/// stream was created without threadpool.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_threadpool_interop_stream_get_threadpool(
|
||||
dnnl_stream_t astream, void **threadpool);
|
||||
|
||||
/// Sets the maximum concurrency assumed by oneDNN when outside a
|
||||
/// parallel call.
|
||||
///
|
||||
/// @param max_concurrency The maximum concurrency assumed by oneDNN
|
||||
/// when outside a parallel call. This is a threadlocal setting.
|
||||
/// @returns #dnnl_success on success and a status describing the
|
||||
/// error otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_threadpool_interop_set_max_concurrency(
|
||||
int max_concurrency);
|
||||
|
||||
/// Gets the maximum concurrency assumed by oneDNN when outside a
|
||||
/// parallel call.
|
||||
///
|
||||
/// @param max_concurrency The maximum concurrency assumed by oneDNN
|
||||
/// when outside a parallel call. This is a threadlocal setting.
|
||||
/// @returns #dnnl_success on success and a status describing the
|
||||
/// error otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_threadpool_interop_get_max_concurrency(
|
||||
int *max_concurrency);
|
||||
|
||||
/// @copydoc dnnl_sgemm()
|
||||
/// @param threadpool A pointer to a threadpool interface (only when built with
|
||||
/// the THREADPOOL CPU runtime).
|
||||
dnnl_status_t DNNL_API dnnl_threadpool_interop_sgemm(char transa, char transb,
|
||||
dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K, float alpha, const float *A,
|
||||
dnnl_dim_t lda, const float *B, dnnl_dim_t ldb, float beta, float *C,
|
||||
dnnl_dim_t ldc, void *threadpool);
|
||||
|
||||
/// @copydoc dnnl_gemm_u8s8s32()
|
||||
/// @param threadpool A pointer to a threadpool interface (only when built with
|
||||
/// the THREADPOOL CPU runtime).
|
||||
dnnl_status_t DNNL_API dnnl_threadpool_interop_gemm_u8s8s32(char transa,
|
||||
char transb, char offsetc, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K,
|
||||
float alpha, const uint8_t *A, dnnl_dim_t lda, uint8_t ao,
|
||||
const int8_t *B, dnnl_dim_t ldb, int8_t bo, float beta, int32_t *C,
|
||||
dnnl_dim_t ldc, const int32_t *co, void *threadpool);
|
||||
|
||||
/// @copydoc dnnl_gemm_s8s8s32()
|
||||
/// @param threadpool A pointer to a threadpool interface (only when built with
|
||||
/// the THREADPOOL CPU runtime).
|
||||
dnnl_status_t DNNL_API dnnl_threadpool_interop_gemm_s8s8s32(char transa,
|
||||
char transb, char offsetc, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K,
|
||||
float alpha, const int8_t *A, dnnl_dim_t lda, int8_t ao,
|
||||
const int8_t *B, dnnl_dim_t ldb, int8_t bo, float beta, int32_t *C,
|
||||
dnnl_dim_t ldc, const int32_t *co, void *threadpool);
|
||||
|
||||
/// @} dnnl_api_threadpool_interop
|
||||
|
||||
/// @} dnnl_api_interop
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_THREADPOOL_HPP
|
||||
#define ONEAPI_DNNL_DNNL_THREADPOOL_HPP
|
||||
|
||||
#include "oneapi/dnnl/dnnl.hpp"
|
||||
#include "oneapi/dnnl/dnnl_threadpool.h"
|
||||
|
||||
#include "oneapi/dnnl/dnnl_threadpool_iface.hpp"
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
namespace dnnl {
|
||||
|
||||
/// @addtogroup dnnl_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_threadpool_interop Threadpool interoperability API
|
||||
/// API extensions to interact with the underlying Threadpool run-time.
|
||||
/// @{
|
||||
|
||||
/// Threadpool interoperability namespace
|
||||
namespace threadpool_interop {
|
||||
|
||||
/// Constructs an execution stream for the specified engine and threadpool.
|
||||
///
|
||||
/// @sa @ref dev_guide_threadpool
|
||||
///
|
||||
/// @param aengine Engine to create the stream on.
|
||||
/// @param threadpool Pointer to an instance of a C++ class that implements
|
||||
/// dnnl::threapdool_iface interface.
|
||||
/// @returns An execution stream.
|
||||
inline dnnl::stream make_stream(
|
||||
const dnnl::engine &aengine, threadpool_iface *threadpool) {
|
||||
dnnl_stream_t c_stream;
|
||||
dnnl::error::wrap_c_api(dnnl_threadpool_interop_stream_create(
|
||||
&c_stream, aengine.get(), threadpool),
|
||||
"could not create stream");
|
||||
return dnnl::stream(c_stream);
|
||||
}
|
||||
|
||||
/// Returns the pointer to a threadpool that is used by an execution stream.
|
||||
///
|
||||
/// @sa @ref dev_guide_threadpool
|
||||
///
|
||||
/// @param astream An execution stream.
|
||||
/// @returns Output pointer to an instance of a C++ class that implements
|
||||
/// dnnl::threapdool_iface interface or NULL if the stream was created
|
||||
/// without threadpool.
|
||||
inline threadpool_iface *get_threadpool(const dnnl::stream &astream) {
|
||||
void *tp;
|
||||
dnnl::error::wrap_c_api(
|
||||
dnnl_threadpool_interop_stream_get_threadpool(astream.get(), &tp),
|
||||
"could not get stream threadpool");
|
||||
return static_cast<threadpool_iface *>(tp);
|
||||
}
|
||||
|
||||
/// @copydoc dnnl_threadpool_interop_sgemm()
|
||||
inline status sgemm(char transa, char transb, dnnl_dim_t M, dnnl_dim_t N,
|
||||
dnnl_dim_t K, float alpha, const float *A, dnnl_dim_t lda,
|
||||
const float *B, dnnl_dim_t ldb, float beta, float *C, dnnl_dim_t ldc,
|
||||
threadpool_iface *threadpool) {
|
||||
return static_cast<status>(dnnl_threadpool_interop_sgemm(transa, transb, M,
|
||||
N, K, alpha, A, lda, B, ldb, beta, C, ldc, threadpool));
|
||||
}
|
||||
/// @copydoc dnnl_threadpool_interop_gemm_u8s8s32()
|
||||
inline status gemm_u8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M,
|
||||
dnnl_dim_t N, dnnl_dim_t K, float alpha, const uint8_t *A,
|
||||
dnnl_dim_t lda, uint8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo,
|
||||
float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co,
|
||||
threadpool_iface *threadpool) {
|
||||
return static_cast<status>(dnnl_threadpool_interop_gemm_u8s8s32(transa,
|
||||
transb, offsetc, M, N, K, alpha, A, lda, ao, B, ldb, bo, beta, C,
|
||||
ldc, co, threadpool));
|
||||
}
|
||||
|
||||
/// @copydoc dnnl_threadpool_interop_gemm_s8s8s32()
|
||||
inline status gemm_s8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M,
|
||||
dnnl_dim_t N, dnnl_dim_t K, float alpha, const int8_t *A,
|
||||
dnnl_dim_t lda, int8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo,
|
||||
float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co,
|
||||
threadpool_iface *threadpool) {
|
||||
return static_cast<status>(dnnl_threadpool_interop_gemm_s8s8s32(transa,
|
||||
transb, offsetc, M, N, K, alpha, A, lda, ao, B, ldb, bo, beta, C,
|
||||
ldc, co, threadpool));
|
||||
}
|
||||
|
||||
} // namespace threadpool_interop
|
||||
|
||||
/// @} dnnl_api_threadpool_interop
|
||||
|
||||
/// @} dnnl_api_interop
|
||||
|
||||
} // namespace dnnl
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2020 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// Threadpool Interoperability C++ Types
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_THREADPOOL_IFACE_HPP
|
||||
#define ONEAPI_DNNL_DNNL_THREADPOOL_IFACE_HPP
|
||||
// NOLINTBEGIN(readability-identifier-naming)
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
namespace dnnl {
|
||||
|
||||
/// @addtogroup dnnl_api_interop
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_threadpool_interop
|
||||
/// @{
|
||||
|
||||
namespace threadpool_interop {
|
||||
|
||||
/// Abstract threadpool interface. The users are expected to subclass this
|
||||
/// interface and pass an object to the library during CPU stream creation or
|
||||
/// directly in case of BLAS functions.
|
||||
struct threadpool_iface {
|
||||
/// Returns the number of worker threads.
|
||||
virtual int get_num_threads() const = 0;
|
||||
|
||||
/// Returns true if the calling thread belongs to this threadpool.
|
||||
virtual bool get_in_parallel() const = 0;
|
||||
|
||||
/// Submits n instances of a closure for execution in parallel:
|
||||
///
|
||||
/// for (int i = 0; i < n; i++) fn(i, n);
|
||||
///
|
||||
virtual void parallel_for(int n, const std::function<void(int, int)> &fn)
|
||||
= 0;
|
||||
|
||||
/// Returns threadpool behavior flags bit mask (see below).
|
||||
virtual uint64_t get_flags() const = 0;
|
||||
|
||||
// Does nothing if SYNCHRONOUS, waits for all jobs for ASYNCHRONOUS
|
||||
virtual void wait() = 0;
|
||||
|
||||
/// If set, parallel_for() returns immediately and oneDNN needs implement
|
||||
/// waiting for the submitted closures to finish execution on its own.
|
||||
static constexpr uint64_t ASYNCHRONOUS = 1;
|
||||
|
||||
virtual ~threadpool_iface() = default;
|
||||
};
|
||||
|
||||
} // namespace threadpool_interop
|
||||
|
||||
/// @} dnnl_api_threadpool_interop
|
||||
|
||||
/// @} dnnl_api_interop
|
||||
|
||||
} // namespace dnnl
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
// NOLINTEND(readability-identifier-naming)
|
||||
#endif /* ONEAPI_DNNL_DNNL_THREADPOOL_IFACE_HPP */
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,350 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2024 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// ukernel C API
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_UKERNEL_H
|
||||
#define ONEAPI_DNNL_DNNL_UKERNEL_H
|
||||
|
||||
#include "oneapi/dnnl/dnnl.h"
|
||||
#include "oneapi/dnnl/dnnl_ukernel_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel
|
||||
/// @{
|
||||
|
||||
#ifdef DNNL_EXPERIMENTAL_UKERNEL
|
||||
|
||||
/// Creates a ukernel attributes memory storage.
|
||||
///
|
||||
/// @param attr_params Output ukernel attributes memory storage.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ukernel_attr_params_create(
|
||||
dnnl_ukernel_attr_params_t *attr_params);
|
||||
|
||||
/// Sets post-operations arguments to a storage.
|
||||
///
|
||||
/// @param attr_params Memory pointers storage object.
|
||||
/// @param post_ops_args A pointer to pointers of post_ops storages. Expected to
|
||||
/// be packed together.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ukernel_attr_params_set_post_ops_args(
|
||||
dnnl_ukernel_attr_params_t attr_params, const void **post_ops_args);
|
||||
|
||||
/// Sets tensor A scales argument to a storage.
|
||||
///
|
||||
/// @param attr_params Memory pointers storage object.
|
||||
/// @param a_scales Pointer to the scales storage.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ukernel_attr_params_set_A_scales(
|
||||
dnnl_ukernel_attr_params_t attr_params, const void *a_scales);
|
||||
|
||||
/// Sets tensor B scales argument to a storage.
|
||||
///
|
||||
/// If `dnnl_brgemm_set_B_scales` used mask of 2, then at least N values of
|
||||
/// selected data type are expected.
|
||||
///
|
||||
/// @param attr_params Memory pointers storage object.
|
||||
/// @param b_scales Pointer to the scales storage.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ukernel_attr_params_set_B_scales(
|
||||
dnnl_ukernel_attr_params_t attr_params, const void *b_scales);
|
||||
|
||||
/// Sets tensor D scales argument to a storage.
|
||||
///
|
||||
/// @param attr_params Memory pointers storage object.
|
||||
/// @param d_scales Pointer to the scales storage.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ukernel_attr_params_set_D_scales(
|
||||
dnnl_ukernel_attr_params_t attr_params, const void *d_scales);
|
||||
|
||||
/// Destroys a ukernel attributes memory storage.
|
||||
///
|
||||
/// @param attr_params Memory pointers storage object to destroy.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_ukernel_attr_params_destroy(
|
||||
dnnl_ukernel_attr_params_t attr_params);
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel_brgemm
|
||||
/// @{
|
||||
|
||||
/// Creates a BRGeMM ukernel object. Operates by the following formula:
|
||||
/// `C = [A x B]`.
|
||||
///
|
||||
/// @param brgemm Output BRGeMM ukernel object.
|
||||
/// @param M Dimension M of tensor A.
|
||||
/// @param N Dimension N of tensor B.
|
||||
/// @param K Dimension K of tensors A and B.
|
||||
/// @param batch_size Number of batches to process.
|
||||
/// @param lda Leading dimension of tensor A.
|
||||
/// @param ldb Leading dimension of tensor B.
|
||||
/// @param ldc Leading dimension of tensor C.
|
||||
/// @param a_dt Data type of tensor A.
|
||||
/// @param b_dt Data type of tensor B.
|
||||
/// @param c_dt Data type of tensor C. Must be dnnl_f32.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_create(dnnl_brgemm_t *brgemm, dnnl_dim_t M,
|
||||
dnnl_dim_t N, dnnl_dim_t K, dnnl_dim_t batch_size, dnnl_dim_t lda,
|
||||
dnnl_dim_t ldb, dnnl_dim_t ldc, dnnl_data_type_t a_dt,
|
||||
dnnl_data_type_t b_dt, dnnl_data_type_t c_dt);
|
||||
|
||||
/// Sets adding an intermediate result to the output tensor C instead of
|
||||
/// writing: `C += [A x B]`.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @param add_C Value to indicate addition. Can be `0` to skip addition, and
|
||||
/// `1` to apply addition.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_set_add_C(dnnl_brgemm_t brgemm, int add_C);
|
||||
|
||||
/// Sets post-operations to a BRGeMM ukernel object: `D = post-operations(C)`.
|
||||
///
|
||||
/// Post-operations applies if one of the following holds:
|
||||
/// * Non-empty attributes are specified.
|
||||
/// * Output data type `d_dt` is different from accumulation data type `c_dt`.
|
||||
///
|
||||
/// If any of conditions happens, the final call of the accumulation chain
|
||||
/// must be `dnnl_brgemm_execute_postops`, and `dnnl_brgemm_execute`, otherwise.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @param ldd Leading dimension of tensor D.
|
||||
/// @param d_dt Data type of tensor D.
|
||||
/// @param post_ops Primitive post operations attribute to extend the kernel
|
||||
/// operations.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_set_post_ops(dnnl_brgemm_t brgemm,
|
||||
dnnl_dim_t ldd, dnnl_data_type_t d_dt, const_dnnl_post_ops_t post_ops);
|
||||
|
||||
/// Sets tensor A scales mask to a BRGeMM ukernel object.
|
||||
///
|
||||
/// For quantization flavor tensor A scales apply to accumulation buffer once C
|
||||
/// is ready.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @param a_scale_mask Tensor A scale mask. Can be `0` only.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_set_A_scales(
|
||||
dnnl_brgemm_t brgemm, int a_scale_mask);
|
||||
|
||||
/// Sets tensor B scales mask to a BRGeMM ukernel object.
|
||||
///
|
||||
/// For quantization flavor tensor B scales apply to accumulation buffer once C
|
||||
/// is ready.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @param b_scale_mask Tensor B scale mask. Can be `0` and `2` only.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_set_B_scales(
|
||||
dnnl_brgemm_t brgemm, int b_scale_mask);
|
||||
|
||||
/// Sets tensor D scales mask to a BRGeMM ukernel object.
|
||||
///
|
||||
/// For quantization flavor tensor D scales apply after all post-ops are
|
||||
/// applied.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @param d_scale_mask Tensor D scale mask. Can be `0` only.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_set_D_scales(
|
||||
dnnl_brgemm_t brgemm, int d_scale_mask);
|
||||
|
||||
/// Finalizes initialization of a BRGeMM ukernel object.
|
||||
///
|
||||
/// This step is mandatory to query information from the object.
|
||||
///
|
||||
/// @param brgemm Output BRGeMM ukernel object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_finalize(dnnl_brgemm_t brgemm);
|
||||
|
||||
/// Returns the packing type expected by a tensor B of a BRGeMM ukernel object.
|
||||
///
|
||||
/// @param pack_type Output packing type. Can be `dnnl_brgemm_pack_undef` when
|
||||
/// ukernel and transform are not supported on the target system,
|
||||
/// `dnnl_brgemm_no_trans` if packing is not required, and
|
||||
/// `dnnl_pack_type_pack32` for x64 backend, otherwise.
|
||||
/// @param a_dt Data type of tensor A.
|
||||
/// @param b_dt Data type of tensor B.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_get_B_pack_type(dnnl_pack_type_t *pack_type,
|
||||
dnnl_data_type_t a_dt, dnnl_data_type_t b_dt);
|
||||
|
||||
/// Returns the size of a scratchpad memory needed for the BRGeMM ukernel
|
||||
/// object.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @param size Output size of a buffer required for the BRGeMM ukernel object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_get_scratchpad_size(
|
||||
const_dnnl_brgemm_t brgemm, size_t *size);
|
||||
|
||||
/// Returns the flag indicating when the call to `dnnl_brgemm_execute_postops`
|
||||
/// is valid.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @param valid The flag indicating if `dnnl_brgemm_execute_postops` is valid
|
||||
/// for a given ukernel object. `1` is for valid and `0`, otherwise.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_is_execute_postops_valid(
|
||||
const_dnnl_brgemm_t brgemm, int *valid);
|
||||
|
||||
/// Initializes the hardware-specific context. If no initialization required,
|
||||
/// returns the success status.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_set_hw_context(const_dnnl_brgemm_t brgemm);
|
||||
|
||||
/// Releases the hardware-specific context. Must be used after all the execution
|
||||
/// calls to BRGeMM ukernel objects.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_release_hw_context();
|
||||
|
||||
/// Generates an executable part of BRGeMM ukernel object.
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_generate(dnnl_brgemm_t brgemm);
|
||||
|
||||
/// Executes a BRGeMM ukernel object.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @param A_ptr Base pointer to a tensor A.
|
||||
/// @param B_ptr Base pointer to a tensor B.
|
||||
/// @param A_B_offsets Pointer to the set of tensor A and tensor B offsets for
|
||||
/// each batch; the set must be contiguous in memory. Single batch should
|
||||
/// supply offsets for both tensors A and B simultaneously. The number of
|
||||
/// batches must coincide with the `batch_size` value passed at the creation
|
||||
/// stage.
|
||||
/// @param C_ptr Pointer to a tensor C (accumulation buffer).
|
||||
/// @param scratchpad_ptr Pointer to a scratchpad buffer.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_execute(const_dnnl_brgemm_t brgemm,
|
||||
const void *A_ptr, const void *B_ptr, const dnnl_dim_t *A_B_offsets,
|
||||
void *C_ptr, void *scratchpad_ptr);
|
||||
|
||||
/// Executes a BRGeMM ukernel object with post operations.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object.
|
||||
/// @param A Base pointer to a tensor A.
|
||||
/// @param B Base pointer to a tensor B.
|
||||
/// @param A_B_offsets Pointer to a set of tensor A and tensor B offsets for
|
||||
/// each batch. A set must be contiguous in memory. A single batch should
|
||||
/// supply offsets for both tensors A and B simultaneously. The number of
|
||||
/// batches must coincide with the `batch_size` value passed at the creation
|
||||
/// stage.
|
||||
/// @param C_ptr Pointer to a tensor C (accumulation buffer).
|
||||
/// @param D_ptr Pointer to a tensor D (output buffer).
|
||||
/// @param scratchpad_ptr Pointer to a scratchpad buffer.
|
||||
/// @param attr_params Ukernel attributes memory storage.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_execute_postops(const_dnnl_brgemm_t brgemm,
|
||||
const void *A, const void *B, const dnnl_dim_t *A_B_offsets,
|
||||
const void *C_ptr, void *D_ptr, void *scratchpad_ptr,
|
||||
const_dnnl_ukernel_attr_params_t attr_params);
|
||||
|
||||
/// Destroys a BRGeMM ukernel object.
|
||||
///
|
||||
/// @param brgemm BRGeMM ukernel object to destroy.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_brgemm_destroy(dnnl_brgemm_t brgemm);
|
||||
|
||||
/// @} dnnl_api_ukernel_brgemm
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel_transform
|
||||
/// @{
|
||||
|
||||
/// Creates a transform object.
|
||||
///
|
||||
/// @param transform Output transform object.
|
||||
/// @param K Dimension K.
|
||||
/// @param N Dimension N.
|
||||
/// @param in_pack_type Input packing type. Must be one of
|
||||
/// `dnnl_pack_type_no_trans`, or `dnnl_pack_type_trans`.
|
||||
/// @param in_ld Input leading dimension.
|
||||
/// @param out_ld Output leading dimension. When packing data, it specifies a
|
||||
/// block by N dimension.
|
||||
/// @param in_dt Input data type.
|
||||
/// @param out_dt Output data type.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_transform_create(dnnl_transform_t *transform,
|
||||
dnnl_dim_t K, dnnl_dim_t N, dnnl_pack_type_t in_pack_type,
|
||||
dnnl_dim_t in_ld, dnnl_dim_t out_ld, dnnl_data_type_t in_dt,
|
||||
dnnl_data_type_t out_dt);
|
||||
|
||||
/// Generates an executable part of transform object.
|
||||
/// @param transform Transform object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_transform_generate(dnnl_transform_t transform);
|
||||
|
||||
/// Executes a transform object.
|
||||
///
|
||||
/// @param transform Transform object.
|
||||
/// @param in_ptr Pointer to an input buffer.
|
||||
/// @param out_ptr Pointer to an output buffer.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_transform_execute(
|
||||
const_dnnl_transform_t transform, const void *in_ptr, void *out_ptr);
|
||||
|
||||
/// Destroys a transform object.
|
||||
///
|
||||
/// @param transform Transform object.
|
||||
/// @returns #dnnl_success on success and a status describing the error
|
||||
/// otherwise.
|
||||
dnnl_status_t DNNL_API dnnl_transform_destroy(dnnl_transform_t transform);
|
||||
|
||||
/// @} dnnl_api_ukernel_transform
|
||||
|
||||
#endif
|
||||
|
||||
/// @} dnnl_api_ukernel
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ONEAPI_DNNL_DNNL_UKERNEL_H */
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,478 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2024 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// ukernel C++ API
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_UKERNEL_HPP
|
||||
#define ONEAPI_DNNL_DNNL_UKERNEL_HPP
|
||||
// NOLINTBEGIN(readability-identifier-naming)
|
||||
|
||||
#include "oneapi/dnnl/dnnl.hpp"
|
||||
#include "oneapi/dnnl/dnnl_ukernel.h"
|
||||
|
||||
/// @addtogroup dnnl_api oneDNN API
|
||||
/// @{
|
||||
|
||||
/// oneDNN namespace
|
||||
namespace dnnl {
|
||||
|
||||
#ifdef DNNL_EXPERIMENTAL_UKERNEL
|
||||
|
||||
/// @addtogroup dnnl_api_utils
|
||||
/// @{
|
||||
|
||||
/// @cond DO_NOT_DOCUMENT_THIS
|
||||
|
||||
template <>
|
||||
struct handle_traits<dnnl_brgemm_t> {
|
||||
static dnnl_status_t destructor(dnnl_brgemm_t p) {
|
||||
return dnnl_brgemm_destroy(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct handle_traits<dnnl_transform_t> {
|
||||
static dnnl_status_t destructor(dnnl_transform_t p) {
|
||||
return dnnl_transform_destroy(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct handle_traits<dnnl_ukernel_attr_params_t> {
|
||||
static dnnl_status_t destructor(dnnl_ukernel_attr_params_t p) {
|
||||
return dnnl_ukernel_attr_params_destroy(p);
|
||||
}
|
||||
};
|
||||
|
||||
/// @endcond
|
||||
|
||||
/// @} dnnl_api_utils
|
||||
|
||||
#endif
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel Ukernels
|
||||
/// Collection of ukernels
|
||||
/// @{
|
||||
|
||||
/// ukernel namespace
|
||||
namespace ukernel {
|
||||
|
||||
#ifdef DNNL_EXPERIMENTAL_UKERNEL
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel_utils ukernel utils
|
||||
/// ukernel utility functions
|
||||
/// \ingroup dnnl_api_ukernel
|
||||
/// @{
|
||||
|
||||
/// Packing specification
|
||||
enum class pack_type {
|
||||
/// Undefined pack type. A guard value.
|
||||
undef = dnnl_pack_type_undef,
|
||||
/// Plain, not transposed layout. Similar to format_tag::ab.
|
||||
no_trans = dnnl_pack_type_no_trans,
|
||||
/// Plain, transposed layout. Similar to format_tag::ba.
|
||||
trans = dnnl_pack_type_trans,
|
||||
/// Packed by 32 bits along K dimension layout.
|
||||
pack32 = dnnl_pack_type_pack32,
|
||||
};
|
||||
|
||||
/// Ukernel attributes memory storage
|
||||
struct attr_params : public handle<dnnl_ukernel_attr_params_t> {
|
||||
/// Constructs a ukernel attributes memory storage.
|
||||
attr_params() {
|
||||
dnnl_ukernel_attr_params_t c_params = nullptr;
|
||||
dnnl_status_t status = dnnl_ukernel_attr_params_create(&c_params);
|
||||
error::wrap_c_api(
|
||||
status, "could not create an attributes memory storage");
|
||||
reset(c_params);
|
||||
}
|
||||
|
||||
/// Sets post-operations arguments to a storage.
|
||||
///
|
||||
/// @param post_ops_args Pointer to pointers of post_ops storages.
|
||||
/// Expected to be packed together.
|
||||
void set_post_ops_args(const void **post_ops_args) {
|
||||
dnnl_status_t status = dnnl_ukernel_attr_params_set_post_ops_args(
|
||||
get(), post_ops_args);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(
|
||||
status, "could not set post operations arguments");
|
||||
}
|
||||
|
||||
/// Sets tensor A scales arguments to a storage.
|
||||
///
|
||||
/// @param a_scales Pointer to scales storage.
|
||||
void set_A_scales(const void *a_scales) {
|
||||
dnnl_status_t status
|
||||
= dnnl_ukernel_attr_params_set_A_scales(get(), a_scales);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not set A scales argument");
|
||||
}
|
||||
|
||||
/// Sets tensor B scales arguments to a storage.
|
||||
///
|
||||
/// If @ref attr_params::set_B_scales used mask of 2, then at
|
||||
/// least N values of selected data type are expected.
|
||||
///
|
||||
/// @param b_scales Pointer to scales storage.
|
||||
void set_B_scales(const void *b_scales) {
|
||||
dnnl_status_t status
|
||||
= dnnl_ukernel_attr_params_set_B_scales(get(), b_scales);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not set B scales argument");
|
||||
}
|
||||
|
||||
/// Sets tensor D scales arguments to a storage.
|
||||
///
|
||||
/// @param d_scales Pointer to scales storage.
|
||||
void set_D_scales(const void *d_scales) {
|
||||
dnnl_status_t status
|
||||
= dnnl_ukernel_attr_params_set_D_scales(get(), d_scales);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not set D scales argument");
|
||||
}
|
||||
};
|
||||
/// @} dnnl_api_ukernel_utils
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel_brgemm BRGeMM ukernel
|
||||
/// BRGeMM ukernel routines
|
||||
/// @{
|
||||
|
||||
/// BRGeMM ukernel
|
||||
struct brgemm : public handle<dnnl_brgemm_t> {
|
||||
/// Default constructor. Produces an empty object.
|
||||
brgemm() = default;
|
||||
|
||||
/// Constructs a BRGeMM ukernel object. Operates by the following formula:
|
||||
/// `C = [A x B]`.
|
||||
///
|
||||
/// @param M Dimension M of tensor A.
|
||||
/// @param N Dimension N of tensor B.
|
||||
/// @param K Dimension K of tensors A and B.
|
||||
/// @param batch_size Number of batches to process.
|
||||
/// @param lda Leading dimension of tensor A.
|
||||
/// @param ldb Leading dimension of tensor B.
|
||||
/// @param ldc Leading dimension of tensor C.
|
||||
/// @param a_dt Data type of tensor A.
|
||||
/// @param b_dt Data type of tensor B.
|
||||
/// @param c_dt Data type of tensor C.
|
||||
/// @param allow_empty A flag signifying whether construction is
|
||||
/// allowed to fail without throwing an exception. In this case an
|
||||
/// empty object will be produced. This flag is optional and
|
||||
/// defaults to false.
|
||||
brgemm(memory::dim M, memory::dim N, memory::dim K, memory::dim batch_size,
|
||||
memory::dim lda, memory::dim ldb, memory::dim ldc,
|
||||
memory::data_type a_dt, memory::data_type b_dt,
|
||||
memory::data_type c_dt, bool allow_empty = false) {
|
||||
|
||||
dnnl_brgemm_t brgemm = nullptr;
|
||||
dnnl_status_t status = dnnl_brgemm_create(&brgemm, M, N, K, batch_size,
|
||||
lda, ldb, ldc, memory::convert_to_c(a_dt),
|
||||
memory::convert_to_c(b_dt), memory::convert_to_c(c_dt));
|
||||
|
||||
if (!allow_empty)
|
||||
error::wrap_c_api(
|
||||
status, "could not create a BRGeMM ukernel object");
|
||||
reset(brgemm);
|
||||
}
|
||||
|
||||
/// Sets adding an intermediate result to the output tensor C instead of
|
||||
/// writing: `C += [A x B]`.
|
||||
///
|
||||
/// @param add_C Value to indicate addition. `false` to skip addition, and
|
||||
/// `true` to apply addition.
|
||||
void set_add_C(bool add_C) {
|
||||
dnnl_status_t status
|
||||
= dnnl_brgemm_set_add_C(get(), static_cast<int>(add_C));
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not set add_C attribute");
|
||||
}
|
||||
|
||||
/// Sets post-operations to a BRGeMM ukernel object:
|
||||
/// `D = post-operations(C)`.
|
||||
///
|
||||
/// Post-operations applies if one of the following holds:
|
||||
/// * Non-empty post-operations are specified.
|
||||
/// * Output data type `d_dt` is different from accumulation data type
|
||||
/// `c_dt`.
|
||||
///
|
||||
/// @param ldd Leading dimension of tensor D.
|
||||
/// @param d_dt Data type of tensor D.
|
||||
/// @param po Primitive post-operation attributes to extend the kernel
|
||||
/// operations.
|
||||
void set_post_ops(memory::dim ldd, memory::data_type d_dt,
|
||||
const post_ops &po = default_post_ops()) {
|
||||
dnnl_status_t status = dnnl_brgemm_set_post_ops(
|
||||
get(), ldd, memory::convert_to_c(d_dt), po.get());
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not set post operations");
|
||||
}
|
||||
|
||||
/// Sets tensor A scales mask to a BRGeMM ukernel object.
|
||||
///
|
||||
/// For quantization flavor tensor A scales apply to accumulation buffer
|
||||
/// once C is ready.
|
||||
///
|
||||
/// @param a_scale_mask Tensor A scale mask. Can be `0` only.
|
||||
void set_A_scales(int a_scale_mask) {
|
||||
dnnl_status_t status = dnnl_brgemm_set_A_scales(get(), a_scale_mask);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not set A scales");
|
||||
}
|
||||
|
||||
/// Sets tensor B scales mask to a BRGeMM ukernel object.
|
||||
///
|
||||
/// For quantization flavor tensor B scales apply to accumulation buffer
|
||||
/// once C is ready.
|
||||
///
|
||||
/// @param b_scale_mask Tensor B scale mask. Can be `0` and `2` only.
|
||||
void set_B_scales(int b_scale_mask) {
|
||||
dnnl_status_t status = dnnl_brgemm_set_B_scales(get(), b_scale_mask);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not set B scales");
|
||||
}
|
||||
|
||||
/// Sets tensor D scales mask to a BRGeMM ukernel object.
|
||||
///
|
||||
/// For quantization flavor tensor D scales apply after all post-ops are
|
||||
/// applied.
|
||||
///
|
||||
/// @param d_scale_mask Tensor D scale mask. Can be `0` only.
|
||||
void set_D_scales(int d_scale_mask) {
|
||||
dnnl_status_t status = dnnl_brgemm_set_D_scales(get(), d_scale_mask);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not set D scales");
|
||||
}
|
||||
|
||||
/// Finalizes initialization of a BRGeMM ukernel object.
|
||||
///
|
||||
/// This step must be performed prior to querying information from the
|
||||
/// object.
|
||||
///
|
||||
/// Returns `true` if the call successfully completed, and `false`,
|
||||
/// otherwise.
|
||||
bool finalize() {
|
||||
dnnl_status_t status = dnnl_brgemm_finalize(get());
|
||||
return status == dnnl_success;
|
||||
}
|
||||
|
||||
/// Returns the packing type expected by a tensor B of a BRGeMM ukernel
|
||||
/// object.
|
||||
///
|
||||
/// @param a_dt Data type of tensor A.
|
||||
/// @param b_dt Data type of tensor B.
|
||||
static pack_type get_B_pack_type(
|
||||
memory::data_type a_dt, memory::data_type b_dt) {
|
||||
dnnl_pack_type_t c_pack_type;
|
||||
dnnl_status_t status = dnnl_brgemm_get_B_pack_type(&c_pack_type,
|
||||
memory::convert_to_c(a_dt), memory::convert_to_c(b_dt));
|
||||
return status == dnnl_success ? static_cast<pack_type>(c_pack_type)
|
||||
: dnnl::ukernel::pack_type::undef;
|
||||
}
|
||||
|
||||
/// Returns the size of a scratchpad memory needed for the BRGeMM ukernel
|
||||
/// object.
|
||||
size_t get_scratchpad_size() const {
|
||||
size_t size;
|
||||
dnnl_status_t status = dnnl_brgemm_get_scratchpad_size(get(), &size);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status,
|
||||
"could not query a scratchpad size from a BRGeMM ukernel "
|
||||
"object");
|
||||
return size;
|
||||
}
|
||||
|
||||
/// Returns the flag indicating when the call to execute with post
|
||||
/// operations is valid.
|
||||
///
|
||||
/// `True` is for a valid call, `false`, otherwise.
|
||||
bool is_execute_postops_valid() const {
|
||||
int valid;
|
||||
dnnl_status_t status
|
||||
= dnnl_brgemm_is_execute_postops_valid(get(), &valid);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status,
|
||||
"could not query a flag for execute postops from a BRGeMM "
|
||||
"ukernel object");
|
||||
return static_cast<bool>(valid);
|
||||
}
|
||||
|
||||
/// Initializes the hardware-specific context. Affects the global state for
|
||||
/// all BRGeMM ukernel objects. If no initialization required, returns.
|
||||
void set_hw_context() const {
|
||||
dnnl_status_t status = dnnl_brgemm_set_hw_context(get());
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not set hardware context");
|
||||
}
|
||||
|
||||
/// Releases the hardware-specific context. Affects the global state for
|
||||
/// all BRGeMM ukernel objects. Must be used after all the execution calls
|
||||
/// to BRGeMM ukernel objects.
|
||||
static void release_hw_context() {
|
||||
dnnl_status_t status = dnnl_brgemm_release_hw_context();
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not release hardware context");
|
||||
}
|
||||
|
||||
/// Generates an executable part of BRGeMM ukernel object.
|
||||
void generate() {
|
||||
dnnl_status_t status = dnnl_brgemm_generate(get());
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status, "could not generate a kernel");
|
||||
}
|
||||
|
||||
/// Executes a BRGeMM ukernel object.
|
||||
///
|
||||
/// @param A Base pointer to a tensor A.
|
||||
/// @param B Base pointer to a tensor B.
|
||||
/// @param A_B_offsets Vector of pairs of tensors A and B offsets for
|
||||
/// each batch. The number of batches must coincide with the
|
||||
/// `batch_size` value passed at object construction stage.
|
||||
/// @param C Pointer to a tensor C (accumulation buffer).
|
||||
/// @param scratchpad Pointer to a scratchpad buffer.
|
||||
void execute(const void *A, const void *B,
|
||||
const std::vector<std::pair<memory::dim, memory::dim>> &A_B_offsets,
|
||||
void *C, void *scratchpad) const {
|
||||
// TODO: export batch_element to C API later for user to fill it and
|
||||
// pass directly to the call.
|
||||
dnnl_status_t status = dnnl_brgemm_execute(get(), A, B,
|
||||
(const dnnl_dim_t *)A_B_offsets.data(), C, scratchpad);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(
|
||||
status, "could not execute a BRGeMM ukernel object");
|
||||
}
|
||||
|
||||
/// Executes a BRGeMM ukernel object with post operations.
|
||||
///
|
||||
/// @param A Base pointer to a tensor A.
|
||||
/// @param B Base pointer to a tensor B.
|
||||
/// @param A_B_offsets Vector of pairs of tensors A and B offsets for
|
||||
/// each batch. The number of batches must coincide with the
|
||||
/// `batch_size` value passed at object construction stage.
|
||||
/// @param C Pointer to a tensor C (accumulation buffer).
|
||||
/// @param D Pointer to a tensor D (output buffer).
|
||||
/// @param scratchpad Pointer to a scratchpad buffer.
|
||||
/// @param params Post-op memory arguments. Must be passed If binary
|
||||
/// post-op or scales were set.
|
||||
void execute(const void *A, const void *B,
|
||||
const std::vector<std::pair<memory::dim, memory::dim>> &A_B_offsets,
|
||||
const void *C, void *D, void *scratchpad,
|
||||
const attr_params ¶ms = default_attr_params()) const {
|
||||
// TODO: export batch_element to C API later for user to fill it and
|
||||
// pass directly to the call.
|
||||
dnnl_status_t status = dnnl_brgemm_execute_postops(get(), A, B,
|
||||
(const dnnl_dim_t *)A_B_offsets.data(), C, D, scratchpad,
|
||||
params.get());
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(
|
||||
status, "could not execute a BRGeMM ukernel object");
|
||||
}
|
||||
|
||||
/// Returns a constant reference to a static instance of default constructed
|
||||
/// primitive post-operations attribute.
|
||||
static const post_ops &default_post_ops() {
|
||||
static const post_ops po;
|
||||
return po;
|
||||
}
|
||||
|
||||
/// Returns a constant reference to a static instance of default constructed
|
||||
/// ukernel attributes parameters.
|
||||
static const attr_params &default_attr_params() {
|
||||
static const attr_params ap;
|
||||
return ap;
|
||||
}
|
||||
};
|
||||
/// @} dnnl_api_ukernel_brgemm
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel_transform Transform ukernel
|
||||
/// Transform routines
|
||||
/// @{
|
||||
|
||||
/// Transform ukernel
|
||||
struct transform : public handle<dnnl_transform_t> {
|
||||
/// Default constructor. Produces an empty object.
|
||||
transform() = default;
|
||||
|
||||
/// Constructs a transform object.
|
||||
///
|
||||
/// @param K Dimension K.
|
||||
/// @param N Dimension N.
|
||||
/// @param in_pack_type Input packing type. Must be one of
|
||||
/// `pack_type::no_trans`, or `pack_type::trans`.
|
||||
/// @param in_ld Input leading dimension.
|
||||
/// @param out_ld Output leading dimension. Specifies a block by N dimension
|
||||
/// during data packing.
|
||||
/// @param in_dt Input data type.
|
||||
/// @param out_dt Output data type.
|
||||
/// @param allow_empty A flag signifying whether construction is
|
||||
/// allowed to fail without throwing an exception. In this case an
|
||||
/// empty object will be produced. This flag is optional and
|
||||
/// defaults to false.
|
||||
transform(memory::dim K, memory::dim N, pack_type in_pack_type,
|
||||
memory::dim in_ld, memory::dim out_ld, memory::data_type in_dt,
|
||||
memory::data_type out_dt, bool allow_empty = false) {
|
||||
|
||||
dnnl_transform_t transform = nullptr;
|
||||
dnnl_status_t status = dnnl_transform_create(&transform, K, N,
|
||||
static_cast<dnnl_pack_type_t>(in_pack_type), in_ld, out_ld,
|
||||
memory::convert_to_c(in_dt), memory::convert_to_c(out_dt));
|
||||
|
||||
if (!allow_empty)
|
||||
error::wrap_c_api(status,
|
||||
"could not create a BRGeMM ukernel packing B object");
|
||||
reset(transform);
|
||||
}
|
||||
|
||||
/// Generates an executable part of transform object.
|
||||
void generate() {
|
||||
dnnl_status_t status = dnnl_transform_generate(get());
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status,
|
||||
"could not generate a BRGeMM ukernel packing B object");
|
||||
}
|
||||
|
||||
/// Executes a transform object.
|
||||
///
|
||||
/// @param in Pointer to an input buffer.
|
||||
/// @param out Pointer to an output buffer.
|
||||
void execute(const void *in, void *out) const {
|
||||
dnnl_status_t status = dnnl_transform_execute(get(), in, out);
|
||||
if (status != dnnl_success)
|
||||
error::wrap_c_api(status,
|
||||
"could not execute a BRGeMM ukernel packing B object");
|
||||
}
|
||||
};
|
||||
|
||||
/// @} dnnl_api_ukernel_transform
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace ukernel
|
||||
|
||||
/// @} dnnl_api_ukernel
|
||||
|
||||
} // namespace dnnl
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
// NOLINTEND(readability-identifier-naming)
|
||||
#endif /* ONEAPI_DNNL_DNNL_UKERNEL_HPP */
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2024 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
/// @file
|
||||
/// ukernel C API types definitions
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_UKERNEL_TYPES_H
|
||||
#define ONEAPI_DNNL_DNNL_UKERNEL_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "oneapi/dnnl/dnnl_types.h"
|
||||
|
||||
/// @addtogroup dnnl_api
|
||||
/// @{
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel
|
||||
/// @{
|
||||
|
||||
#ifdef DNNL_EXPERIMENTAL_UKERNEL
|
||||
|
||||
/// Packing specification
|
||||
typedef enum {
|
||||
/// Undefined pack type. A guard value.
|
||||
dnnl_pack_type_undef = 0,
|
||||
/// Plain, not transposed layout. Similar to format_tag::ab.
|
||||
dnnl_pack_type_no_trans,
|
||||
/// Plain, transposed layout. Similar to format_tag::ba.
|
||||
dnnl_pack_type_trans,
|
||||
/// Packed by 32 bits along K dimension layout.
|
||||
dnnl_pack_type_pack32,
|
||||
} dnnl_pack_type_t;
|
||||
|
||||
/// @struct dnnl_ukernel_attr_params
|
||||
/// An opaque structure to describe ukernel attributes memory storage.
|
||||
struct dnnl_ukernel_attr_params;
|
||||
|
||||
/// A ukernel attributes memory storage handle.
|
||||
typedef struct dnnl_ukernel_attr_params *dnnl_ukernel_attr_params_t;
|
||||
|
||||
/// A constant ukernel attributes memory storage handle.
|
||||
typedef const struct dnnl_ukernel_attr_params *const_dnnl_ukernel_attr_params_t;
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel_brgemm
|
||||
/// @{
|
||||
|
||||
/// @struct dnnl_brgemm
|
||||
/// An opaque structure to describe a brgemm ukernel.
|
||||
struct dnnl_brgemm;
|
||||
|
||||
/// A brgemm ukernel handle.
|
||||
typedef struct dnnl_brgemm *dnnl_brgemm_t;
|
||||
|
||||
/// A constant brgemm ukernel handle.
|
||||
typedef const struct dnnl_brgemm *const_dnnl_brgemm_t;
|
||||
|
||||
/// @} dnnl_api_ukernel_brgemm
|
||||
|
||||
/// @addtogroup dnnl_api_ukernel_transform
|
||||
/// @{
|
||||
|
||||
/// @struct dnnl_transform
|
||||
/// An opaque structure to describe a transform routine.
|
||||
struct dnnl_transform;
|
||||
|
||||
/// A transform routine handle.
|
||||
typedef struct dnnl_transform *dnnl_transform_t;
|
||||
|
||||
/// A constant transform routine handle.
|
||||
typedef const struct dnnl_transform *const_dnnl_transform_t;
|
||||
|
||||
/// @} dnnl_api_ukernel_transform
|
||||
#endif
|
||||
|
||||
/// @} dnnl_api_ukernel
|
||||
|
||||
/// @} dnnl_api
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ONEAPI_DNNL_DNNL_UKERNEL_TYPES_H */
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
@@ -0,0 +1,38 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2019 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_VERSION_H
|
||||
#define ONEAPI_DNNL_DNNL_VERSION_H
|
||||
|
||||
// clang-format off
|
||||
|
||||
/// Major version
|
||||
#define DNNL_VERSION_MAJOR 3
|
||||
|
||||
/// Minor version
|
||||
#define DNNL_VERSION_MINOR 11
|
||||
|
||||
/// Patch version
|
||||
#define DNNL_VERSION_PATCH 2
|
||||
|
||||
// clang-format on
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
/*******************************************************************************
|
||||
* Copyright 2024 Intel Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef ONEAPI_DNNL_DNNL_VERSION_HASH_H
|
||||
#define ONEAPI_DNNL_DNNL_VERSION_HASH_H
|
||||
|
||||
// clang-format off
|
||||
|
||||
/// Note: this macro and header file were moved to a separate instance to avoid
|
||||
/// incremental build issues as moving from commit to commit would trigger a
|
||||
/// complete library rebuild. Including a generated header file in a single
|
||||
/// translation unit makes this problem go away.
|
||||
/// Git commit hash
|
||||
#define DNNL_VERSION_HASH "03c022d3ffdcee958cfacbe720048e725fdf644c"
|
||||
|
||||
// clang-format on
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
|
||||
#endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
|
||||
Reference in New Issue
Block a user