Beispiel #1
0
GIL_FORCEINLINE void tbb_copy_pixels( const View1& src, const View2& dst)
{ 
    assert(src.dimensions()==dst.dimensions());
    tbb::parallel_for( tbb::blocked_range<std::size_t>( 0, src.height()),
                        detail::make_tbb_copy_pixels_fun( src, dst),
                        GIL_TBB_ALGORITHMS_DEFAULT_PARTITIONER());
}
Beispiel #2
0
 ExecStatus
 Nq<View0,View1>::post(Home home, View0 x0, View1 x1){
   if (x0.assigned() && x1.assigned()) {
     if (overlap(x0.val(),x1.val()))
       return ES_FAILED;
   } else if (same(x0,x1)) {
     return ES_FAILED;
   } else {
     (void) new (home) Nq<View0,View1>(home,x0,x1);
   }
   return ES_OK;
 }
Beispiel #3
0
 void operator () (View1 to, View2 from)
 {
     auto w = std::min(to.GetWidth(), from.GetWidth());
     auto h = std::min(to.GetHeight(), from.GetHeight());
     for (size_t i = 0; i < h; i++)
     {
         auto p1 = to.BeginRow(i);
         auto p2 = from.BeginRow(i);
         for (size_t j = 0; j < w; j++, p1++, p2++)
         {
             *p1 = *p2;
         }
     }
 }
Beispiel #4
0
void
check_not_alias(
  View1<T1, Block1>& vec1,
  View2<T2, Block2>& vec2)
{
  fill_block(vec1.block(), 2);
  fill_block(vec2.block(), 3);

  // Make sure that updates to vec2 do not affect vec1.
  test_assert(check_vector(vec1, 2));

  // And visa-versa.
  fill_block(vec1.block(), 4);
  test_assert(check_vector(vec2, 3));
}
Beispiel #5
0
GIL_FORCEINLINE
F transform_pixels_progress( const View1& src, const View2& dst, const F& fun, IProgress& p )
{
	assert( src.dimensions() == dst.dimensions() );
	for( std::ptrdiff_t y = 0; y < src.height(); ++y )
	{
		typename View1::x_iterator srcIt = src.row_begin( y );
		typename View2::x_iterator dstIt = dst.row_begin( y );
		for( std::ptrdiff_t x = 0; x < src.width(); ++x )
			dstIt[x] = fun( srcIt[x] );
		if( p.progressForward( dst.width() ) )
			return fun;
	}
	return fun;
}
Beispiel #6
0
void
apply_ukernel(View0 in0,
	      View1 in1,
	      View2 in2,
	      View3 out)
{
  dda::Ext_data<typename View0::block_type> ext0(in0.block());
  dda::Ext_data<typename View1::block_type> ext1(in1.block());
  dda::Ext_data<typename View2::block_type> ext2(in2.block());
  dda::Ext_data<typename View3::block_type> ext3(out.block());

  assert(ext0.stride(1) == 1);
  assert(ext1.stride(1) == 1);
  assert(ext2.stride(1) == 1);
  assert(ext3.stride(1) == 1);

  example::Cblock kernel((uintptr_t)ext0.data(), ext0.stride(0),
			 (uintptr_t)ext1.data(), ext1.stride(0),
			 (uintptr_t)ext2.data(), ext2.stride(0),
			 (uintptr_t)ext3.data(), ext3.stride(0),
			 out.size(0), out.size(1));
  
  vsip_csl::ukernel::Ukernel<example::Cblock> uk(kernel);

  uk();
}
Beispiel #7
0
GIL_FORCEINLINE void tbb_transform3_pixels( const View1& src1, const View2& src2,
                                            const View3& src3, const View4& dst, Fun f)
{
    tbb::parallel_for( tbb::blocked_range<std::size_t>( 0, src1.height()), 
                        detail::make_tbb_transform3_pixels_fun( src1, src2, src3, dst, f),
                        GIL_TBB_ALGORITHMS_DEFAULT_PARTITIONER());
}
Beispiel #8
0
void
apply_ukernel(View0 in0,
	      View1 in1,
	      View2 in2,
	      View3 out)
{
  dda::Data<typename View0::block_type, dda::in> data0(in0.block());
  dda::Data<typename View1::block_type, dda::in> data1(in1.block());
  dda::Data<typename View2::block_type, dda::in> data2(in2.block());
  dda::Data<typename View3::block_type, dda::out> data3(out.block());

  assert(data0.stride(1) == 1);
  assert(data1.stride(1) == 1);
  assert(data2.stride(1) == 1);
  assert(data3.stride(1) == 1);

  example::Cblock kernel((uintptr_t)data0.ptr(), data0.stride(0),
			 (uintptr_t)data1.ptr(), data1.stride(0),
			 (uintptr_t)data2.ptr(), data2.stride(0),
			 (uintptr_t)data3.ptr(), data3.stride(0),
			 out.size(0), out.size(1));
  
  vsip_csl::ukernel::Ukernel<example::Cblock> uk(kernel);

  uk();
}
Beispiel #9
0
GIL_FORCEINLINE F transform_pixels_locator(const View1& src1, const Rect<std::ptrdiff_t>& src1Rod, const View2& src2,
                                           const Rect<std::ptrdiff_t>& src2Rod, const View2& src3,
                                           const Rect<std::ptrdiff_t>& src3Rod, const ViewDst& dst,
                                           const Rect<std::ptrdiff_t>& dstRod, const Rect<std::ptrdiff_t>& renderWin,
                                           const F& fun)
{
    const std::ptrdiff_t renderWidth = renderWin.x2 - renderWin.x1;
    typename View1::xy_locator s1loc = src1.xy_at(renderWin.x1 - src1Rod.x1, renderWin.y1 - src1Rod.y1);
    typename View2::xy_locator s2loc = src2.xy_at(renderWin.x1 - src2Rod.x1, renderWin.y1 - src2Rod.y1);
    typename View3::xy_locator s3loc = src3.xy_at(renderWin.x1 - src3Rod.x1, renderWin.y1 - src3Rod.y1);
    for(std::ptrdiff_t y = renderWin.y1; y < renderWin.y2; ++y)
    {
        typename ViewDst::x_iterator dstIt = dst.x_at(dstRod.x1, y - dstRod.y1);
        for(std::ptrdiff_t x = renderWin.x1; x < renderWin.x2; ++x, ++s1loc.x(), ++s2loc.x(), ++s3loc.x(), ++dstIt)
        {
            *dstIt = fun(s1loc, s2loc, s3loc);
        }
        s1loc.x() -= renderWidth;
        ++s1loc.y();
        s2loc.x() -= renderWidth;
        ++s2loc.y();
        s3loc.x() -= renderWidth;
        ++s3loc.y();
    }
    return fun;
}
Beispiel #10
0
GIL_FORCEINLINE
F transform_pixels_locator_progress( const View1& src1, const OfxRectI& src1Rod,
									 const View2& src2, const OfxRectI& src2Rod,
									 const ViewDst& dst, const OfxRectI& dstRod,
									 const OfxRectI& renderWin, const F& fun, IProgress& p )
{
	const std::ptrdiff_t renderWidth = renderWin.x2 - renderWin.x1;
	typename View1::xy_locator s1loc = src1.xy_at( renderWin.x1-src1Rod.x1, renderWin.y1-src1Rod.y1 );
	typename View2::xy_locator s2loc = src2.xy_at( renderWin.x1-src2Rod.x1, renderWin.y1-src2Rod.y1 );
	for( std::ptrdiff_t y = renderWin.y1; y < renderWin.y2; ++y )
	{
		typename ViewDst::x_iterator dstIt = dst.x_at( dstRod.x1, y-dstRod.y1 );
		for( std::ptrdiff_t x = renderWin.x1;
		     x < renderWin.x2;
		     ++x, ++s1loc.x(), ++s2loc.x(), ++dstIt )
		{
			*dstIt = fun( s1loc, s2loc );
		}
		s1loc.x() -= renderWidth; ++s1loc.y();
		s2loc.x() -= renderWidth; ++s2loc.y();
		if( p.progressForward( renderWidth ) )
			return fun;
	}
	return fun;
}
Beispiel #11
0
GIL_FORCEINLINE
F transform_pixels_progress( const View1& src1, const View2& src2, const View3& src3, const View4& dst, const F& fun, IProgress& p )
{
	assert( src1.dimensions() == dst.dimensions() );
	assert( src2.dimensions() == dst.dimensions() );
	assert( src3.dimensions() == dst.dimensions() );
	for( std::ptrdiff_t y = 0; y < dst.height(); ++y )
	{
		typename View1::x_iterator srcIt1 = src1.row_begin( y );
		typename View2::x_iterator srcIt2 = src2.row_begin( y );
		typename View3::x_iterator srcIt3 = src3.row_begin( y );
		typename View4::x_iterator dstIt  = dst.row_begin( y );
		for( std::ptrdiff_t x = 0; x < dst.width(); ++x )
			dstIt[x] = fun( srcIt1[x], srcIt2[x], srcIt3[x] );
		if( p.progressForward( dst.width() ) )
			return fun;
	}
	return fun;
}
inline void checkNewViewWasAllocated( View1 const &v1, View2 const &v2 )
{
    BOOST_TEST( v1.data() != v2.data() );

    BOOST_TEST( (int)View1::rank == (int)View2::rank );
    BOOST_TEST( ( std::is_same<typename View1::const_value_type,
                               typename View2::const_value_type>::value ) );

    BOOST_TEST( v1.dimension_0() == v2.dimension_0() );
    BOOST_TEST( v1.dimension_1() == v2.dimension_1() );
    BOOST_TEST( v1.dimension_2() == v2.dimension_2() );
    BOOST_TEST( v1.dimension_3() == v2.dimension_3() );
    BOOST_TEST( v1.dimension_4() == v2.dimension_4() );
    BOOST_TEST( v1.dimension_5() == v2.dimension_5() );
    BOOST_TEST( v1.dimension_6() == v2.dimension_6() );
    BOOST_TEST( v1.dimension_7() == v2.dimension_7() );
}
Beispiel #13
0
void
check_alias(
  View1<T1, Block1>& vec1,
  View2<T2, Block2>& vec2)
{
  fill_block(vec1.block(), 2);
  test_assert(check_vector(vec1, 2));
  test_assert(check_vector(vec2, 2));

  fill_block(vec2.block(), 3);
  test_assert(check_vector(vec1, 3));
  test_assert(check_vector(vec2, 3));
}
Beispiel #14
0
 ExecStatus PartitionN<View0,View1>::post(Home home, ViewArray<View0>& x,
                                          View1 y) {
   switch (x.size()) {
   case 0:
     GECODE_ME_CHECK(y.cardMax(home, 0));
     return ES_OK;
   case 1:
     return Rel::Eq<View0,View1>::post(home, x[0], y);
   default:
     (void) new (home) PartitionN<View0,View1>(home,x,y);
     return ES_OK;
   }
 }
inline void checkViewWasNotAllocated( View1 const &v1, View2 const &v2 )
{
    // NOTE: cannot use operator== here because array layout may "change" for
    // rank-1 views
    BOOST_TEST( v1.data() == v2.data() );
    BOOST_TEST( v1.span() == v2.span() );

    BOOST_TEST( (int)View1::rank == (int)View2::rank );
    BOOST_TEST( ( std::is_same<typename View1::const_value_type,
                               typename View2::const_value_type>::value ) );
    BOOST_TEST( ( std::is_same<typename View1::memory_space,
                               typename View2::memory_space>::value ) );

    BOOST_TEST( v1.dimension_0() == v2.dimension_0() );
    BOOST_TEST( v1.dimension_1() == v2.dimension_1() );
    BOOST_TEST( v1.dimension_2() == v2.dimension_2() );
    BOOST_TEST( v1.dimension_3() == v2.dimension_3() );
    BOOST_TEST( v1.dimension_4() == v2.dimension_4() );
    BOOST_TEST( v1.dimension_5() == v2.dimension_5() );
    BOOST_TEST( v1.dimension_6() == v2.dimension_6() );
    BOOST_TEST( v1.dimension_7() == v2.dimension_7() );
}
inline void checkNewViewWasAllocated( View1 const &v1, View2 const &v2,
                                      bool &success,
                                      Teuchos::FancyOStream &out )
{
    TEST_INEQUALITY( v1.data(), v2.data() );

    TEST_EQUALITY( (int)View1::rank, (int)View2::rank );
    TEST_ASSERT( ( std::is_same<typename View1::const_value_type,
                                typename View2::const_value_type>::value ) );

    TEST_EQUALITY( v1.dimension_0(), v2.dimension_0() );
    TEST_EQUALITY( v1.dimension_1(), v2.dimension_1() );
    TEST_EQUALITY( v1.dimension_2(), v2.dimension_2() );
    TEST_EQUALITY( v1.dimension_3(), v2.dimension_3() );
    TEST_EQUALITY( v1.dimension_4(), v2.dimension_4() );
    TEST_EQUALITY( v1.dimension_5(), v2.dimension_5() );
    TEST_EQUALITY( v1.dimension_6(), v2.dimension_6() );
    TEST_EQUALITY( v1.dimension_7(), v2.dimension_7() );
}
inline void checkViewWasNotAllocated( View1 const &v1, View2 const &v2,
                                      bool &success,
                                      Teuchos::FancyOStream &out )
{
    // NOTE: cannot use operator== here because array layout may "change" for
    // rank-1 views
    TEST_EQUALITY( v1.data(), v2.data() );
    TEST_EQUALITY( v1.span(), v2.span() );

    TEST_EQUALITY( (int)View1::rank, (int)View2::rank );
    TEST_ASSERT( ( std::is_same<typename View1::const_value_type,
                                typename View2::const_value_type>::value ) );
    TEST_ASSERT( ( std::is_same<typename View1::memory_space,
                                typename View2::memory_space>::value ) );

    TEST_EQUALITY( v1.dimension_0(), v2.dimension_0() );
    TEST_EQUALITY( v1.dimension_1(), v2.dimension_1() );
    TEST_EQUALITY( v1.dimension_2(), v2.dimension_2() );
    TEST_EQUALITY( v1.dimension_3(), v2.dimension_3() );
    TEST_EQUALITY( v1.dimension_4(), v2.dimension_4() );
    TEST_EQUALITY( v1.dimension_5(), v2.dimension_5() );
    TEST_EQUALITY( v1.dimension_6(), v2.dimension_6() );
    TEST_EQUALITY( v1.dimension_7(), v2.dimension_7() );
}
Beispiel #18
0
 ExecStatus
 Eq<View0,View1>::post(Home home, View0 x0, View1 x1){
   if (x0.assigned()) {
     GECODE_ME_CHECK(x1.eq(home,x0.val()));
   } else if (x1.assigned()) {
     GECODE_ME_CHECK(x0.eq(home,x1.val()));
   } else if (!same(x0,x1)) {
     GECODE_ME_CHECK(x0.lq(home,x1.max()));
     GECODE_ME_CHECK(x1.lq(home,x0.max()));
     GECODE_ME_CHECK(x0.gq(home,x1.min()));
     GECODE_ME_CHECK(x1.gq(home,x0.min()));
     (void) new (home) Eq<View0,View1>(home,x0,x1);
   }
   return ES_OK;
 }
Beispiel #19
0
 ExecStatus
 Distinct<View0,View1>::post(Home home, View0 x, View1 y) {
   if (x.assigned()) {
     GlbRanges<View0> xr(x);
     IntSet xs(xr);
     ConstSetView cv(home, xs);
     GECODE_ES_CHECK((DistinctDoit<View1>::post(home,y,cv)));
   }
   if (y.assigned()) {
     GlbRanges<View1> yr(y);
     IntSet ys(yr);
     ConstSetView cv(home, ys);
     GECODE_ES_CHECK((DistinctDoit<View0>::post(home,x,cv)));
   }
   (void) new (home) Distinct<View0,View1>(home,x,y);
   return ES_OK;
 }
 AssignFunctor( const View1 view_1, View2 view_2 )
     : _view_1( view_1 )
     , _view_2( view_2 )
 {
     static_assert( std::is_same<typename View1::traits::value_type,
                                 typename View2::traits::value_type>::value,
                    "View data types must be the same" );
     static_assert( std::is_same<typename View1::traits::device_type,
                                 typename View2::traits::device_type>::value,
                    "View device types must be the same" );
     static_assert( static_cast<unsigned>( View1::Rank ) == 2,
                    "View ranks must be 2" );
     static_assert( static_cast<unsigned>( View2::Rank ) == 2,
                    "View ranks must be 2" );
     DTK_REQUIRE( view_1.extent( 0 ) == view_2.extent( 0 ) );
     DTK_REQUIRE( view_1.extent( 1 ) == view_2.extent( 1 ) );
 }