Go to the documentation of this file.
26 #ifndef TILEDARRAY_EXPRESSIONS_CONT_ENGINE_H__INCLUDED
27 #define TILEDARRAY_EXPRESSIONS_CONT_ENGINE_H__INCLUDED
38 namespace expressions {
41 template <
typename,
typename>
43 template <
typename,
typename,
typename>
49 template <
typename Derived>
124 const std::string& index_label,
unsigned int i,
125 const unsigned int n) {
127 if (
indices[i] == index_label)
break;
162 template <
typename L,
typename R>
171 template <
typename L,
typename R,
typename S>
194 this->
template init_indices_<TensorProduct::Contraction>(target_indices);
213 if (!children_initialized) {
214 left_.init_indices();
218 this->
template init_indices_<TensorProduct::Contraction>();
241 if constexpr (TiledArray::detail::is_tensor_of_tensor_v<value_type>) {
255 ? math::blas::Transpose
256 : math::blas::NoTranspose);
259 ? math::blas::Transpose
260 : math::blas::NoTranspose);
265 if constexpr (!TiledArray::detail::is_tensor_of_tensor_v<value_type>) {
280 if constexpr (!TiledArray::detail::is_tensor_of_tensor_v<value_type>) {
308 const unsigned int left_outer_rank = left_rank - inner_rank;
311 const auto* MADNESS_RESTRICT
const left_tiles_size =
312 left_.trange().tiles_range().extent_data();
313 const auto* MADNESS_RESTRICT
const left_element_size =
314 left_.trange().elements_range().extent_data();
315 const auto* MADNESS_RESTRICT
const right_tiles_size =
316 right_.trange().tiles_range().extent_data();
317 const auto* MADNESS_RESTRICT
const right_element_size =
318 right_.trange().elements_range().extent_data();
321 size_type M = 1ul, m = 1ul, N = 1ul, n = 1ul;
323 for (; i < left_outer_rank; ++i) {
324 M *= left_tiles_size[i];
325 m *= left_element_size[i];
327 for (; i < left_rank; ++i)
K_ *= left_tiles_size[i];
328 for (i = inner_rank; i < right_rank; ++i) {
329 N *= right_tiles_size[i];
330 n *= right_element_size[i];
354 const unsigned int left_outer_rank = left_rank - inner_rank;
358 unsigned int i = 0ul;
359 for (
unsigned int x = 0ul; x < left_outer_rank; ++x, ++i) {
360 const unsigned int pi = (perm ? perm[i] : i);
361 ranges[pi] =
left_.trange().data()[x];
363 for (
unsigned int x = inner_rank; x < right_rank; ++x, ++i) {
364 const unsigned int pi = (perm ? perm[i] : i);
365 ranges[pi] =
right_.trange().data()[x];
371 for (
unsigned int l = left_outer_rank, r = 0ul; l < left_rank; ++l, ++r) {
375 "The contracted dimensions of the left- "
376 "and right-hand arguments are not congruent:"
377 <<
"\n left = " <<
left_.trange()
378 <<
"\n right = " <<
right_.trange());
381 "The contracted dimensions of the left- and "
382 "right-hand expressions are not congruent.");
386 "The contracted dimensions of the left- and "
387 "right-hand expressions are not congruent.");
400 math::blas::NoTranspose, math::blas::NoTranspose,
412 math::blas::NoTranspose, math::blas::NoTranspose,
421 typename right_type::dist_eval_type,
422 op_type,
typename Derived::policy>
425 typename left_type::dist_eval_type left =
left_.make_dist_eval();
426 typename right_type::dist_eval_type right =
right_.make_dist_eval();
428 std::shared_ptr<impl_type> pimpl =
439 std::stringstream ss;
459 if constexpr (TiledArray::detail::is_tensor_of_tensor_v<value_type>) {
460 using inner_tile_type =
typename value_type::value_type;
462 TA_ASSERT(inner_prod == TensorProduct::Contraction ||
463 inner_prod == TensorProduct::Hadamard);
464 if (inner_prod == TensorProduct::Contraction) {
465 using inner_tile_type =
typename value_type::value_type;
466 using contract_inner_tile_type =
470 auto contrreduce_op =
472 ? contract_inner_tile_type(
480 : contract_inner_tile_type(
487 inner_tile_type& result,
488 const inner_tile_type& left,
489 const inner_tile_type& right) {
490 contrreduce_op(result, left, right);
492 }
else if (inner_prod == TensorProduct::Hadamard) {
497 if (this->factor_ == 1) {
500 inner_tile_type,
false,
false>;
504 auto mult_op = (inner_target_indices !=
inner(this->
indices_))
510 inner_tile_type& result,
511 const inner_tile_type& left,
512 const inner_tile_type& right) {
513 if (outer_prod == TensorProduct::Hadamard)
514 result = mult_op(left, right);
516 TA_ASSERT(outer_prod == TensorProduct::Hadamard ||
517 outer_prod == TensorProduct::Contraction);
522 result = mult_op(left, right);
524 auto result_increment = mult_op(left, right);
525 add_to(result, result_increment);
537 auto mult_op = (inner_target_indices !=
inner(this->
indices_))
538 ?
op_type(base_op_type(this->factor_),
541 :
op_type(base_op_type(this->factor_));
543 inner_tile_type& result,
544 const inner_tile_type& left,
545 const inner_tile_type& right) {
546 TA_ASSERT(outer_prod == TensorProduct::Hadamard ||
547 outer_prod == TensorProduct::Contraction);
548 if (outer_prod == TensorProduct::Hadamard)
549 result = mult_op(left, right);
555 result = mult_op(left, right);
557 auto result_increment = mult_op(left, right);
558 add_to(result, result_increment);
568 const inner_tile_type& left,
const inner_tile_type& right) {
569 inner_tile_type result;
570 inner_tile_nonreturn_op(result, left, right);
581 #endif // TILEDARRAY_EXPRESSIONS_CONT_ENGINE_H__INCLUDED
void init_indices(bool children_initialized=false)
Initialize the index list of this expression.
dist_eval_type make_dist_eval() const
auto outer_size(const IndexList &p)
Contraction to *GEMM helper.
shape_type shape_
The shape of the result tensor.
std::function< void(tile_element_type &, const tile_element_type &, const tile_element_type &)> inner_tile_nonreturn_op_
void inc()
Increment the number of tabs.
unsigned int left_rank() const
Left-hand argument rank accessor.
BipartiteIndexList right_indices_
Target right-hand index list.
PermutationType right_inner_permtype_
Right-hand permutation type.
PermutationType left_inner_permtype_
Left-hand permutation type.
right_type right_
The right-hand argument.
Tile scale-multiplication operation.
EngineTrait< Derived >::pmap_interface pmap_interface
Process map interface type.
PermutationType left_inner_permtype_
Left-hand permutation type.
derived_type & derived()
Cast this object to its derived type.
TensorProduct product_type_
Contract and (sum) reduce operation.
PermutationType left_outer_permtype_
Left-hand permutation type.
std::shared_ptr< pmap_interface > pmap_
The process map for the result tensor.
trange_type trange_
The tiled range of the result tensor.
TiledArray::detail::ContractReduce< value_type, typename eval_trait< typename left_type::value_type >::type, typename eval_trait< typename right_type::value_type >::type, scalar_type > op_type
The tile operation type.
Permutation of a sequence of objects indexed by base-0 indices.
Tile multiplication operation.
const math::GemmHelper & gemm_helper() const
Gemm meta data accessor.
auto outer(const IndexList &p)
trange_type trange_
The tiled range of the result tensor.
std::shared_ptr< pmap_interface > pmap_
The process map for the result tensor.
TensorProduct inner_product_type() const
TensorProduct inner_product_type_
std::shared_ptr< EngineParamOverride< Derived > > override_ptr_
The engine params overriding the default.
std::shared_ptr< Pmap > make_pmap() const
Construct a cyclic process.
BipartiteIndexList left_indices_
Target left-hand index list.
World * world_
The world where this expression will be evaluated.
std::string make_tag() const
Expression identification tag.
trange_type make_trange() const
Non-permuting tiled range factory function.
const BipartiteIndexList & indices() const
Index list accessor.
ContEngine< Derived > ContEngine_
This class type.
shape_type make_shape() const
Non-permuting shape factory function.
EngineTrait< Derived >::trange_type trange_type
Tiled range type.
EngineTrait< Derived >::dist_eval_type dist_eval_type
The distributed evaluator type.
BipartiteIndexList left_indices_
Target left-hand index list.
BipartitePermutation perm_
The permutation that will be applied to the outer tensor of tensors.
TiledArray::detail::ProcGrid proc_grid_
Process grid for the contraction.
EngineTrait< Derived >::scalar_type scalar_type
Tile scalar type.
Distributed contraction evaluator implementation.
BipartiteIndexList right_indices_
Target right-hand index list.
void perm_indices(const BipartiteIndexList &target_indices)
Set the index list for this expression.
auto inner(const IndexList &p)
BipartiteIndexList indices_
Binary tile operation wrapper.
blas::Op to_cblas_op(PermutationType permtype)
Multiplication expression.
#define TA_ASSERT(EXPR,...)
std::shared_ptr< Pmap > make_col_phase_pmap(const size_type rows) const
Construct column phased a cyclic process.
World & get_default_world()
unsigned int result_rank() const
Result rank accessor.
@ Hadamard
fused indices only
std::function< tile_element_type(const tile_element_type &, const tile_element_type &)> inner_tile_return_op_
EngineTrait< Derived >::size_type size_type
Size type.
ContEngine(const ScalMultExpr< L, R, S > &expr)
Constructor.
EngineTrait< Derived >::trange_type trange_type
Tiled range type.
right_type right_
The right-hand argument.
Tile< Result > & add_to(Tile< Result > &result, const Tile< Arg > &arg)
Add to the result tile.
EngineTrait< Derived >::left_type left_type
The left-hand expression type.
left_type left_
The left-hand argument.
World * world_
The world where this expression will be evaluated.
EngineTrait< Derived >::size_type size_type
Size type.
ExprEngine< Derived > ExprEngine_
Expression engine base class type.
static unsigned int find(const BipartiteIndexList &indices, const std::string &index_label, unsigned int i, const unsigned int n)
void print(ExprOStream os, const BipartiteIndexList &target_indices) const
Expression print.
Expression output stream.
void init_indices(const BipartiteIndexList &target_indices)
Initialize the index list of this expression.
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
Initialize result tensor distribution.
void init_struct(const BipartiteIndexList &target_indices)
Initialize result tensor structure.
void dec()
Decrement the number of tabs.
bool is_congruent(const BlockRange &r1, const BlockRange &r2)
Test that two BlockRange objects are congruent.
scalar_type factor_
Contraction scaling factor.
EngineTrait< Derived >::op_type op_type
The tile operation type.
op_type op_
Tile operation.
EngineTrait< Derived >::value_type value_type
The result tile type.
unsigned int right_rank() const
Right-hand argument rank accessor.
PermutationType left_outer_permtype_
Left-hand permutation type.
EngineTrait< Derived >::shape_type shape_type
Shape type.
TensorProduct
types of binary tensor products known to TiledArray
BipartitePermutation make_perm(const BipartiteIndexList &target_indices) const
Permutation factory function.
BipartiteIndexList indices_
ContEngine(const MultExpr< L, R > &expr)
Constructor.
void init_inner_tile_op(const IndexList &inner_target_indices)
Multiplication expression engine.
EngineTrait< Derived >::dist_eval_type dist_eval_type
The distributed evaluator type.
EngineTrait< Derived >::shape_type shape_type
Shape type.
unsigned int num_contract_ranks() const
Compute the number of contracted ranks.
TensorProduct product_type() const
bool empty(const Tile< Arg > &arg)
Check that arg is empty (no data)
EngineTrait< Derived >::policy policy
The result policy type.
EngineTrait< Derived >::right_type right_type
The right-hand expression type.
std::shared_ptr< Pmap > make_row_phase_pmap(const size_type cols) const
Construct row phased a cyclic process.
const BipartiteIndexList & indices() const
Index list accessor.
PermutationType right_inner_permtype_
Right-hand permutation type.
#define TA_USER_ERROR_MESSAGE(m)
trange_type make_trange(const Permutation &perm={}) const
Tiled range factory function.
shape_type shape_
The shape of the result tensor.
Determine the object type used in the evaluation of tensor expressions.
Multiplication expression.
shape_type make_shape(const Permutation &perm) const
Permuting shape factory function.
BinaryEngine< Derived > BinaryEngine_
Binary base class type.
PermutationType right_outer_permtype_
Right-hand permutation type.
typename value_type::value_type tile_element_type
Permutation of a bipartite set.
void print(ExprOStream &os, const BipartiteIndexList &target_indices) const
Expression print.
auto inner_size(const IndexList &p)
void init_distribution(World *world, std::shared_ptr< pmap_interface > pmap)
Initialize result tensor distribution.
left_type left_
The left-hand argument.
size_type K_
Inner dimension size.
PermutationType right_outer_permtype_
Right-hand permutation type.
BipartitePermutation perm_
The permutation that will be applied to the outer tensor of tensors.