Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sparsity: removed unused code #170

Open
wants to merge 1 commit into
base: v2.7_for_ie_master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 1 addition & 74 deletions include/oneapi/dnnl/dnnl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1144,44 +1144,17 @@ dnnl_status_t DNNL_API dnnl_memory_desc_init_by_tag(
///
/// @param sparse_desc Output sparse descriptor.
/// @param encoding Encoding.
/// @param ndims_order Number of elements in @p dims_order.
/// Has to be consistent with #dnnl_memory_desc_t::ndims.
/// Can be 0 if @p dims_order is NULL.
/// @param dims_order Array with dimensions order. E.g. [0, 1] or [1, 0].
/// Can be NULL.
/// Can be NULL in which case [0, ndims - 1] order will be used.
/// @param nnze Number or non-zero entries.
/// @param ntypes Number of data types for metadata.
/// @param metadata_types Array of data types for metadata.
/// @param nentry_dims Number of dimensions of an entry. Can be 0 if entry
/// is a scalar.
/// @param entry_dims Array of dimensions of an entry.
/// Can be NULL if @p nentry_dims is 0.
/// @param structure_ndims Number of dimensions of a structure block.
/// Can be 0 if sparsity has not structure.
/// @param structure_dims Array of dimensions of a structure block.
/// Can be NULL if @p structure_ndims is 0.
/// @param structure_nnz Array that specifies number of non-zero elements per
/// structure block dimension. E.g. when a structure block is a vector of
/// size 8 the @p structure_nnz array will contain a single element
/// 4 meaning that 4 out of 8 elements are guaranteed to be non-zero.
/// Can be NULL if @p structure_ndims is 0.
/// @returns #dnnl_success on success and a status describing the error
/// otherwise.
dnnl_status_t DNNL_API dnnl_sparse_desc_init(dnnl_sparse_desc_t *sparse_desc,
dnnl_sparse_encoding_t encoding, int ndims_order,
const dnnl_dims_t dims_order, dnnl_dim_t nnze, int ntypes,
const dnnl_data_type_t *metadata_types, int nentry_dims,
const dnnl_dim_t *entry_dims, int structure_ndims,
const dnnl_dim_t *structure_dims, const dnnl_dim_t *structure_nnz);
dnnl_sparse_encoding_t encoding);

/// Initializes a memory descriptor by the given sparse descriptor.
///
/// @param memory_desc Output memory descriptor.
/// @param ndims Number of dimensions.
/// @param dims Array of dimensions.
/// @param data_type Elements data type.
/// @param structure_nnz Array that specifies number of non-zero elements per
/// @param sparse_desc Sparse descriptor.
/// @returns #dnnl_success on success and a status describing the error
/// otherwise
Expand Down Expand Up @@ -1316,17 +1289,6 @@ int DNNL_API dnnl_memory_desc_equal(
size_t DNNL_API dnnl_memory_desc_get_size(
const dnnl_memory_desc_t *memory_desc);

/// Returns the size of a values and metadata for a particular sparse encoding.
///
/// @param memory_desc Memory descriptor.
/// @param index Index that correspondes to values or metadata. Each sparse
/// encoding defines index interpretation.
///
/// @returns The number of bytes required for values or metadata for a
/// particular sparse encoding described by a memory descriptor.
size_t DNNL_API dnnl_memory_desc_get_size_sparse(
const dnnl_memory_desc_t *memory_desc, int index);

/// Returns the size of data type.
///
/// @param data_type Data type.
Expand Down Expand Up @@ -1357,27 +1319,6 @@ dnnl_status_t DNNL_API dnnl_memory_create(dnnl_memory_t *memory,
const dnnl_memory_desc_t *memory_desc, dnnl_engine_t engine,
void *handle);

/// Creates a sparse memory object.
///
/// @param memory Output memory object.
/// @param memory_desc Memory descriptor.
/// @param engine Engine to use.
/// @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 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 memory object. In this case the library
/// owns the buffer.
/// - DNNL_MEMORY_NONE Instructs the library to skip allocation of the
/// memory buffer.
/// @returns #dnnl_success on success and a status describing the error
/// otherwise.
dnnl_status_t DNNL_API dnnl_memory_create_sparse(dnnl_memory_t *memory,
const dnnl_memory_desc_t *memory_desc, dnnl_engine_t engine,
dnnl_dim_t nhandles, void **handles);

/// Returns the memory descriptor for a memory object.
///
/// @param memory Memory object.
Expand Down Expand Up @@ -1439,13 +1380,6 @@ dnnl_status_t DNNL_API dnnl_memory_map_data(
dnnl_status_t DNNL_API dnnl_memory_unmap_data(
const_dnnl_memory_t memory, void *mapped_ptr);

// TODO: add documentation and put these in the right place.
dnnl_status_t DNNL_API dnnl_memory_map_data_sparse(
const_dnnl_memory_t memory, int index, void **mapped_ptr);

dnnl_status_t DNNL_API dnnl_memory_unmap_data_sparse(
const_dnnl_memory_t memory, int index, void *mapped_ptr);

/// Returns memory object's data handle.
///
/// @param memory Memory object.
Expand All @@ -1470,13 +1404,6 @@ dnnl_status_t DNNL_API dnnl_memory_set_data_handle(

dnnl_status_t DNNL_API dnnl_memory_set_data_handle_no_pads_proc(
dnnl_memory_t memory, void *handle);

// TODO: add documentation and put these in the right place.
dnnl_status_t DNNL_API dnnl_memory_get_data_handles(
const_dnnl_memory_t memory, dnnl_dim_t *nhandles, void **handles);

dnnl_status_t DNNL_API dnnl_memory_set_data_handles(
dnnl_memory_t memory, dnnl_dim_t nhandles, void **handles);

/// Sets the underlying memory buffer.
///
Expand Down
143 changes: 7 additions & 136 deletions include/oneapi/dnnl/dnnl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2497,22 +2497,9 @@ struct memory : public handle<dnnl_memory_t> {
/// A memory descriptor.
struct desc {
struct sparse_desc {
sparse_desc(dnnl_sparse_encoding_t encoding, const dims &dims_order,
dim nnze, const std::vector<data_type> &metadata_types,
const dims &entry_dims, const dims &structure_dims,
const dims &structure_nnz, bool allow_empty = false) {
std::vector<dnnl_data_type_t> c_metadata_types(
metadata_types.size());
for (size_t i = 0; i < c_metadata_types.size(); i++) {
c_metadata_types[i] = convert_to_c(metadata_types[i]);
}
sparse_desc(dnnl_sparse_encoding_t encoding, bool allow_empty = false) {
// TODO: check structure_dims.size() == structure_nnz.size();
dnnl_status_t status = dnnl_sparse_desc_init(&data, encoding,
(int)dims_order.size(), dims_order.data(), nnze,
(int)c_metadata_types.size(), c_metadata_types.data(),
(int)entry_dims.size(), entry_dims.data(),
(int)structure_dims.size(), structure_dims.data(),
structure_nnz.data());
dnnl_status_t status = dnnl_sparse_desc_init(&data, encoding);
if (!allow_empty)
error::wrap_c_api(
status, "could not construct a sparse descriptor");
Expand Down Expand Up @@ -2602,41 +2589,8 @@ struct memory : public handle<dnnl_memory_t> {
"sparse descriptor");
}

/// Function for creating CSR sparse desc with unstructured sparsity.
static sparse_desc csr(dim nnze, data_type index_type,
data_type pointer_type, bool allow_empty = false) {
return sparse_desc(dnnl_sparse_encoding_csr, {0, 1}, nnze,
{index_type, pointer_type}, {}, {}, {}, allow_empty);
}

/// Function for creating CSC sparse desc with unstructured sparsity.
static sparse_desc csc(dim nnze, data_type index_type,
data_type pointer_type, bool allow_empty = false) {
return sparse_desc(dnnl_sparse_encoding_csc, {1, 0}, nnze,
{index_type, pointer_type}, {}, {}, {}, allow_empty);
}

/// Function for creating BCSR sparse desc with unstructured sparsity.
static sparse_desc bcsr(dim nnze, data_type index_type,
data_type pointer_type, const dims &block_dims,
bool allow_empty = false) {
return sparse_desc(dnnl_sparse_encoding_bcsr, {0, 1}, nnze,
{index_type, pointer_type}, block_dims, {}, {},
allow_empty);
}

/// Function for creating BCSC sparse desc unstructured sparsity.
static sparse_desc bcsc(dim nnze, data_type index_type,
data_type pointer_type, const dims &block_dims,
bool allow_empty = false) {
return sparse_desc(dnnl_sparse_encoding_bcsc, {1, 0}, nnze,
{index_type, pointer_type}, block_dims, {}, {},
allow_empty);
}

static sparse_desc packed(dim nnze, bool allow_empty = false) {
return sparse_desc(dnnl_sparse_encoding_packed, {}, nnze, {}, {},
{}, {}, allow_empty);
static sparse_desc packed(bool allow_empty = false) {
return sparse_desc(dnnl_sparse_encoding_packed, allow_empty);
}

/// Constructs a memory descriptor for a region inside an area
Expand Down Expand Up @@ -2786,18 +2740,6 @@ struct memory : public handle<dnnl_memory_t> {
/// including the padding area.
size_t get_size() const { return dnnl_memory_desc_get_size(&data); }

/// Returns the size of a values and metadata for a particular sparse
/// encoding.
///
/// @param index Index that correspondes to values or metadata.
/// Each sparse encoding defines index interpretation.
///
/// @returns The number of bytes required for values or metadata for a
/// particular sparse encoding described by a memory descriptor.
size_t get_size(int index) const {
return dnnl_memory_desc_get_size_sparse(&data, index);
}

/// Checks whether the memory descriptor is zero (empty).
/// @returns @c true if the memory descriptor describes an empty
/// memory and @c false otherwise.
Expand Down Expand Up @@ -2858,44 +2800,12 @@ struct memory : public handle<dnnl_memory_t> {

/// Constructs a memory object.
///
/// The underlying buffer(s) for the memory will be allocated by the
/// library.
/// The underlying buffer for the memory will be allocated by the library.
///
/// @param md Memory descriptor.
/// @param aengine Engine to store the data on.
memory(const desc &md, const engine &aengine) {
dnnl_status_t status;
dnnl_memory_t result;
const bool is_sparse_md = md.data.format_kind == dnnl_format_sparse;
if (is_sparse_md) {
// Deduce number of handles.
dim nhandles = 0;
switch (md.data.format_desc.sparse_desc.encoding) {
case dnnl_sparse_encoding_csr:
case dnnl_sparse_encoding_csc:
case dnnl_sparse_encoding_bcsr:
case dnnl_sparse_encoding_bcsc: nhandles = 3; break;
case dnnl_sparse_encoding_packed: nhandles = 1; break;
default: nhandles = 0;
}
std::vector<void *> handles(nhandles, DNNL_MEMORY_ALLOCATE);
status = dnnl_memory_create_sparse(&result, &md.data, aengine.get(),
(dim)handles.size(), handles.data());
} else {
status = dnnl_memory_create(
&result, &md.data, aengine.get(), DNNL_MEMORY_ALLOCATE);
}
error::wrap_c_api(status, "could not create a memory object");
reset(result);
}

memory(const desc &md, const engine &aengine, std::vector<void *> handles) {
dnnl_memory_t result;
dnnl_status_t status = dnnl_memory_create_sparse(&result, &md.data,
aengine.get(), (dim)handles.size(), handles.data());
error::wrap_c_api(status, "could not create a memory object");
reset(result);
}
memory(const desc &md, const engine &aengine)
: memory(md, aengine, DNNL_MEMORY_ALLOCATE) {}

/// Returns the associated memory descriptor.
desc get_desc() const {
Expand Down Expand Up @@ -2924,28 +2834,6 @@ struct memory : public handle<dnnl_memory_t> {
return handle;
}

// TODO: add documentation.
std::vector<void *> get_data_handles() const {
dim nhandles;
error::wrap_c_api(
dnnl_memory_get_data_handles(get(), &nhandles, nullptr),
"could not get a number of native handles from a memory "
"object");
std::vector<void *> handles(nhandles);
error::wrap_c_api(
dnnl_memory_get_data_handles(get(), &nhandles, handles.data()),
"could not get native handles from a memory object");
return handles;
}

// TODO: add documentation.
void set_data_handles(std::vector<void *> handles) {
dim nhandles = handles.size();
error::wrap_c_api(
dnnl_memory_set_data_handles(get(), nhandles, handles.data()),
"could not set native handles of a memory object");
}

/// Sets the underlying memory buffer.
///
/// This function may write zero values to the memory specified by the @p
Expand Down Expand Up @@ -3031,23 +2919,6 @@ struct memory : public handle<dnnl_memory_t> {
return static_cast<T *>(mapped_ptr);
}

// TODO: add documentation.
template <typename T = void>
T *map_data(int index) const {
void *mapped_ptr;
error::wrap_c_api(
dnnl_memory_map_data_sparse(get(), index, &mapped_ptr),
"could not map memory object data");
return static_cast<T *>(mapped_ptr);
}

// TODO: add documentation.
void unmap_data(int index, void *mapped_ptr) const {
error::wrap_c_api(
dnnl_memory_unmap_data_sparse(get(), index, mapped_ptr),
"could not unmap memory object data");
}

/// Unmaps a memory object and writes back any changes made to the
/// previously mapped memory buffer.
///
Expand Down
26 changes: 0 additions & 26 deletions include/oneapi/dnnl/dnnl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1823,38 +1823,12 @@ typedef struct {
typedef enum {
dnnl_sparse_encoding_undef = 0,
dnnl_sparse_encoding_any,
dnnl_sparse_encoding_csr,
dnnl_sparse_encoding_csc,
dnnl_sparse_encoding_bcsr,
dnnl_sparse_encoding_bcsc,
dnnl_sparse_encoding_packed,
} dnnl_sparse_encoding_t;

/// Maximum number of types for metadata.
#define DNNL_MAX_METADATA_TYPES 12

typedef struct {
/// Specifies what encoding is used.
dnnl_sparse_encoding_t encoding;
/// Order of dimensions. E.g. for CSR it's [0, 1], for CSC [1, 0].
dnnl_dims_t dims_order;
/// Number of non-zero entries.
dnnl_dim_t nnze;
/// Metadata types. Each encoding defines how to interpret these.
dnnl_data_type_t metadata_types[DNNL_MAX_METADATA_TYPES];
/// Dimensions of an entry. For example: 1x1 for CSR/CSC or MxN for
/// BCSR/BCSC.
dnnl_dim_t entry_dims[2];

/// Section that describes sparsity pattern.
///
/// Number of dimensions of a structure block. When ndims is 0 then sparsity
/// pattern is considered unstructured.
int structure_ndims;
/// Dimensions of a structure block.
dnnl_dim_t structure_dims[2];
/// Number of non-zero elements per-dimension.
dnnl_dim_t structure_nnz[2];
/// Descriptor for blocked bitmask - opaque.
dnnl_blocking_desc_t packed_desc;
} dnnl_sparse_desc_t;
Expand Down
4 changes: 0 additions & 4 deletions src/common/c_types_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,10 +1221,6 @@ using sparse_encoding_t = dnnl_sparse_encoding_t;
namespace sparse_encoding {
const sparse_encoding_t undef = dnnl_sparse_encoding_undef;
const sparse_encoding_t any = dnnl_sparse_encoding_any;
const sparse_encoding_t csr = dnnl_sparse_encoding_csr;
const sparse_encoding_t csc = dnnl_sparse_encoding_csc;
const sparse_encoding_t bcsr = dnnl_sparse_encoding_bcsr;
const sparse_encoding_t bcsc = dnnl_sparse_encoding_bcsc;
const sparse_encoding_t packed = dnnl_sparse_encoding_packed;
} // namespace sparse_encoding

Expand Down
4 changes: 0 additions & 4 deletions src/common/dnnl_debug_autogenerated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,10 +1212,6 @@ const char *dnnl_alg_kind2str(dnnl_alg_kind_t v) {
const char *dnnl_sparse_encoding2str(dnnl_sparse_encoding_t v) {
if (v == dnnl_sparse_encoding_undef) return "undef";
if (v == dnnl_sparse_encoding_any) return "any";
if (v == dnnl_sparse_encoding_csr) return "sparse_encoding_csr";
if (v == dnnl_sparse_encoding_csc) return "sparse_encoding_csc";
if (v == dnnl_sparse_encoding_bcsr) return "sparse_encoding_bcsr";
if (v == dnnl_sparse_encoding_bcsc) return "sparse_encoding_bcsc";
if (v == dnnl_sparse_encoding_packed) return "sparse_encoding_packed";
assert(!"unknown sparse_encoding");
return "unknown sparse_encoding";
Expand Down
Loading