Ejemplo n.º 1
0
func (p *Program) GetKernelCounts() (int, error) {
	var val C.size_t
	if err := C.clGetProgramInfo(p.clProgram, C.CL_PROGRAM_NUM_KERNELS, C.size_t(unsafe.Sizeof(val)), (unsafe.Pointer)(&val), nil); err != C.CL_SUCCESS {
		panic("Should never fail")
		return -1, toError(err)
	}
	return int(val), nil
}
Ejemplo n.º 2
0
func (p *Program) GetContext() (*Context, error) {
	var val C.cl_context
	if err := C.clGetProgramInfo(p.clProgram, C.CL_PROGRAM_CONTEXT, C.size_t(unsafe.Sizeof(val)), (unsafe.Pointer)(&val), nil); err != C.CL_SUCCESS {
		panic("Should never fail")
		return nil, toError(err)
	}

	return &Context{clContext: val, devices: nil}, nil
}
Ejemplo n.º 3
0
func (p *Program) GetReferenceCount() (int, error) {
	var val C.cl_uint
	if err := C.clGetProgramInfo(p.clProgram, C.CL_PROGRAM_REFERENCE_COUNT, C.size_t(unsafe.Sizeof(val)), (unsafe.Pointer)(&val), nil); err != C.CL_SUCCESS {
		panic("Should never fail")
		return -1, toError(err)
	}

	return int(val), nil
}
Ejemplo n.º 4
0
func (p *Program) GetKernelNames() (string, error) {
	var strC [1024]C.char
	var strN C.size_t
	if err := C.clGetProgramInfo(p.clProgram, C.CL_PROGRAM_KERNEL_NAMES, 1024, unsafe.Pointer(&strC), &strN); err != C.CL_SUCCESS {
		panic("Should never fail")
		return "", toError(err)
	}

	// OpenCL strings are NUL-terminated, and the terminator is included in strN
	// Go strings aren't NUL-terminated, so subtract 1 from the length
	return C.GoStringN((*C.char)(unsafe.Pointer(&strC)), C.int(strN-1)), nil
}
Ejemplo n.º 5
0
func (p *Program) GetBinarySizes() ([]int, error) {
	var val C.size_t
	var arr []C.size_t
	if err := C.clGetProgramInfo(p.clProgram, C.CL_PROGRAM_BINARY_SIZES, C.size_t(unsafe.Sizeof(val)), (unsafe.Pointer)(&arr), &val); err != C.CL_SUCCESS {
		panic("Should never fail")
		return nil, toError(err)
	}

	returnCount := make([]int, int(val))
	for i := 0; i < int(val); i++ {
		returnCount[i] = int(arr[i])
	}
	return returnCount, nil
}
Ejemplo n.º 6
0
func (p *Program) GetBinaries() ([]*uint8, error) {
	var item *uint8
	var val C.size_t
	var arr []*uint8
	if err := C.clGetProgramInfo(p.clProgram, C.CL_PROGRAM_BINARIES, C.size_t(unsafe.Sizeof(item)), (unsafe.Pointer)(&arr), &val); err != C.CL_SUCCESS {
		panic("Should never fail")
		return nil, toError(err)
	}

	returnBinaries := make([]*uint8, int(val))
	for i := 0; i < int(val); i++ {
		returnBinaries[i] = arr[i]
	}
	return returnBinaries, nil
}
Ejemplo n.º 7
0
func (p *Program) GetDevices() ([]*Device, error) {
	var val C.cl_device_id
	var arr []C.cl_device_id
	var cnts C.size_t
	if err := C.clGetProgramInfo(p.clProgram, C.CL_PROGRAM_DEVICES, C.size_t(unsafe.Sizeof(val)), (unsafe.Pointer)(&arr), &cnts); err != C.CL_SUCCESS {
		panic("Should never fail")
		return nil, toError(err)
	}

	returnDevices := make([]*Device, int(cnts))
	for i := 0; i < int(cnts); i++ {
		returnDevices[i] = &Device{id: arr[i]}
	}
	return returnDevices, nil
}
Ejemplo n.º 8
0
Archivo: package.go Proyecto: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetProgramInfo.html
func GetProgramInfo(prog Program, paramName ProgramInfo, paramValueSize uint64, paramValue unsafe.Pointer, paramValueSizeRet *uint64) ErrorCode {
	return ErrorCode(C.clGetProgramInfo(prog, C.cl_program_info(paramName), C.size_t(paramValueSize), paramValue, (*C.size_t)(paramValueSizeRet)))
}
Ejemplo n.º 9
0
func CLGetProgramInfo(program CL_program,
	param_name CL_program_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.clGetProgramInfo(program.cl_program,
				C.cl_program_info(param_name),
				C.size_t(param_value_size),
				nil,
				&c_param_value_size_ret)
		} else {
			switch param_name {
			case CL_PROGRAM_SOURCE:

				value := make([]C.char, param_value_size)
				c_errcode_ret = C.clGetProgramInfo(program.cl_program,
					C.cl_program_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value[0]),
					&c_param_value_size_ret)

				*param_value = C.GoStringN(&value[0], C.int(c_param_value_size_ret-1))

			case CL_PROGRAM_REFERENCE_COUNT,
				CL_PROGRAM_NUM_DEVICES:

				var value C.cl_uint
				c_errcode_ret = C.clGetProgramInfo(program.cl_program,
					C.cl_program_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

			case CL_PROGRAM_CONTEXT:

				var value C.cl_context
				c_errcode_ret = C.clGetProgramInfo(program.cl_program,
					C.cl_program_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value),
					&c_param_value_size_ret)

			case CL_PROGRAM_DEVICES:
				var param C.cl_device_id
				length := int(C.size_t(param_value_size) / C.size_t(unsafe.Sizeof(param)))

				value1 := make([]C.cl_device_id, length)
				value2 := make([]CL_device_id, length)

				c_errcode_ret = C.clGetProgramInfo(program.cl_program,
					C.cl_program_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value1[0]),
					&c_param_value_size_ret)

				for i := 0; i < length; i++ {
					value2[i].cl_device_id = value1[i]
				}

				*param_value = value2

			case CL_PROGRAM_BINARY_SIZES:
				var param C.size_t
				length := int(C.size_t(param_value_size) / C.size_t(unsafe.Sizeof(param)))

				value1 := make([]C.size_t, length)
				value2 := make([]CL_size_t, length)

				c_errcode_ret = C.clGetProgramInfo(program.cl_program,
					C.cl_program_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value1[0]),
					&c_param_value_size_ret)

				for i := 0; i < length; i++ {
					value2[i] = CL_size_t(value1[i])
				}

				*param_value = value2

			case CL_PROGRAM_BINARIES:
				var param *C.uchar
				length := int(C.size_t(param_value_size) / C.size_t(unsafe.Sizeof(param)))

				value1 := make([]*C.uchar, length)
				value2 := make([]*CL_uchar, length)

				c_errcode_ret = C.clGetProgramInfo(program.cl_program,
					C.cl_program_info(param_name),
					C.size_t(param_value_size),
					unsafe.Pointer(&value1[0]),
					&c_param_value_size_ret)

				for i := 0; i < length; i++ {
					value2[i] = (*CL_uchar)(value1[i])
				}

				*param_value = value2

			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)
	}
}