YAKL
YAKL_intrinsics_any.h
Go to the documentation of this file.
1 
2 #pragma once
3 // Included by YAKL_intrinsics.h
4 
6 namespace yakl {
7  namespace intrinsics {
8 
9  template <class T, int rank, int myStyle>
10  inline bool any( Array<T,rank,memHost,myStyle> arr ) {
11  #ifdef YAKL_DEBUG
12  if (!arr.initialized()) { yakl_throw("ERROR: calling any on an array that has not been initialized"); }
13  #endif
14  bool any_true = false;
15  for (int i=0; i < arr.totElems(); i++) { if (arr.data()[i]) any_true = true; }
16  return any_true;
17  }
18 
19  template <class T, int rank, int myStyle>
20  inline bool any( Array<T,rank,memDevice,myStyle> arr , Stream stream = Stream() ) {
21  #ifdef YAKL_DEBUG
22  if (!arr.initialized()) { yakl_throw("ERROR: calling any on an array that has not been initialized"); }
23  #endif
24  ScalarLiveOut<bool> any_true(false,stream);
25  c::parallel_for( "YAKL_internal_any" , arr.totElems() , YAKL_LAMBDA (int i) { if (arr.data()[i]) any_true = true; },
26  DefaultLaunchConfig().set_stream(stream) );
27  return any_true.hostRead(stream);
28  }
29 
30  template <class T, int rank, unsigned D0, unsigned D1, unsigned D2, unsigned D3>
31  inline bool any( SArray<T,rank,D0,D1,D2,D3> const &arr ) {
32  bool any_true = false;
33  for (int i=0; i < arr.totElems(); i++) { if (arr.data()[i]) any_true = true; }
34  return any_true;
35  }
36 
37  template <class T, int rank, class B0, class B1, class B2, class B3>
38  inline bool any( FSArray<T,rank,B0,B1,B2,B3> const &arr ) {
39  bool any_true = false;
40  for (int i=0; i < arr.totElems(); i++) { if (arr.data()[i]) any_true = true; }
41  return any_true;
42  }
43 
44  }
45 }
47 
yakl::FSArray::totElems
static constexpr unsigned totElems()
Get the total number of array elements.
Definition: YAKL_FSArray.h:179
yakl::Stream
Implements the functionality of a stream for parallel kernel execution. If the Stream::create() metho...
Definition: YAKL_streams_events.h:394
yakl::c::parallel_for
void parallel_for(char const *str, Bounds< N, simple > const &bounds, F const &f, LaunchConfig< VecLen, B4B > config=LaunchConfig<>())
[ASYNCHRONOUS] Launch the passed functor in parallel.
yakl::ScalarLiveOut::hostRead
T hostRead(Stream stream=Stream()) const
Returns a host copy of the data. This is blocking.
Definition: YAKL_ScalarLiveOut.h:83
__YAKL_NAMESPACE_WRAPPER_END__
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
__YAKL_NAMESPACE_WRAPPER_BEGIN__
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
yakl::DefaultLaunchConfig
LaunchConfig<> DefaultLaunchConfig
This launch configuration sets vector length to the device default and B4B to false.
Definition: YAKL_LaunchConfig.h:77
yakl::ScalarLiveOut
Class to handle scalars that exist before kernels, are written to by kernels, and read after the kern...
Definition: YAKL_ScalarLiveOut.h:39
yakl::yakl_throw
YAKL_INLINE void yakl_throw(const char *msg)
Throw an error message. Works from the host or device.
Definition: YAKL_error.h:17
yakl::Array
This declares the yakl::Array class. Please see the yakl::styleC and yakl::styleFortran template spec...
Definition: YAKL_Array.h:40
yakl::CSArray
C-style array on the stack similar in nature to, e.g., float arr[ny][nx];
Definition: YAKL_CSArray.h:30
yakl
yakl::CSArray::totElems
static constexpr unsigned totElems()
Get the total number of array elements.
Definition: YAKL_CSArray.h:131
yakl::CSArray::data
YAKL_INLINE T * data() const
Get the underlying raw data pointer.
Definition: YAKL_CSArray.h:123
yakl::FSArray::data
YAKL_INLINE T * data() const
Get the underlying raw data pointer.
Definition: YAKL_FSArray.h:171
YAKL_LAMBDA
#define YAKL_LAMBDA
Used to create C++ lambda expressions passed to parallel_for and parallel_outer
Definition: YAKL_defines.h:128
yakl::FSArray
Fortran-style array on the stack similar in nature to, e.g., float arr[ny][nx];
Definition: YAKL_FSArray.h:53
yakl::intrinsics::any
bool any(Array< T, rank, memHost, myStyle > arr)
Definition: YAKL_intrinsics_any.h:10