Skip to content

Commit 27d900a

Browse files
committed
sparsity: removed unused code
1 parent 44de3c3 commit 27d900a

17 files changed

+34
-560
lines changed

include/oneapi/dnnl/dnnl.h

+1-51
Original file line numberDiff line numberDiff line change
@@ -1169,11 +1169,7 @@ dnnl_status_t DNNL_API dnnl_memory_desc_init_by_tag(
11691169
/// @returns #dnnl_success on success and a status describing the error
11701170
/// otherwise.
11711171
dnnl_status_t DNNL_API dnnl_sparse_desc_init(dnnl_sparse_desc_t *sparse_desc,
1172-
dnnl_sparse_encoding_t encoding, int ndims_order,
1173-
const dnnl_dims_t dims_order, dnnl_dim_t nnze, int ntypes,
1174-
const dnnl_data_type_t *metadata_types, int nentry_dims,
1175-
const dnnl_dim_t *entry_dims, int structure_ndims,
1176-
const dnnl_dim_t *structure_dims, const dnnl_dim_t *structure_nnz);
1172+
dnnl_sparse_encoding_t encoding);
11771173

11781174
/// Initializes a memory descriptor by the given sparse descriptor.
11791175
///
@@ -1316,17 +1312,6 @@ int DNNL_API dnnl_memory_desc_equal(
13161312
size_t DNNL_API dnnl_memory_desc_get_size(
13171313
const dnnl_memory_desc_t *memory_desc);
13181314

1319-
/// Returns the size of a values and metadata for a particular sparse encoding.
1320-
///
1321-
/// @param memory_desc Memory descriptor.
1322-
/// @param index Index that correspondes to values or metadata. Each sparse
1323-
/// encoding defines index interpretation.
1324-
///
1325-
/// @returns The number of bytes required for values or metadata for a
1326-
/// particular sparse encoding described by a memory descriptor.
1327-
size_t DNNL_API dnnl_memory_desc_get_size_sparse(
1328-
const dnnl_memory_desc_t *memory_desc, int index);
1329-
13301315
/// Returns the size of data type.
13311316
///
13321317
/// @param data_type Data type.
@@ -1357,27 +1342,6 @@ dnnl_status_t DNNL_API dnnl_memory_create(dnnl_memory_t *memory,
13571342
const dnnl_memory_desc_t *memory_desc, dnnl_engine_t engine,
13581343
void *handle);
13591344

1360-
/// Creates a sparse memory object.
1361-
///
1362-
/// @param memory Output memory object.
1363-
/// @param memory_desc Memory descriptor.
1364-
/// @param engine Engine to use.
1365-
/// @param nhandles Number of handles.
1366-
/// @param handles Handles of the memory buffers to use as underlying storages.
1367-
/// For each element of the @p handles array the following applies:
1368-
/// - A pointer to the user-allocated buffer. In this case the library
1369-
/// doesn't own the buffer.
1370-
/// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
1371-
/// allocate the buffer for the memory object. In this case the library
1372-
/// owns the buffer.
1373-
/// - DNNL_MEMORY_NONE Instructs the library to skip allocation of the
1374-
/// memory buffer.
1375-
/// @returns #dnnl_success on success and a status describing the error
1376-
/// otherwise.
1377-
dnnl_status_t DNNL_API dnnl_memory_create_sparse(dnnl_memory_t *memory,
1378-
const dnnl_memory_desc_t *memory_desc, dnnl_engine_t engine,
1379-
dnnl_dim_t nhandles, void **handles);
1380-
13811345
/// Returns the memory descriptor for a memory object.
13821346
///
13831347
/// @param memory Memory object.
@@ -1439,13 +1403,6 @@ dnnl_status_t DNNL_API dnnl_memory_map_data(
14391403
dnnl_status_t DNNL_API dnnl_memory_unmap_data(
14401404
const_dnnl_memory_t memory, void *mapped_ptr);
14411405

1442-
// TODO: add documentation and put these in the right place.
1443-
dnnl_status_t DNNL_API dnnl_memory_map_data_sparse(
1444-
const_dnnl_memory_t memory, int index, void **mapped_ptr);
1445-
1446-
dnnl_status_t DNNL_API dnnl_memory_unmap_data_sparse(
1447-
const_dnnl_memory_t memory, int index, void *mapped_ptr);
1448-
14491406
/// Returns memory object's data handle.
14501407
///
14511408
/// @param memory Memory object.
@@ -1470,13 +1427,6 @@ dnnl_status_t DNNL_API dnnl_memory_set_data_handle(
14701427

14711428
dnnl_status_t DNNL_API dnnl_memory_set_data_handle_no_pads_proc(
14721429
dnnl_memory_t memory, void *handle);
1473-
1474-
// TODO: add documentation and put these in the right place.
1475-
dnnl_status_t DNNL_API dnnl_memory_get_data_handles(
1476-
const_dnnl_memory_t memory, dnnl_dim_t *nhandles, void **handles);
1477-
1478-
dnnl_status_t DNNL_API dnnl_memory_set_data_handles(
1479-
dnnl_memory_t memory, dnnl_dim_t nhandles, void **handles);
14801430

14811431
/// Sets the underlying memory buffer.
14821432
///

include/oneapi/dnnl/dnnl.hpp

+7-136
Original file line numberDiff line numberDiff line change
@@ -2497,22 +2497,9 @@ struct memory : public handle<dnnl_memory_t> {
24972497
/// A memory descriptor.
24982498
struct desc {
24992499
struct sparse_desc {
2500-
sparse_desc(dnnl_sparse_encoding_t encoding, const dims &dims_order,
2501-
dim nnze, const std::vector<data_type> &metadata_types,
2502-
const dims &entry_dims, const dims &structure_dims,
2503-
const dims &structure_nnz, bool allow_empty = false) {
2504-
std::vector<dnnl_data_type_t> c_metadata_types(
2505-
metadata_types.size());
2506-
for (size_t i = 0; i < c_metadata_types.size(); i++) {
2507-
c_metadata_types[i] = convert_to_c(metadata_types[i]);
2508-
}
2500+
sparse_desc(dnnl_sparse_encoding_t encoding, bool allow_empty = false) {
25092501
// TODO: check structure_dims.size() == structure_nnz.size();
2510-
dnnl_status_t status = dnnl_sparse_desc_init(&data, encoding,
2511-
(int)dims_order.size(), dims_order.data(), nnze,
2512-
(int)c_metadata_types.size(), c_metadata_types.data(),
2513-
(int)entry_dims.size(), entry_dims.data(),
2514-
(int)structure_dims.size(), structure_dims.data(),
2515-
structure_nnz.data());
2502+
dnnl_status_t status = dnnl_sparse_desc_init(&data, encoding);
25162503
if (!allow_empty)
25172504
error::wrap_c_api(
25182505
status, "could not construct a sparse descriptor");
@@ -2602,41 +2589,8 @@ struct memory : public handle<dnnl_memory_t> {
26022589
"sparse descriptor");
26032590
}
26042591

2605-
/// Function for creating CSR sparse desc with unstructured sparsity.
2606-
static sparse_desc csr(dim nnze, data_type index_type,
2607-
data_type pointer_type, bool allow_empty = false) {
2608-
return sparse_desc(dnnl_sparse_encoding_csr, {0, 1}, nnze,
2609-
{index_type, pointer_type}, {}, {}, {}, allow_empty);
2610-
}
2611-
2612-
/// Function for creating CSC sparse desc with unstructured sparsity.
2613-
static sparse_desc csc(dim nnze, data_type index_type,
2614-
data_type pointer_type, bool allow_empty = false) {
2615-
return sparse_desc(dnnl_sparse_encoding_csc, {1, 0}, nnze,
2616-
{index_type, pointer_type}, {}, {}, {}, allow_empty);
2617-
}
2618-
2619-
/// Function for creating BCSR sparse desc with unstructured sparsity.
2620-
static sparse_desc bcsr(dim nnze, data_type index_type,
2621-
data_type pointer_type, const dims &block_dims,
2622-
bool allow_empty = false) {
2623-
return sparse_desc(dnnl_sparse_encoding_bcsr, {0, 1}, nnze,
2624-
{index_type, pointer_type}, block_dims, {}, {},
2625-
allow_empty);
2626-
}
2627-
2628-
/// Function for creating BCSC sparse desc unstructured sparsity.
2629-
static sparse_desc bcsc(dim nnze, data_type index_type,
2630-
data_type pointer_type, const dims &block_dims,
2631-
bool allow_empty = false) {
2632-
return sparse_desc(dnnl_sparse_encoding_bcsc, {1, 0}, nnze,
2633-
{index_type, pointer_type}, block_dims, {}, {},
2634-
allow_empty);
2635-
}
2636-
2637-
static sparse_desc packed(dim nnze, bool allow_empty = false) {
2638-
return sparse_desc(dnnl_sparse_encoding_packed, {}, nnze, {}, {},
2639-
{}, {}, allow_empty);
2592+
static sparse_desc packed(bool allow_empty = false) {
2593+
return sparse_desc(dnnl_sparse_encoding_packed, allow_empty);
26402594
}
26412595

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

2789-
/// Returns the size of a values and metadata for a particular sparse
2790-
/// encoding.
2791-
///
2792-
/// @param index Index that correspondes to values or metadata.
2793-
/// Each sparse encoding defines index interpretation.
2794-
///
2795-
/// @returns The number of bytes required for values or metadata for a
2796-
/// particular sparse encoding described by a memory descriptor.
2797-
size_t get_size(int index) const {
2798-
return dnnl_memory_desc_get_size_sparse(&data, index);
2799-
}
2800-
28012743
/// Checks whether the memory descriptor is zero (empty).
28022744
/// @returns @c true if the memory descriptor describes an empty
28032745
/// memory and @c false otherwise.
@@ -2858,44 +2800,12 @@ struct memory : public handle<dnnl_memory_t> {
28582800

28592801
/// Constructs a memory object.
28602802
///
2861-
/// The underlying buffer(s) for the memory will be allocated by the
2862-
/// library.
2803+
/// The underlying buffer for the memory will be allocated by the library.
28632804
///
28642805
/// @param md Memory descriptor.
28652806
/// @param aengine Engine to store the data on.
2866-
memory(const desc &md, const engine &aengine) {
2867-
dnnl_status_t status;
2868-
dnnl_memory_t result;
2869-
const bool is_sparse_md = md.data.format_kind == dnnl_format_sparse;
2870-
if (is_sparse_md) {
2871-
// Deduce number of handles.
2872-
dim nhandles = 0;
2873-
switch (md.data.format_desc.sparse_desc.encoding) {
2874-
case dnnl_sparse_encoding_csr:
2875-
case dnnl_sparse_encoding_csc:
2876-
case dnnl_sparse_encoding_bcsr:
2877-
case dnnl_sparse_encoding_bcsc: nhandles = 3; break;
2878-
case dnnl_sparse_encoding_packed: nhandles = 1; break;
2879-
default: nhandles = 0;
2880-
}
2881-
std::vector<void *> handles(nhandles, DNNL_MEMORY_ALLOCATE);
2882-
status = dnnl_memory_create_sparse(&result, &md.data, aengine.get(),
2883-
(dim)handles.size(), handles.data());
2884-
} else {
2885-
status = dnnl_memory_create(
2886-
&result, &md.data, aengine.get(), DNNL_MEMORY_ALLOCATE);
2887-
}
2888-
error::wrap_c_api(status, "could not create a memory object");
2889-
reset(result);
2890-
}
2891-
2892-
memory(const desc &md, const engine &aengine, std::vector<void *> handles) {
2893-
dnnl_memory_t result;
2894-
dnnl_status_t status = dnnl_memory_create_sparse(&result, &md.data,
2895-
aengine.get(), (dim)handles.size(), handles.data());
2896-
error::wrap_c_api(status, "could not create a memory object");
2897-
reset(result);
2898-
}
2807+
memory(const desc &md, const engine &aengine)
2808+
: memory(md, aengine, DNNL_MEMORY_ALLOCATE) {}
28992809

29002810
/// Returns the associated memory descriptor.
29012811
desc get_desc() const {
@@ -2924,28 +2834,6 @@ struct memory : public handle<dnnl_memory_t> {
29242834
return handle;
29252835
}
29262836

2927-
// TODO: add documentation.
2928-
std::vector<void *> get_data_handles() const {
2929-
dim nhandles;
2930-
error::wrap_c_api(
2931-
dnnl_memory_get_data_handles(get(), &nhandles, nullptr),
2932-
"could not get a number of native handles from a memory "
2933-
"object");
2934-
std::vector<void *> handles(nhandles);
2935-
error::wrap_c_api(
2936-
dnnl_memory_get_data_handles(get(), &nhandles, handles.data()),
2937-
"could not get native handles from a memory object");
2938-
return handles;
2939-
}
2940-
2941-
// TODO: add documentation.
2942-
void set_data_handles(std::vector<void *> handles) {
2943-
dim nhandles = handles.size();
2944-
error::wrap_c_api(
2945-
dnnl_memory_set_data_handles(get(), nhandles, handles.data()),
2946-
"could not set native handles of a memory object");
2947-
}
2948-
29492837
/// Sets the underlying memory buffer.
29502838
///
29512839
/// This function may write zero values to the memory specified by the @p
@@ -3031,23 +2919,6 @@ struct memory : public handle<dnnl_memory_t> {
30312919
return static_cast<T *>(mapped_ptr);
30322920
}
30332921

3034-
// TODO: add documentation.
3035-
template <typename T = void>
3036-
T *map_data(int index) const {
3037-
void *mapped_ptr;
3038-
error::wrap_c_api(
3039-
dnnl_memory_map_data_sparse(get(), index, &mapped_ptr),
3040-
"could not map memory object data");
3041-
return static_cast<T *>(mapped_ptr);
3042-
}
3043-
3044-
// TODO: add documentation.
3045-
void unmap_data(int index, void *mapped_ptr) const {
3046-
error::wrap_c_api(
3047-
dnnl_memory_unmap_data_sparse(get(), index, mapped_ptr),
3048-
"could not unmap memory object data");
3049-
}
3050-
30512922
/// Unmaps a memory object and writes back any changes made to the
30522923
/// previously mapped memory buffer.
30532924
///

include/oneapi/dnnl/dnnl_types.h

-26
Original file line numberDiff line numberDiff line change
@@ -1823,38 +1823,12 @@ typedef struct {
18231823
typedef enum {
18241824
dnnl_sparse_encoding_undef = 0,
18251825
dnnl_sparse_encoding_any,
1826-
dnnl_sparse_encoding_csr,
1827-
dnnl_sparse_encoding_csc,
1828-
dnnl_sparse_encoding_bcsr,
1829-
dnnl_sparse_encoding_bcsc,
18301826
dnnl_sparse_encoding_packed,
18311827
} dnnl_sparse_encoding_t;
18321828

1833-
/// Maximum number of types for metadata.
1834-
#define DNNL_MAX_METADATA_TYPES 12
1835-
18361829
typedef struct {
18371830
/// Specifies what encoding is used.
18381831
dnnl_sparse_encoding_t encoding;
1839-
/// Order of dimensions. E.g. for CSR it's [0, 1], for CSC [1, 0].
1840-
dnnl_dims_t dims_order;
1841-
/// Number of non-zero entries.
1842-
dnnl_dim_t nnze;
1843-
/// Metadata types. Each encoding defines how to interpret these.
1844-
dnnl_data_type_t metadata_types[DNNL_MAX_METADATA_TYPES];
1845-
/// Dimensions of an entry. For example: 1x1 for CSR/CSC or MxN for
1846-
/// BCSR/BCSC.
1847-
dnnl_dim_t entry_dims[2];
1848-
1849-
/// Section that describes sparsity pattern.
1850-
///
1851-
/// Number of dimensions of a structure block. When ndims is 0 then sparsity
1852-
/// pattern is considered unstructured.
1853-
int structure_ndims;
1854-
/// Dimensions of a structure block.
1855-
dnnl_dim_t structure_dims[2];
1856-
/// Number of non-zero elements per-dimension.
1857-
dnnl_dim_t structure_nnz[2];
18581832
/// Descriptor for blocked bitmask - opaque.
18591833
dnnl_blocking_desc_t packed_desc;
18601834
} dnnl_sparse_desc_t;

src/common/c_types_map.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -1221,10 +1221,6 @@ using sparse_encoding_t = dnnl_sparse_encoding_t;
12211221
namespace sparse_encoding {
12221222
const sparse_encoding_t undef = dnnl_sparse_encoding_undef;
12231223
const sparse_encoding_t any = dnnl_sparse_encoding_any;
1224-
const sparse_encoding_t csr = dnnl_sparse_encoding_csr;
1225-
const sparse_encoding_t csc = dnnl_sparse_encoding_csc;
1226-
const sparse_encoding_t bcsr = dnnl_sparse_encoding_bcsr;
1227-
const sparse_encoding_t bcsc = dnnl_sparse_encoding_bcsc;
12281224
const sparse_encoding_t packed = dnnl_sparse_encoding_packed;
12291225
} // namespace sparse_encoding
12301226

src/common/dnnl_debug_autogenerated.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -1212,10 +1212,6 @@ const char *dnnl_alg_kind2str(dnnl_alg_kind_t v) {
12121212
const char *dnnl_sparse_encoding2str(dnnl_sparse_encoding_t v) {
12131213
if (v == dnnl_sparse_encoding_undef) return "undef";
12141214
if (v == dnnl_sparse_encoding_any) return "any";
1215-
if (v == dnnl_sparse_encoding_csr) return "sparse_encoding_csr";
1216-
if (v == dnnl_sparse_encoding_csc) return "sparse_encoding_csc";
1217-
if (v == dnnl_sparse_encoding_bcsr) return "sparse_encoding_bcsr";
1218-
if (v == dnnl_sparse_encoding_bcsc) return "sparse_encoding_bcsc";
12191215
if (v == dnnl_sparse_encoding_packed) return "sparse_encoding_packed";
12201216
assert(!"unknown sparse_encoding");
12211217
return "unknown sparse_encoding";

0 commit comments

Comments
 (0)