6 #if !defined(DISABLE_SPARSE_TENSORS)
14 namespace onnxruntime {
17 class DataTransferManager;
86 std::shared_ptr<IAllocator> allocator);
121 std::shared_ptr<IAllocator> allocator,
202 return ml_data_type_;
210 return utils::IsPrimitiveDataType<std::string>(ml_data_type_);
220 return utils::IsPrimitiveDataType<T>(ml_data_type_);
235 std::reference_wrapper<const Tensor> indices_;
242 CooView
AsCoo()
const;
272 size_t values_count,
const void* values_data, gsl::span<const int64_t>
indices);
296 std::reference_wrapper<Tensor> values_;
297 std::reference_wrapper<Tensor> indices_;
307 CooMutator
MakeCooData(
size_t values_count,
size_t index_count);
315 : inner_(inner), outer_(outer) {}
320 std::reference_wrapper<const Tensor> inner_;
321 std::reference_wrapper<const Tensor> outer_;
328 CsrView
AsCsr()
const;
352 size_t values_count,
const void* values_data,
353 gsl::span<const int64_t> inner_index,
354 gsl::span<const int64_t> outer_index);
368 gsl::span<const int64_t> inner_index,
369 gsl::span<const int64_t> outer_index);
377 : values_(
values), inner_(inner), outer_(outer) {}
383 std::reference_wrapper<Tensor> values_;
384 std::reference_wrapper<Tensor> inner_;
385 std::reference_wrapper<Tensor> outer_;
396 CsrMutator
MakeCsrData(
size_t values_count,
size_t inner_index_count,
size_t outer_index_count);
408 std::reference_wrapper<const Tensor> indices_;
446 const TensorShape& values_shape,
const void* values_data,
447 const TensorShape& indices_shape,
const int32_t* indices_data);
461 const TensorShape& indices_shape,
const int32_t* indices_data);
474 std::reference_wrapper<Tensor> values_;
475 std::reference_wrapper<Tensor> indices_;
504 Status AllocateBuffer(int64_t buffer_size,
size_t num_values);
505 void ReleaseBuffer();
506 void* IndicesStart(int64_t values_bytes);
507 const void* IndicesStart(int64_t values_bytes)
const;
510 std::vector<int64_t> GetCooIndexDims(
size_t values_count,
size_t index_size)
const;
511 void InitCooIndex(
const TensorShape& index_shape, int64_t* index_data);
513 Status ValidateCsrIndices(
size_t values_count,
size_t inner_size,
size_t outer_size)
const;
514 void InitCsrIndices(
size_t inner_size,
const int64_t* inner,
size_t outer_size,
const int64_t* outer);
515 void InitBlockSparseIndices(
const TensorShape& indices_shape, int32_t* indices_data);
524 int64_t buffer_size_;
527 std::vector<Tensor> format_data_;
Tensor & Values() const noexcept
Tensor & Inner() const noexcept
CooView AsCoo() const
Returns Coo index view
GLsizei GLenum const void * indices
static void InitOrtValue(MLDataType elt_type, const TensorShape &dense_shape, const TensorShape &values_shape, void *values_data, const OrtMemoryInfo &location, OrtValue &ort_value)
The factory function creates an instance of SparseTensor on the heap using appropriate constructor an...
Base class for MLDataType.
Status MakeCooStrings(size_t string_count, const char *const *strings, gsl::span< const int64_t > indices)
The method allocates a single contiguous buffer and creates instances of std::strings in it...
Status MakeBlockSparseStrings(const TensorShape &values_shape, const char *const *strings, const TensorShape &indices_shape, const int32_t *indices_data)
The method allocates a single contiguous buffer and creates instances of std::strings in it...
CsrMutator(Tensor &values, Tensor &inner, Tensor &outer) noexcept
CsrView AsCsr() const
Returns Csr indices read only view
const Tensor & Indices() const noexcept
BlockSparseMutator(Tensor &values, Tensor &indices) noexcept
Status MakeCooData(const IDataTransfer &data_transfer, const OrtMemoryInfo &data_location, size_t values_count, const void *values_data, gsl::span< const int64_t > indices)
The method allocates a single contiguous buffer and copies specified values and indices into it using...
Status UseBlockSparseIndices(const TensorShape &indices_shape, int32_t *indices_data)
Use blocksparse indices contained in the user allocated buffer. The shape of the index must be 2-D an...
Status MakeCsrStrings(size_t string_count, const char *const *strings, gsl::span< const int64_t > inner_index, gsl::span< const int64_t > outer_index)
The method allocates a single contiguous buffer and creates instances of std::strings in it...
MLDataType DataType() const noexcept
Return Element MLDataType
Read only access to Csr indices
Status MakeCsrData(const IDataTransfer &data_transfer, const OrtMemoryInfo &data_location, size_t values_count, const void *values_data, gsl::span< const int64_t > inner_index, gsl::span< const int64_t > outer_index)
The function will allocate a single contiguous buffer and will copy values and indices into it...
Tensor & Indices() noexcept
Status MakeBlockSparseData(const IDataTransfer &data_transfer, const OrtMemoryInfo &data_location, const TensorShape &values_shape, const void *values_data, const TensorShape &indices_shape, const int32_t *indices_data)
The function allocates a single contiguous buffer and copies values and index into it...
Gives mutable access to Coo buffers so they can be populated
int32_t GetDataType() const
int32_t GetElementType() const
Returns Tensor element type enum. Useful for type dispatching
Tensor & Outer() const noexcept
const TensorShape & Shape() const noexcept
static const SparseTensor & GetSparseTensorFromOrtValue(const OrtValue &v)
The function will check if the OrtValue is allocated fetch the containing SparseTensor instance or th...
This class implements SparseTensor. This class holds sparse non-zero data (values) and sparse format ...
const Tensor & Outer() const noexcept
BlockSparseView AsBlockSparse() const
Return BlockSparseIndex view
const Tensor & Inner() const noexcept
CooView(const Tensor &indices) noexcept
CsrView(const Tensor &inner, const Tensor &outer) noexcept
int64_t RequiredAllocationSize() const noexcept
Calculates and returns how much this fully initialized SparseTensor data (would) occupy in a contiguo...
PrimitiveDataTypeBase Base class for primitive Tensor contained types.
const Tensor & Values() const noexcept
Read only accessor to non-zero values
GLsizei const GLchar *const * strings
const TensorShape & DenseShape() const noexcept
Returns a would be dense_shape
Give writable access to Csr values and indices
bool IsDataType() const
Checks if the Tensor contains data type T
Read only access to BlockSparse index
SparseFormat
This is a Sparse Format enumeration.
std::shared_ptr< IAllocator > AllocatorPtr
GLenum GLsizei GLsizei GLint * values
const OrtMemoryInfo & Location() const noexcept
CooMutator(Tensor &values, Tensor &indices) noexcept
Tensor & Values() noexcept
ORT_DISALLOW_COPY_AND_ASSIGNMENT(SparseTensor)
Tensor & Values() noexcept
Status UseCsrIndices(gsl::span< int64_t > inner_index, gsl::span< int64_t > outer_index)
This function will use Csr indices contained within the user allocated buffers. The lifespan of the b...
Read only access to Coo indices
std::ostream & operator<<(std::ostream &out, AllocKind alloc_kind)
Tensor & Indices() noexcept
Status Copy(const DataTransferManager &data_transfer_manager, SparseTensor &dst_tensor) const
X-device copy. Destination tensor must have allocator set.
const Tensor & Indices() const noexcept
bool IsDataTypeString() const
Test for string type
BlockSparseView(const Tensor &indices) noexcept
Status UseCooIndices(gsl::span< int64_t > indices)
Uses COO index contained in the user allocated buffer along with the values buffer passed on to the c...