Exemple #1
0
func (k *Kernel) SetArg(index uint, arg interface{}) error {
	var ret C.cl_int

	switch t := arg.(type) {
	case *Buffer: // can't use *Image here, compiler bug?
		ret = C.clSetKernelArg(k.id, C.cl_uint(index), C.size_t(unsafe.Sizeof(t.id)), unsafe.Pointer(&t.id))
	case *Image:
		ret = C.clSetKernelArg(k.id, C.cl_uint(index), C.size_t(unsafe.Sizeof(t.id)), unsafe.Pointer(&t.id))
	case float32:
		ret = C.clSetKernelArg(k.id, C.cl_uint(index), C.size_t(4), unsafe.Pointer(&t))
	case []float32:
		ret = C.clSetKernelArg(k.id, C.cl_uint(index), C.size_t(len(t)*4), unsafe.Pointer(&t[0]))
	case *float32:
		var p *C.float
		ret = C.clSetKernelArg(k.id, C.cl_uint(index), C.size_t(unsafe.Sizeof(p)), unsafe.Pointer(&t))

	default:
		return Cl_error(C.CL_INVALID_VALUE)
	}

	if ret != C.CL_SUCCESS {
		return Cl_error(ret)
	}
	return nil
}
Exemple #2
0
func CLSetKernelArg(kernel CL_kernel,
	arg_index CL_uint,
	arg_size CL_size_t,
	arg_value unsafe.Pointer) CL_int {
	return CL_int(C.clSetKernelArg(kernel.cl_kernel,
		C.cl_uint(arg_index),
		C.size_t(arg_size),
		arg_value))
}
Exemple #3
0
func (k *Kernel) SetArg(index uint, arg interface{}) error {
	var ret C.cl_int

	switch t := arg.(type) {
	case *Buffer:
		ret = C.clSetKernelArg(k.id, C.cl_uint(index), C.size_t(unsafe.Sizeof(t.id)), unsafe.Pointer(&t.id))
	case *Image:
		ret = C.clSetKernelArg(k.id, C.cl_uint(index), C.size_t(unsafe.Sizeof(t.id)), unsafe.Pointer(&t.id))
	case *Sampler:
		ret = C.clSetKernelArg(k.id, C.cl_uint(index), C.size_t(unsafe.Sizeof(t.id)), unsafe.Pointer(&t.id))
	case float32:
		f := C.float(t)
		ret = C.clSetKernelArg(k.id, C.cl_uint(index), C.size_t(unsafe.Sizeof(f)), unsafe.Pointer(&f))

	default:
		return Cl_error(C.CL_INVALID_VALUE)
	}

	if ret != C.CL_SUCCESS {
		return Cl_error(ret)
	}
	return nil
}
Exemple #4
0
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetKernelArg.html
func SetKernelArg(ker Kernel, argIndex uint32, argSize uint64, argValue unsafe.Pointer) ErrorCode {
	return ErrorCode(C.clSetKernelArg(ker, C.cl_uint(argIndex), C.size_t(argSize), argValue))
}
Exemple #5
0
func (k *Kernel) SetArgUnsafe(index, argSize int, arg unsafe.Pointer) error {
	return toError(C.clSetKernelArg(k.clKernel, C.cl_uint(index), C.size_t(argSize), arg))
}