Beispiel #1
0
    // copy memory from one gpu range to another
    void copy(const view_type &from, view_type &to) {
        assert(from.size()==to.size());
        assert(!from.overlaps(to));

        auto status = cudaMemcpy(
                reinterpret_cast<void*>(to.begin()),
                reinterpret_cast<const void*>(from.begin()),
                from.size()*sizeof(value_type),
                cudaMemcpyDeviceToDevice
        );
        if(status != cudaSuccess) {
            std::cerr << util::red("error") << " bad CUDA memcopy, unable to copy " << sizeof(T)*from.size() << " bytes from device to device";
            exit(-1);
        }
    }
Beispiel #2
0
    std::pair<CudaEvent, view_type>
    copy(const ArrayView<
                value_type,
                HostCoordinator<
                    value_type,
                    PinnedAllocator<
                        value_type,
                        alignment>>> &from,
         view_type &to) {
        assert(from.size()==to.size());

        #ifdef VERBOSE
        using oType = ArrayView< value_type, HostCoordinator< value_type, PinnedAllocator< value_type, alignment>>>;
        std::cout << util::pretty_printer<DeviceCoordinator>::print(*this)
                  << "::" << util::blue("copy") << "(asynchronous, " << from.size() << ")"
                  << "\n  " << util::type_printer<oType>::print() << " @ " << from.data()
                  << util::yellow(" -> ")
                  << util::type_printer<view_type>::print() << " @ " << to.data() << std::endl;
        #endif

        auto status = cudaMemcpy(
                reinterpret_cast<void*>(to.begin()),
                reinterpret_cast<const void*>(from.begin()),
                from.size()*sizeof(value_type),
                cudaMemcpyHostToDevice
        );
        if(status != cudaSuccess) {
            std::cerr << util::red("error") << " bad CUDA memcopy, unable to copy " << sizeof(T)*from.size() << " bytes from host to device";
            exit(-1);
        }

        CudaEvent event;
        return std::make_pair(event, to);
    }
Beispiel #3
0
    void MergeGroup::addImage(view_type const& image)
    {
        if (image.width() != width_ || image.height() != height_)
        {
            throw std::invalid_argument("Dimensions of image passed in differ to others in the sequence.");
        }

        if (pyramids_.size() == groupSize_)
        {
            throw std::invalid_argument("Group already contains enough images to fuse. Cannot add another.");
        }

        // TODO: do quality mask here, then create pyramid from Pending image

        // which image in the group is this
        size_t imageNum = pyramids_.size();

        // create subviews from arena for a single pyramid
        std::vector< view_type > subviews;
        for (auto& fuseView : fuseViews_)
        {
            subviews.push_back(fuseView[imageNum]);
        }

        // transfer input image into first level of pyramid
        std::copy(image.begin(), image.end(), subviews.front().begin());

        std::cout << "========================\n"
                     "Creating Pyramid.\n"
                     "========================"
                  << std::endl;
        ImagePyramid pyramid(context_, std::move(subviews),
                [=](Pending2DImage const& im)
                {
                    return createPyramidLevel(im, program_);
                });

        pyramids_.push_back(std::move(pyramid));
    }
Beispiel #4
0
int main()
{
	typedef float channel_type;

	typedef mizuiro::image::format<
		mizuiro::image::dimension<
			3
		>,
		mizuiro::image::interleaved<
			mizuiro::color::homogenous<
				channel_type,
				mizuiro::color::layout::rgba
			>
		>
	> format;

	typedef mizuiro::image::store<
		format,
		mizuiro::access::raw
	> store;

	store img(
		store::dim_type(
			100,
			100,
			100	
		)
	);

	typedef store::view_type view_type;

	typedef view_type::bound_type bound_type;

	// TODO: create an algorithm for this!
	{
		view_type const view(
			img.view()
		);

		typedef view_type::dim_type dim_type;

		typedef dim_type::size_type size_type;

		dim_type const dim(
			img.view().dim()
		);

		for(size_type x = 0; x < dim[0]; ++x)
			for(size_type y = 0; y < dim[1]; ++y)
				for(size_type z = 0; z < dim[2]; ++z)
					view[
						dim_type(
							x,
							y,
							z
						)
					]
					= mizuiro::color::object<
						format::color_format
					>(
						(mizuiro::color::init::red = static_cast<channel_type>(x))
						(mizuiro::color::init::green = static_cast<channel_type>(y))
						(mizuiro::color::init::blue = static_cast<channel_type>(z))
						(mizuiro::color::init::alpha = static_cast<channel_type>(255))
					);
	}

	std::cout << '\n';

	view_type const sub_view(
		mizuiro::image::sub_view(
			img.view(),
			bound_type(
				bound_type::dim_type(
					1,
					1,
					1
				),
				bound_type::dim_type(
					3,
					4,
					3	
				)
			)
		)
	);

	std::cout
		<< "sub image (with pitch "
		<< sub_view.pitch()
		<< ")\n";


	view_type const sub_sub_view(
		mizuiro::image::sub_view(
			sub_view,
			bound_type(
				bound_type::dim_type(
					1,	
					1,
					1
				),
				bound_type::dim_type(
					2,
					3,
					2
				)
			)
		)
	);

	std::cout
		<< "sub sub image (with pitch "
		<< sub_sub_view.pitch()
		<< ")\n";

	mizuiro::image::algorithm::print(
		std::cout,
		sub_sub_view
	);

	std::cout << '\n';

	{
		typedef std::reverse_iterator<
			view_type::iterator
		> reverse_iterator;

		for(
			reverse_iterator it(
				sub_sub_view.end()
			);
			it != reverse_iterator(sub_sub_view.begin());
			++it
		)
			std::cout << *it << ' ';
	}

	std::cout << '\n';
}