Exemple #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
}
Exemple #2
0
//////////////// 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
}
Exemple #3
0
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}
}