Blame c++/contourgl/cudacontext.h

Ivan Mahonin 383633
/*
Ivan Mahonin 383633
    ......... 2018 Ivan Mahonin
Ivan Mahonin 383633
Ivan Mahonin 383633
    This program is free software: you can redistribute it and/or modify
Ivan Mahonin 383633
    it under the terms of the GNU General Public License as published by
Ivan Mahonin 383633
    the Free Software Foundation, either version 3 of the License, or
Ivan Mahonin 383633
    (at your option) any later version.
Ivan Mahonin 383633
Ivan Mahonin 383633
    This program is distributed in the hope that it will be useful,
Ivan Mahonin 383633
    but WITHOUT ANY WARRANTY; without even the implied warranty of
Ivan Mahonin 383633
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Ivan Mahonin 383633
    GNU General Public License for more details.
Ivan Mahonin 383633
Ivan Mahonin 383633
    You should have received a copy of the GNU General Public License
Ivan Mahonin 383633
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
Ivan Mahonin 383633
*/
Ivan Mahonin 383633
Ivan Mahonin 383633
#ifndef _CUDACONTEXT_H_
Ivan Mahonin 383633
#define _CUDACONTEXT_H_
Ivan Mahonin 383633
Ivan Mahonin 383633
#include <vector>
Ivan Mahonin 383633
Ivan Mahonin 383633
#include <cuda.h>
Ivan Mahonin 383633
Ivan Mahonin 383633
Ivan Mahonin 383633
class CudaParams {
Ivan Mahonin 383633
private:
Ivan Mahonin 383633
	std::vector<char> params_buffer;
Ivan Mahonin 383633
	std::vector<int> params_offsets;
Ivan Mahonin 383633
	std::vector<void*> params_pointers;
Ivan Mahonin 383633
	std::vector<void*> params_extra;
Ivan Mahonin 383633
	size_t params_buffer_size;
Ivan Mahonin 383633
Ivan Mahonin 383633
public:
Ivan Mahonin 383633
	CudaParams();
Ivan Mahonin 383633
Ivan Mahonin 383633
	void reset();
Ivan Mahonin 383633
Ivan Mahonin 383633
	CudaParams& add(const void* data, int size, int align);
Ivan Mahonin 383633
Ivan Mahonin 383633
	template<typename T>
Ivan Mahonin 383633
	CudaParams& add(const T &data, int align)
Ivan Mahonin 383633
		{ return add(&data, sizeof(data), align); }
Ivan Mahonin 383633
Ivan Mahonin 383633
	template<typename T>
Ivan Mahonin 383633
	CudaParams& add(const T &data)
Ivan Mahonin 383633
		{ return add(data, __alignof(T)); }
Ivan Mahonin 383633
Ivan Mahonin 383633
	void** get_params() const
Ivan Mahonin 383633
		{ return params_pointers.empty() ? NULL : &(const_cast<CudaParams*>(this)->params_pointers.front()); }
Ivan Mahonin 383633
	void** get_extra() const
Ivan Mahonin 383633
		{ return params_extra.empty() ? NULL : &(const_cast<CudaParams*>(this)->params_extra.front()); }
Ivan Mahonin 383633
};
Ivan Mahonin 383633
Ivan Mahonin 383633
Ivan Mahonin 383633
class CudaContext {
Ivan Mahonin 383633
public:
Ivan Mahonin 383633
	CUdevice device;
Ivan Mahonin 383633
	CUcontext context;
Ivan Mahonin 383633
	CUresult err;
Ivan Mahonin 383633
Ivan Mahonin 383633
	CudaContext();
Ivan Mahonin 383633
	~CudaContext();
Ivan Mahonin 383633
Ivan Mahonin 383633
	void hello();
Ivan Mahonin 383633
};
Ivan Mahonin 383633
Ivan Mahonin 383633
#endif