inline typename CrsArrayType::crsarray_type create_crsarray( const std::string & label , const std::vector< std::vector< InputSizeType > > & input ) { typedef CrsArrayType output_type ; typedef std::vector< std::vector< InputSizeType > > input_type ; typedef typename output_type::entries_type entries_type ; typedef typename output_type::size_type size_type ; typedef typename Impl::assert_shape_is_rank_one< typename entries_type::shape_type >::type ok_rank ; typedef View< typename output_type::size_type [] , typename output_type::array_layout , typename output_type::device_type > work_type ; output_type output ; // Create the row map: const size_t length = input.size(); { work_type row_work( "tmp" , length + 1 ); typename work_type::HostMirror row_work_host = create_mirror_view( row_work ); size_t sum = 0 ; row_work_host[0] = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { row_work_host[i+1] = sum += input[i].size(); } deep_copy( row_work , row_work_host ); output.entries = entries_type( label , sum ); output.row_map = row_work ; } // Fill in the entries: { typename entries_type::HostMirror host_entries = create_mirror_view( output.entries ); size_t sum = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { for ( size_t j = 0 ; j < input[i].size() ; ++j , ++sum ) { host_entries( sum ) = input[i][j] ; } } deep_copy( output.entries , host_entries ); } return output ; }
inline typename StaticCrsGraphType::staticcrsgraph_type create_staticcrsgraph( const std::string & label , const std::vector< std::vector< InputSizeType > > & input ) { typedef StaticCrsGraphType output_type ; typedef typename output_type::entries_type entries_type ; static_assert( entries_type::rank == 1 , "Graph entries view must be rank one" ); typedef View< typename output_type::size_type [] , typename output_type::array_layout , typename output_type::execution_space > work_type ; output_type output ; // Create the row map: const size_t length = input.size(); { work_type row_work( "tmp" , length + 1 ); typename work_type::HostMirror row_work_host = create_mirror_view( row_work ); size_t sum = 0 ; row_work_host[0] = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { row_work_host[i+1] = sum += input[i].size(); } deep_copy( row_work , row_work_host ); output.entries = entries_type( label , sum ); output.row_map = row_work ; } // Fill in the entries: { typename entries_type::HostMirror host_entries = create_mirror_view( output.entries ); size_t sum = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { for ( size_t j = 0 ; j < input[i].size() ; ++j , ++sum ) { host_entries( sum ) = input[i][j] ; } } deep_copy( output.entries , host_entries ); } return output ; }
inline typename CrsArray< DataType , Arg1Type , Arg2Type , SizeType >::HostMirror create_mirror( const CrsArray<DataType,Arg1Type,Arg2Type,SizeType > & view ) { #if KOKKOSARRAY_MIRROR_VIEW_OPTIMIZE // Allow choice via type: return create_mirror_view( view ); #else // Force copy: typedef Impl::ViewAssignment< Impl::LayoutDefault > alloc ; typedef CrsArray< DataType , Arg1Type , Arg2Type , SizeType > crsarray_type ; typename crsarray_type::HostMirror tmp ; typename crsarray_type::row_map_type::HostMirror tmp_row_map ; // Allocation to match: alloc( tmp_row_map , view.row_map ); alloc( tmp.entries , view.entries ); // Assignment of 'const' from 'non-const' tmp.row_map = tmp_row_map ; // Deep copy: deep_copy( tmp_row_map , view.row_map ); deep_copy( tmp.entries , view.entries ); return tmp ; #endif }
void print_block_distance(std::ostream &out) { host_histogram_view host_copy = create_mirror_view(m_block_distance); Kokkos::deep_copy(host_copy, m_block_distance); for (int i=0, size = host_copy.size(); i<size; ++i) { out << host_copy[i] << " , "; } out << "\b\b\b " << std::endl; }
void print_length(std::ostream &out) { host_histogram_view host_copy = create_mirror_view(m_length); Kokkos::deep_copy(host_copy, m_length); for (int i=0, size = host_copy.dimension_0(); i<size; ++i) { out << host_copy[i] << " , "; } out << "\b\b\b " << std::endl; }
inline typename StaticCrsGraphType::staticcrsgraph_type create_staticcrsgraph( const std::string & label , const std::vector< InputSizeType > & input ) { typedef StaticCrsGraphType output_type ; //typedef std::vector< InputSizeType > input_type ; // unused typedef typename output_type::entries_type entries_type ; typedef View< typename output_type::size_type [] , typename output_type::array_layout , typename output_type::execution_space > work_type ; output_type output ; // Create the row map: const size_t length = input.size(); { work_type row_work( "tmp" , length + 1 ); typename work_type::HostMirror row_work_host = create_mirror_view( row_work ); size_t sum = 0 ; row_work_host[0] = 0 ; for ( size_t i = 0 ; i < length ; ++i ) { row_work_host[i+1] = sum += input[i]; } deep_copy( row_work , row_work_host ); output.entries = entries_type( label , sum ); output.row_map = row_work ; } return output ; }