예제 #1
0
func (ctx *Context) CreateImage(flags MemFlag, imageFormat ImageFormat, imageDesc ImageDescription, data []byte) (*MemObject, error) {
	format := imageFormat.toCl()
	desc := imageDesc.toCl()
	var dataPtr unsafe.Pointer
	if data != nil {
		dataPtr = unsafe.Pointer(&data[0])
	}
	var err C.cl_int
	clBuffer := C.clCreateImage(ctx.clContext, C.cl_mem_flags(flags), &format, &desc, dataPtr, &err)

	if err == C.CL_INVALID_OPERATION {
		// retry with deprecated functions
		switch imageDesc.Type {
		case MemObjectTypeImage2D:
			clBuffer = C.clCreateImage2D(ctx.clContext, C.cl_mem_flags(flags), &format,
				C.size_t(imageDesc.Width), C.size_t(imageDesc.Height), C.size_t(imageDesc.RowPitch), dataPtr, &err)
		}
	}

	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clBuffer == nil {
		return nil, ErrUnknown
	}
	return newMemObject(clBuffer, len(data)), nil
}
예제 #2
0
파일: image11.go 프로젝트: Dirbaio/gominer
func CLCreateImage3D(context CL_context,
	flags CL_mem_flags,
	image_format *CL_image_format,
	image_width CL_size_t,
	image_height CL_size_t,
	image_depth CL_size_t,
	image_row_pitch CL_size_t,
	image_slice_pitch CL_size_t,
	host_ptr unsafe.Pointer,
	errcode_ret *CL_int) CL_mem {

	var c_image_format C.cl_image_format
	var c_errcode_ret C.cl_int
	var c_image C.cl_mem

	c_image_format.image_channel_order = C.cl_channel_order(image_format.Image_channel_order)
	c_image_format.image_channel_data_type = C.cl_channel_type(image_format.Image_channel_data_type)

	c_image = C.clCreateImage3D(context.cl_context,
		C.cl_mem_flags(flags),
		&c_image_format,
		C.size_t(image_width),
		C.size_t(image_height),
		C.size_t(image_depth),
		C.size_t(image_row_pitch),
		C.size_t(image_slice_pitch),
		host_ptr,
		&c_errcode_ret)

	if errcode_ret != nil {
		*errcode_ret = CL_int(c_errcode_ret)
	}

	return CL_mem{c_image}
}
예제 #3
0
파일: package.go 프로젝트: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetSupportedImageFormats.html
func GetSupportedImageFormats(context Context, flags MemFlags, memObjectType MemObjectType, numEntries uint32, imageformats *ImageFormat, numImageFormat *uint32) ErrorCode {
	return ErrorCode(C.clGetSupportedImageFormats(context.clContext,
		C.cl_mem_flags(flags),
		C.cl_mem_object_type(memObjectType),
		C.cl_uint(numEntries),
		(*C.cl_image_format)(unsafe.Pointer(imageformats)),
		(*C.cl_uint)(numImageFormat)))
}
예제 #4
0
파일: image.go 프로젝트: xfong/gocl
func CLGetSupportedImageFormats(context CL_context,
	flags CL_mem_flags,
	image_type CL_mem_object_type,
	num_entries CL_uint,
	image_formats []CL_image_format,
	num_image_formats *CL_uint) CL_int {

	if (num_entries == 0 || image_formats == nil) && num_image_formats == nil {
		return CL_INVALID_VALUE
	} else {
		var c_num_image_formats C.cl_uint
		var c_errcode_ret C.cl_int

		if num_entries == 0 || image_formats == nil {
			c_errcode_ret = C.clGetSupportedImageFormats(context.cl_context,
				C.cl_mem_flags(flags),
				C.cl_mem_object_type(image_type),
				C.cl_uint(num_entries),
				nil,
				&c_num_image_formats)
		} else {
			c_image_formats := make([]C.cl_image_format, len(image_formats))
			c_errcode_ret = C.clGetSupportedImageFormats(context.cl_context,
				C.cl_mem_flags(flags),
				C.cl_mem_object_type(image_type),
				C.cl_uint(num_entries),
				&c_image_formats[0],
				&c_num_image_formats)
			if c_errcode_ret == C.CL_SUCCESS {
				for i := 0; i < len(image_formats); i++ {
					image_formats[i].Image_channel_data_type = CL_channel_type(c_image_formats[i].image_channel_data_type)
					image_formats[i].Image_channel_order = CL_channel_order(c_image_formats[i].image_channel_order)
				}
			}
		}

		if num_image_formats != nil {
			*num_image_formats = CL_uint(c_num_image_formats)
		}

		return CL_int(c_errcode_ret)
	}
}
예제 #5
0
파일: context.go 프로젝트: xfong/go-opencl
func (ctx *Context) CreateBufferUnsafe(flags MemFlag, size int, dataPtr unsafe.Pointer) (*MemObject, error) {
	var err C.cl_int
	clBuffer := C.clCreateBuffer(ctx.clContext, C.cl_mem_flags(flags), C.size_t(size), dataPtr, &err)
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clBuffer == nil {
		return nil, ErrUnknown
	}
	return newMemObject(clBuffer, size), nil
}
예제 #6
0
파일: memory.go 프로젝트: xfong/tmpCL
func (mobj *MemObject) CreateSubBuffer(flags MemFlag, origin, bSize int) (*MemObject, error) {
	var err C.cl_int
	clBuffer := C.CLcreateSubBuffer(mobj.clMem, C.cl_mem_flags(flags), (C.size_t)(origin), (C.size_t)(bSize), &err)
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clBuffer == nil {
		return nil, ErrUnknown
	}
	return newMemObject(clBuffer, bSize), nil
}
예제 #7
0
func (c *Context) NewBuffer(flags MemFlags, size uint32) (*Buffer, error) {
	var c_buffer C.cl_mem
	var err C.cl_int

	if c_buffer = C.clCreateBuffer(c.id, C.cl_mem_flags(flags), C.size_t(size), nil, &err); err != C.CL_SUCCESS {
		return nil, Cl_error(err)
	}

	buffer := &Buffer{id: c_buffer}
	runtime.SetFinalizer(buffer, (*Buffer).release)

	return buffer, nil
}
예제 #8
0
파일: image.go 프로젝트: xfong/tmpCL
func (ctx *Context) GetSupportedImageFormats(flags MemFlag, imageType MemObjectType) ([]ImageFormat, error) {
	var formats [maxImageFormats]C.cl_image_format
	var nFormats C.cl_uint
	if err := C.clGetSupportedImageFormats(ctx.clContext, C.cl_mem_flags(flags), C.cl_mem_object_type(imageType), maxImageFormats, &formats[0], &nFormats); err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	fmts := make([]ImageFormat, nFormats)
	for i, f := range formats[:nFormats] {
		fmts[i] = ImageFormat{
			ChannelOrder:    ChannelOrder(f.image_channel_order),
			ChannelDataType: ChannelDataType(f.image_channel_data_type),
		}
	}
	return fmts, nil
}
예제 #9
0
func (ctx *Context) CreateImage2D(flags MemFlag, imageFormat ImageFormat, width, height, rowPitch int, data []byte) (*MemObject, error) {
	format := imageFormat.toCl()
	var dataPtr unsafe.Pointer
	if data != nil {
		dataPtr = unsafe.Pointer(&data[0])
	}
	var err C.cl_int
	clBuffer := C.clCreateImage2D(ctx.clContext, C.cl_mem_flags(flags), &format, C.size_t(width), C.size_t(height), C.size_t(rowPitch), dataPtr, &err)
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clBuffer == nil {
		return nil, ErrUnknown
	}
	return newMemObject(clBuffer, len(data)), nil
}
예제 #10
0
파일: context.go 프로젝트: xfong/go-opencl
func (b *MemObject) CreateSubBufferRegion(flags MemFlag, origin int, size int) (*MemObject, error) {
	var err C.cl_int
	ci := C.cl_buffer_region{
		origin: C.size_t(origin),
		size:   C.size_t(size),
	}
	clBuffer := C.clCreateSubBuffer(b.clMem, C.cl_mem_flags(flags),
		C.CL_BUFFER_CREATE_TYPE_REGION, unsafe.Pointer(&ci), &err)
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clBuffer == nil {
		return nil, ErrUnknown
	}
	return newMemObject(clBuffer, size), nil
}
예제 #11
0
파일: image.go 프로젝트: xfong/tmpCL
//////////////// Abstract Functions ////////////////
func (ctx *Context) CreateImage(flags MemFlag, imageFormat ImageFormat, imageDesc ImageDescription, data []byte) (*MemObject, error) {
	format := imageFormat.toCl()
	desc := imageDesc.toCl()
	var dataPtr unsafe.Pointer
	if data != nil {
		dataPtr = unsafe.Pointer(&data[0])
	}
	var err C.cl_int
	clBuffer := C.clCreateImage(ctx.clContext, C.cl_mem_flags(flags), &format, &desc, dataPtr, &err)
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clBuffer == nil {
		return nil, ErrUnknown
	}
	return newMemObject(clBuffer, len(data)), nil
}
예제 #12
0
func (c *Context) NewImage3D(flags MemoryFlags, format ImageFormat, width, height, depth, rowPitch, slicePitch uint32, data *byte) (*Image, error) {
	var c_buffer C.cl_mem
	var err C.cl_int

	c_format := &C.cl_image_format{
		image_channel_order:     C.cl_channel_order(format.ChannelOrder),
		image_channel_data_type: C.cl_channel_type(format.ChannelDataType)}

	if c_buffer = C.clCreateImage3D(c.id, C.cl_mem_flags(flags), c_format, C.size_t(width), C.size_t(height), C.size_t(depth), C.size_t(rowPitch), C.size_t(slicePitch), unsafe.Pointer(data), &err); err != C.CL_SUCCESS {
		return nil, Cl_error(err)
	}

	image := &Image{id: c_buffer, format: format, properties: make(map[ImageProperty]Size)}
	runtime.SetFinalizer(image, (*Image).release)

	return image, nil
}
예제 #13
0
func (c *Context) NewImage3D(flags MemFlags, order ChannelOrder, dataType ChannelType, width, height, depth, rowPitch, slicePitch uint32, data *byte) (*Image, error) {
	var c_buffer C.cl_mem
	var err C.cl_int

	format := new(C.cl_image_format)
	format.image_channel_order = C.cl_channel_order(order)
	format.image_channel_data_type = C.cl_channel_type(dataType)

	if c_buffer = C.clCreateImage3D(c.id, C.cl_mem_flags(flags), format, C.size_t(width), C.size_t(height), C.size_t(depth), C.size_t(rowPitch), C.size_t(slicePitch), unsafe.Pointer(data), &err); err != C.CL_SUCCESS {
		return nil, Cl_error(err)
	}

	image := &Image{id: c_buffer, w: width, h: height, d: depth, hostptr: data}
	runtime.SetFinalizer(image, (*Image).release)

	return image, nil
}
예제 #14
0
파일: buffer.go 프로젝트: Dirbaio/gominer
func CLCreateBuffer(context CL_context,
	flags CL_mem_flags,
	size CL_size_t,
	host_ptr unsafe.Pointer,
	errcode_ret *CL_int) CL_mem {

	var c_errcode_ret C.cl_int
	var c_memobj C.cl_mem

	c_memobj = C.clCreateBuffer(context.cl_context,
		C.cl_mem_flags(flags),
		C.size_t(size),
		host_ptr,
		&c_errcode_ret)

	if errcode_ret != nil {
		*errcode_ret = CL_int(c_errcode_ret)
	}

	return CL_mem{c_memobj}
}
예제 #15
0
파일: buffer.go 프로젝트: Dirbaio/gominer
func CLCreateSubBuffer(buffer CL_mem,
	flags CL_mem_flags,
	buffer_create_type CL_buffer_create_type,
	buffer_create_info unsafe.Pointer,
	errcode_ret *CL_int) CL_mem {

	var c_errcode_ret C.cl_int
	var c_memobj C.cl_mem

	c_memobj = C.clCreateSubBuffer(buffer.cl_mem,
		C.cl_mem_flags(flags),
		C.cl_buffer_create_type(buffer_create_type),
		buffer_create_info,
		&c_errcode_ret)

	if errcode_ret != nil {
		*errcode_ret = CL_int(c_errcode_ret)
	}

	return CL_mem{c_memobj}
}
예제 #16
0
파일: image12.go 프로젝트: xfong/gocl
func CLCreateImage(context CL_context,
	flags CL_mem_flags,
	image_format *CL_image_format,
	image_desc *CL_image_desc,
	host_ptr unsafe.Pointer,
	errcode_ret *CL_int) CL_mem {

	var c_image_format C.cl_image_format
	var c_image_desc C.cl_image_desc
	var c_errcode_ret C.cl_int
	var c_image C.cl_mem

	c_image_format.image_channel_order = C.cl_channel_order(image_format.Image_channel_order)
	c_image_format.image_channel_data_type = C.cl_channel_type(image_format.Image_channel_data_type)

	c_image_desc.image_type = C.cl_mem_object_type(image_desc.Image_type)
	c_image_desc.image_width = C.size_t(image_desc.Image_width)
	c_image_desc.image_height = C.size_t(image_desc.Image_height)
	c_image_desc.image_depth = C.size_t(image_desc.Image_depth)
	c_image_desc.image_array_size = C.size_t(image_desc.Image_array_size)
	c_image_desc.image_row_pitch = C.size_t(image_desc.Image_row_pitch)
	c_image_desc.image_slice_pitch = C.size_t(image_desc.Image_slice_pitch)
	c_image_desc.num_mip_levels = C.cl_uint(image_desc.Num_mip_levels)
	c_image_desc.num_samples = C.cl_uint(image_desc.Num_samples)
	c_image_desc.buffer = image_desc.Buffer.cl_mem

	c_image = C.clCreateImage(context.cl_context,
		C.cl_mem_flags(flags),
		&c_image_format,
		&c_image_desc,
		host_ptr,
		&c_errcode_ret)

	if errcode_ret != nil {
		*errcode_ret = CL_int(c_errcode_ret)
	}

	return CL_mem{c_image}
}
예제 #17
0
파일: package.go 프로젝트: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html
func CreateImage3D(context Context, flags MemFlags, imageFormat ImageFormat, imageWidth, imageHeight, imageDepth, imageRowPitch, imageSlicePitch uint64, hostptr unsafe.Pointer, errcode *ErrorCode) Mem {
	return Mem(C.clCreateImage3D(context.clContext, C.cl_mem_flags(flags), imageFormat.toC(), C.size_t(imageWidth), C.size_t(imageHeight), C.size_t(imageDepth), C.size_t(imageRowPitch), C.size_t(imageSlicePitch), hostptr, (*C.cl_int)(unsafe.Pointer(errcode))))
}
예제 #18
0
파일: package.go 프로젝트: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html
func CreateBuffer(context Context, flags, paramValueSize MemFlags, hostPtr unsafe.Pointer, errcode *ErrorCode) Mem {
	return Mem(C.clCreateBuffer(context.clContext, C.cl_mem_flags(flags), C.size_t(paramValueSize), hostPtr, (*C.cl_int)(unsafe.Pointer(errcode))))
}