ALP User Documentation  0.8.preview
Algebraic Programming User Documentation
blas2.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2021 Huawei Technologies Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
27 #ifndef _H_GRB_BLAS2_BASE
28 #define _H_GRB_BLAS2_BASE
29 
30 #include <assert.h>
31 
32 #include <graphblas/backends.hpp>
33 #include <graphblas/blas1.hpp>
35 #include <graphblas/rc.hpp>
36 #include <graphblas/semiring.hpp>
37 
38 #include "config.hpp"
39 #include "matrix.hpp"
40 #include "vector.hpp"
41 
42 
43 namespace grb {
44 
235  template<
237  class Semiring,
238  typename IOType, typename InputType1, typename InputType2,
239  typename InputType3, typename InputType4,
240  typename Coords, typename RIT, typename CIT, typename NIT,
241  Backend backend
242  >
249  const Semiring &semiring = Semiring(),
250  const Phase &phase = EXECUTE,
251  const typename std::enable_if<
258  void >::type * const = nullptr
259  ) {
260 #ifdef _DEBUG
261  std::cerr << "Selected backend does not implement mxv "
262  << "(doubly-masked, semiring)\n";
263 #endif
264 #ifndef NDEBUG
265  const bool selected_backed_does_not_support_doubly_masked_mxv_sr = false;
266  assert( selected_backed_does_not_support_doubly_masked_mxv_sr );
267 #endif
268  (void) u;
269  (void) u_mask;
270  (void) A;
271  (void) v;
272  (void) v_mask;
273  (void) semiring;
274  return UNSUPPORTED;
275  }
276 
299  template<
301  class Semiring,
302  typename IOType, typename InputType1, typename InputType2,
303  typename InputType3, typename InputType4,
304  typename Coords, typename RIT, typename CIT, typename NIT,
305  enum Backend backend
306  >
313  const Semiring &semiring = Semiring(),
314  const Phase &phase = EXECUTE,
315  typename std::enable_if<
322  void >::type * = nullptr
323  ) {
324 #ifdef _DEBUG
325  std::cerr << "Selected backend does not implement doubly-masked grb::vxm\n";
326 #endif
327 #ifndef NDEBUG
328  const bool selected_backend_does_not_support_doubly_masked_vxm_sr = false;
329  assert( selected_backend_does_not_support_doubly_masked_vxm_sr );
330 #endif
331  (void) u;
332  (void) u_mask;
333  (void) v;
334  (void) v_mask;
335  (void) A;
336  (void) semiring;
337  return UNSUPPORTED;
338  }
339 
434  template<
435  typename Func, typename DataType,
436  typename RIT, typename CIT, typename NIT,
437  Backend implementation = config::default_backend,
438  typename... Args
439  >
441  const Func f,
443  Args...
444  ) {
445 #ifdef _DEBUG
446  std::cerr << "Selected backend does not implement grb::eWiseLambda (matrices)\n";
447 #endif
448 #ifndef NDEBUG
449  const bool selected_backend_does_not_support_matrix_eWiseLamba = false;
450  assert( selected_backend_does_not_support_matrix_eWiseLamba );
451 #endif
452  (void) f;
453  (void) A;
454  return UNSUPPORTED;
455  }
456 
457  // default (non-)implementations follow:
458 
471  template<
473  class Ring,
474  typename IOType, typename InputType1, typename InputType2,
475  typename InputType3,
476  typename RIT, typename CIT, typename NIT,
477  typename Coords,
478  enum Backend implementation = config::default_backend
479  >
485  const Ring &ring = Ring(),
486  const Phase &phase = EXECUTE,
487  typename std::enable_if<
489  void >::type * = nullptr
490  ) {
491 #ifdef _DEBUG
492  std::cerr << "Selected backend does not implement grb::mxv (output-masked)\n";
493 #endif
494 #ifndef NDEBUG
495  const bool backend_does_not_support_output_masked_mxv = false;
496  assert( backend_does_not_support_output_masked_mxv );
497 #endif
498  (void) u;
499  (void) mask;
500  (void) A;
501  (void) v;
502  (void) ring;
503  return UNSUPPORTED;
504  }
505 
518  template<
520  class Ring,
521  typename IOType, typename InputType1, typename InputType2,
522  typename Coords, typename RIT, typename CIT, typename NIT,
523  Backend implementation = config::default_backend
524  >
529  const Ring &ring,
530  typename std::enable_if<
532  >::type * = nullptr
533  ) {
534 #ifdef _DEBUG
535  std::cerr << "Selected backend does not implement grb::mxv\n";
536 #endif
537 #ifndef NDEBUG
538  const bool backend_does_not_support_mxv = false;
539  assert( backend_does_not_support_mxv );
540 #endif
541  (void) u;
542  (void) A;
543  (void) v;
544  (void) ring;
545  return UNSUPPORTED;
546  }
547 
560  template<
562  class Ring,
563  typename IOType, typename InputType1, typename InputType2,
564  typename InputType3,
565  typename Coords, typename RIT, typename CIT, typename NIT,
566  enum Backend implementation = config::default_backend
567  >
573  const Ring &ring = Ring(),
574  const Phase &phase = EXECUTE,
575  typename std::enable_if<
577  >::type * = nullptr
578  ) {
579 #ifdef _DEBUG
580  std::cerr << "Selected backend does not implement grb::vxm (output-masked)\n";
581 #endif
582 #ifndef NDEBUG
583  const bool selected_backend_does_not_support_output_masked_vxm = false;
584  assert( selected_backend_does_not_support_output_masked_vxm );
585 #endif
586  (void) u;
587  (void) mask;
588  (void) v;
589  (void) A;
590  (void) ring;
591  (void) phase;
592  return UNSUPPORTED;
593  }
594 
607  template<
609  class Ring,
610  typename IOType, typename InputType1, typename InputType2,
611  typename Coords, typename RIT, typename CIT, typename NIT,
612  enum Backend implementation = config::default_backend
613  >
618  const Ring &ring = Ring(),
619  const Phase &phase = EXECUTE,
620  typename std::enable_if<
622  >::type * = nullptr
623  ) {
624 #ifdef _DEBUG
625  std::cerr << "Selected backend does not implement grb::vxm\n";
626 #endif
627 #ifndef NDEBUG
628  const bool selected_backend_does_not_support_vxm = false;
629  assert( selected_backend_does_not_support_vxm );
630 #endif
631  (void) u;
632  (void) v;
633  (void) A;
634  (void) ring;
635  return UNSUPPORTED;
636  }
637 
651  template<
653  class AdditiveMonoid, class MultiplicativeOperator,
654  typename IOType, typename InputType1, typename InputType2,
655  typename InputType3, typename InputType4,
656  typename Coords, typename RIT, typename CIT, typename NIT,
657  Backend backend
658  >
665  const AdditiveMonoid &add = AdditiveMonoid(),
666  const MultiplicativeOperator &mul = MultiplicativeOperator(),
667  const Phase &phase = EXECUTE,
668  const typename std::enable_if<
676  !std::is_same< InputType2, void >::value,
677  void >::type * const = nullptr
678  ) {
679 #ifdef _DEBUG
680  std::cerr << "Selected backend does not implement vxm (doubly-masked)\n";
681 #endif
682 #ifndef NDEBUG
683  const bool selected_backed_does_not_support_doubly_masked_vxm = false;
684  assert( selected_backed_does_not_support_doubly_masked_vxm );
685 #endif
686  (void) u;
687  (void) mask;
688  (void) v;
689  (void) v_mask;
690  (void) A;
691  (void) add;
692  (void) mul;
693  return UNSUPPORTED;
694  }
695 
709  template<
711  class AdditiveMonoid, class MultiplicativeOperator,
712  typename IOType, typename InputType1, typename InputType2,
713  typename InputType3, typename InputType4,
714  typename Coords, typename RIT, typename CIT, typename NIT,
715  Backend backend
716  >
723  const AdditiveMonoid &add = AdditiveMonoid(),
724  const MultiplicativeOperator &mul = MultiplicativeOperator(),
725  const Phase &phase = EXECUTE,
726  const typename std::enable_if<
734  !std::is_same< InputType2,
735  void >::value, void >::type * const = nullptr
736  ) {
737 #ifdef _DEBUG
738  std::cerr << "Selected backend does not implement mxv (doubly-masked)\n";
739 #endif
740 #ifndef NDEBUG
741  const bool selected_backed_does_not_support_doubly_masked_mxv = false;
742  assert( selected_backed_does_not_support_doubly_masked_mxv );
743 #endif
744  (void) u;
745  (void) mask;
746  (void) A;
747  (void) v;
748  (void) v_mask;
749  (void) add;
750  (void) mul;
751  return UNSUPPORTED;
752  }
753 
767  template<
769  class AdditiveMonoid, class MultiplicativeOperator,
770  typename IOType, typename InputType1, typename InputType2,
771  typename InputType3,
772  typename Coords, typename RIT, typename CIT, typename NIT,
773  Backend backend
774  >
780  const AdditiveMonoid & add = AdditiveMonoid(),
781  const MultiplicativeOperator & mul = MultiplicativeOperator(),
782  const Phase &phase = EXECUTE,
783  const typename std::enable_if<
790  !std::is_same< InputType2, void >::value,
791  void >::type * const = nullptr
792  ) {
793 #ifdef _DEBUG
794  std::cerr << "Selected backend does not implement "
795  << "singly-masked monoid-op mxv\n";
796 #endif
797 #ifndef NDEBUG
798  const bool selected_backed_does_not_support_masked_monop_mxv = false;
799  assert( selected_backed_does_not_support_masked_monop_mxv );
800 #endif
801  (void) u;
802  (void) mask;
803  (void) A;
804  (void) v;
805  (void) add;
806  (void) mul;
807  return UNSUPPORTED;
808  }
809 
823  template<
825  class AdditiveMonoid, class MultiplicativeOperator,
826  typename IOType, typename InputType1, typename InputType2,
827  typename Coords, typename RIT, typename CIT, typename NIT,
828  Backend backend
829  >
834  const AdditiveMonoid &add = AdditiveMonoid(),
835  const MultiplicativeOperator &mul = MultiplicativeOperator(),
836  const Phase &phase = EXECUTE,
837  const typename std::enable_if<
843  !std::is_same< InputType2, void >::value,
844  void >::type * const = nullptr
845  ) {
846 #ifdef _DEBUG
847  std::cerr << "Selected backend does not implement vxm "
848  << "(unmasked, monoid-op version )\n";
849 #endif
850 #ifndef NDEBUG
851  const bool selected_backed_does_not_support_monop_vxm = false;
852  assert( selected_backed_does_not_support_monop_vxm );
853 #endif
854  (void) u;
855  (void) v;
856  (void) A;
857  (void) add;
858  (void) mul;
859  return UNSUPPORTED;
860  }
861 
875  template<
877  class AdditiveMonoid, class MultiplicativeOperator,
878  typename IOType, typename InputType1, typename InputType2,
879  typename InputType3,
880  typename Coords, typename RIT, typename CIT, typename NIT,
881  Backend implementation
882  >
888  const AdditiveMonoid &add = AdditiveMonoid(),
889  const MultiplicativeOperator &mul = MultiplicativeOperator(),
890  const Phase &phase = EXECUTE,
891  typename std::enable_if<
897  !std::is_same< InputType2, void >::value,
898  void >::type * = nullptr
899  ) {
900 #ifdef _DEBUG
901  std::cerr << "Selected backend does not implement grb::vxm (output-masked)\n";
902 #endif
903 #ifndef NDEBUG
904  const bool selected_backed_does_not_support_masked_monop_vxm = false;
905  assert( selected_backed_does_not_support_masked_monop_vxm );
906 #endif
907  (void) u;
908  (void) mask;
909  (void) v;
910  (void) A;
911  (void) add;
912  (void) mul;
913  return UNSUPPORTED;
914  }
915 
929  template<
931  class AdditiveMonoid, class MultiplicativeOperator,
932  typename IOType, typename InputType1, typename InputType2,
933  typename Coords, typename RIT, typename CIT, typename NIT,
934  Backend backend
935  >
940  const AdditiveMonoid &add = AdditiveMonoid(),
941  const MultiplicativeOperator &mul = MultiplicativeOperator(),
942  const Phase &phase = EXECUTE,
943  const typename std::enable_if<
949  !std::is_same< InputType2, void >::value,
950  void >::type * const = nullptr
951  ) {
952 #ifdef _DEBUG
953  std::cerr << "Selected backend does not implement grb::mxv (unmasked)\n";
954 #endif
955 #ifndef NDEBUG
956  const bool selected_backed_does_not_support_monop_mxv = false;
957  assert( selected_backed_does_not_support_monop_mxv );
958 #endif
959  (void) u;
960  (void) A;
961  (void) v;
962  (void) add;
963  (void) mul;
964  return UNSUPPORTED;
965  }
966 
969 } // namespace grb
970 
971 #endif // end _H_GRB_BLAS2_BASE
972 
Defines the ALP error codes.
This file contains a register of all backends that are either implemented, under implementation,...
An ALP/GraphBLAS matrix.
Definition: matrix.hpp:72
RC
Return codes of ALP primitives.
Definition: rc.hpp:47
A GraphBLAS vector.
Definition: vector.hpp:64
Specifies the ALP/GraphBLAS matrix container.
Used to inspect whether a given type is an ALP monoid.
Definition: type_traits.hpp:85
Speculatively assumes that the output container of the requested operation has enough capacity to com...
Definition: phase.hpp:257
Used to inspect whether a given type is an ALP semiring.
Definition: type_traits.hpp:66
Used to inspect whether a given type is an ALP/GraphBLAS object.
Definition: type_traits.hpp:130
Phase
Primitives with sparse ALP/GraphBLAS output containers may run into the issue where an appropriate gr...
Definition: phase.hpp:152
static constexpr Descriptor no_operation
Indicates no additional pre- or post-processing on any of the GraphBLAS function arguments.
Definition: descriptors.hpp:63
unsigned int Descriptor
Descriptors indicate pre- or post-processing for some or all of the arguments to an ALP/GraphBLAS cal...
Definition: descriptors.hpp:54
Defines all ALP/GraphBLAS descriptors.
RC vxm(Vector< IOType, backend, Coords > &u, const Vector< InputType3, backend, Coords > &u_mask, const Vector< InputType1, backend, Coords > &v, const Vector< InputType4, backend, Coords > &v_mask, const Matrix< InputType2, backend, RIT, CIT, NIT > &A, const Semiring &semiring=Semiring(), const Phase &phase=EXECUTE, typename std::enable_if< grb::is_semiring< Semiring >::value &&!grb::is_object< InputType1 >::value &&!grb::is_object< InputType2 >::value &&!grb::is_object< InputType3 >::value &&!grb::is_object< InputType4 >::value &&!grb::is_object< IOType >::value, void >::type *=nullptr)
Left-handed in-place doubly-masked sparse matrix times vector multiplication, .
Definition: blas2.hpp:307
Indicates that the execution of the requested primitive with the given arguments is not supported by ...
Definition: rc.hpp:129
RC mxv(Vector< IOType, backend, Coords > &u, const Vector< InputType3, backend, Coords > &u_mask, const Matrix< InputType2, backend, RIT, CIT, NIT > &A, const Vector< InputType1, backend, Coords > &v, const Vector< InputType4, backend, Coords > &v_mask, const Semiring &semiring=Semiring(), const Phase &phase=EXECUTE, const typename std::enable_if< grb::is_semiring< Semiring >::value &&!grb::is_object< IOType >::value &&!grb::is_object< InputType1 >::value &&!grb::is_object< InputType2 >::value &&!grb::is_object< InputType3 >::value &&!grb::is_object< InputType4 >::value, void >::type *const =nullptr)
Right-handed in-place doubly-masked sparse matrix times vector multiplication, .
Definition: blas2.hpp:243
Backend
A collection of all backends.
Definition: backends.hpp:49
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:477
Specifies the ALP/GraphBLAS vector container.
Provides an ALP semiring.
Defines both configuration parameters effective for all backends, as well as defines structured ways ...
RC eWiseLambda(const Func f, const Vector< DataType, backend, Coords > &x, Args...)
Executes an arbitrary element-wise user-defined function f on any number of vectors of equal length.
Definition: blas1.hpp:3746
A generalised semiring.
Definition: semiring.hpp:190
Used to inspect whether a given type is an ALP operator.
Definition: type_traits.hpp:104