Beispiel #1
0
func (b *MemObject) GetFlags() (MemFlag, error) {
	if b.clMem != nil {
		var tmp C.cl_mem_flags
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_FLAGS, C.size_t(unsafe.Sizeof(tmp)), unsafe.Pointer(&tmp), nil)
		if toError(err) != nil {
			return -1, toError(err)
		}
		switch {
		case tmp == C.CL_MEM_READ_WRITE:
			return MemReadWrite, nil
		case tmp == C.CL_MEM_WRITE_ONLY:
			return MemWriteOnly, nil
		case tmp == C.CL_MEM_READ_ONLY:
			return MemReadOnly, nil
		case tmp == C.CL_MEM_USE_HOST_PTR:
			return MemUseHostPtr, nil
		case tmp == C.CL_MEM_ALLOC_HOST_PTR:
			return MemAllocHostPtr, nil
		case tmp == C.CL_MEM_COPY_HOST_PTR:
			return MemCopyHostPtr, nil
		default:
			return -1, nil
		}
	}
	return -1, toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #2
0
func (b *MemObject) GetDX9SurfaceInfo() (unsafe.Pointer, error) {
	if b.clMem != nil {
		var val C.cl_dx9_surface_info_khr
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR, (C.size_t)(unsafe.Sizeof(val)), unsafe.Pointer(&val), nil)
		if toError(err) != nil {
			return nil, toError(err)
		}
		return (unsafe.Pointer)(&val), nil
	}
	return nil, toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #3
0
func (b *MemObject) GetD3D10Resource() (*C.ID3D10Resource, error) {
	if b.clMem != nil {
		var val C.ID3D10Resource
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_D3D10_RESOURCE_KHR, (C.size_t)(unsafe.Sizeof(val)), unsafe.Pointer(&val), nil)
		if toError(err) != nil {
			return nil, toError(err)
		}
		return &val, nil
	}
	return nil, toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #4
0
func (b *MemObject) GetOffset() (int, error) {
	if b.clMem != nil {
		var tmp C.size_t
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_OFFSET, C.size_t(unsafe.Sizeof(tmp)), unsafe.Pointer(&tmp), nil)
		if toError(err) != nil {
			return int(-1), toError(err)
		}
		return int(tmp), nil
	}
	return 0, toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #5
0
func (b *MemObject) GetHostPtr() (unsafe.Pointer, error) {
	if b.clMem != nil {
		var tmp unsafe.Pointer
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_HOST_PTR, C.size_t(unsafe.Sizeof(tmp)), unsafe.Pointer(&tmp), nil)
		if toError(err) != nil {
			return nil, toError(err)
		}
		return tmp, nil
	}
	return nil, toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #6
0
func (b *MemObject) GetRefenceCount() (int, error) {
	if b.clMem != nil {
		var tmp C.cl_uint
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_REFERENCE_COUNT, C.size_t(unsafe.Sizeof(tmp)), unsafe.Pointer(&tmp), nil)
		if toError(err) != nil {
			return 0, toError(err)
		}
		return int(tmp), nil
	}
	return 0, toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #7
0
func (b *MemObject) GetContext() (*Context, error) {
	if b.clMem != nil {
		var tmp C.cl_context
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_CONTEXT, C.size_t(unsafe.Sizeof(tmp)), unsafe.Pointer(&tmp), nil)
		if toError(err) != nil {
			return nil, nil
		}
		return &Context{clContext: tmp, devices: nil}, toError(err)
	}
	return nil, toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #8
0
func (b *MemObject) GetAssociatedMemObject() (*MemObject, error) {
	if b.clMem != nil {
		var tmp C.cl_mem
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_ASSOCIATED_MEMOBJECT, C.size_t(unsafe.Sizeof(tmp)), unsafe.Pointer(&tmp), nil)
		if toError(err) != nil {
			return nil, toError(err)
		}
		tmpObj := newMemObject(tmp, 0)
		val, errTmp := tmpObj.GetSize()
		if errTmp != nil {
			fmt.Printf("Failed to get size of associated memobject: %+v \n", err)
			return newMemObject(tmp, 0), nil
		}
		return newMemObject(tmp, val), nil
	}
	return nil, toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #9
0
func (b *MemObject) GetDX9MediaAdapterType() (CLDX9AdapterType, error) {
	if b.clMem != nil {
		var val C.cl_dx9_media_adapter_type_khr
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR, (C.size_t)(unsafe.Sizeof(val)), unsafe.Pointer(&val), nil)
		if toError(err) != nil {
			return -1, toError(err)
		}
		switch val {
		default:
			return -1, toError(err)
		case C.CL_CONTEXT_ADAPTER_D3D9_KHR:
			return CLDX9Adapter, nil
		case C.CL_CONTEXT_ADAPTER_D3D9EX_KHR:
			return CLDX9EXAdapter, nil
		case C.CL_CONTEXT_ADAPTER_DXVA_KHR:
			return CLDXVAAdapter, nil
		}
	}
	return -1, toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #10
0
func (b *MemObject) GetType() (string, error) {
	if b.clMem != nil {
		var tmp C.cl_mem_object_type
		err := C.clGetMemObjectInfo(b.clMem, C.CL_MEM_TYPE, C.size_t(unsafe.Sizeof(tmp)), unsafe.Pointer(&tmp), nil)
		if toError(err) != nil {
			return "Unknown", toError(err)
		}
		switch {
		case MemObjectType(tmp) == MemObjectTypeBuffer:
			return "Buffer", nil
		case MemObjectType(tmp) == MemObjectTypeImage2D:
			return "Image2D", nil
		case MemObjectType(tmp) == MemObjectTypeImage3D:
			return "Image3D", nil
		default:
			return "Unknown", nil
		}
	}
	return "Unknown", toError(C.CL_INVALID_MEM_OBJECT)
}
Beispiel #11
0
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetMemObjectInfo.html
func GetMemObjectInfo(mem Mem, paramName MemInfo, paramValueSize uint64, paramValue unsafe.Pointer, paramValueSizeRet *uint64) ErrorCode {
	return ErrorCode(C.clGetMemObjectInfo(mem, C.cl_mem_info(paramName), C.size_t(paramValueSize), paramValue, (*C.size_t)(paramValueSizeRet)))
}
Beispiel #12
0
func CLGetMemObjectInfo(memobj CL_mem,
	param_name CL_mem_info,
	param_value_size CL_size_t,
	param_value *interface{},
	param_value_size_ret *CL_size_t) CL_int {

	if (param_value_size == 0 || param_value == nil) && param_value_size_ret == nil {
		return CL_INVALID_VALUE
	} else {
		var c_param_value_size_ret C.size_t
		var c_errcode_ret C.cl_int

		if param_value_size == 0 || param_value == nil {
			c_errcode_ret = C.clGetMemObjectInfo(memobj.cl_mem,
				C.cl_mem_info(param_name),
				C.size_t(param_value_size),
				nil,
				&c_param_value_size_ret)
		} else {
			switch param_name {
			case CL_MEM_TYPE:
				var value C.cl_mem_object_type
				c_errcode_ret = C.clGetMemObjectInfo(memobj.cl_mem,
					C.cl_mem_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_mem_object_type(value)
			case CL_MEM_FLAGS:
				var value C.cl_mem_flags
				c_errcode_ret = C.clGetMemObjectInfo(memobj.cl_mem,
					C.cl_mem_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_mem_flags(value)
			case CL_MEM_SIZE,
				CL_MEM_OFFSET:
				var value C.size_t
				c_errcode_ret = C.clGetMemObjectInfo(memobj.cl_mem,
					C.cl_mem_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_size_t(value)
			case CL_MEM_HOST_PTR:
				var value unsafe.Pointer
				c_errcode_ret = C.clGetMemObjectInfo(memobj.cl_mem,
					C.cl_mem_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = value
			case CL_MEM_MAP_COUNT,
				CL_MEM_REFERENCE_COUNT:
				var value C.cl_uint
				c_errcode_ret = C.clGetMemObjectInfo(memobj.cl_mem,
					C.cl_mem_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_uint(value)
			case CL_MEM_CONTEXT:
				var value C.cl_context
				c_errcode_ret = C.clGetMemObjectInfo(memobj.cl_mem,
					C.cl_mem_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_context{value}
			case CL_MEM_ASSOCIATED_MEMOBJECT:
				var value C.cl_mem
				c_errcode_ret = C.clGetMemObjectInfo(memobj.cl_mem,
					C.cl_mem_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_mem{value}

			case CL_MEM_USES_SVM_POINTER:
				var value C.cl_bool
				c_errcode_ret = C.clGetMemObjectInfo(memobj.cl_mem,
					C.cl_mem_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

				*param_value = CL_bool(value)

			default:
				return CL_INVALID_VALUE
			}
		}

		if param_value_size_ret != nil {
			*param_value_size_ret = CL_size_t(c_param_value_size_ret)
		}

		return CL_int(c_errcode_ret)
	}
}