예제 #1
0
파일: program.go 프로젝트: xfong/tmpCL
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
}
예제 #2
0
파일: program.go 프로젝트: xfong/tmpCL
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
}
예제 #3
0
파일: program.go 프로젝트: xfong/tmpCL
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
}
예제 #4
0
파일: program.go 프로젝트: xfong/tmpCL
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
}
예제 #5
0
파일: program.go 프로젝트: xfong/tmpCL
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
}
예제 #6
0
파일: program.go 프로젝트: xfong/tmpCL
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
}
예제 #7
0
파일: program.go 프로젝트: xfong/tmpCL
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
}
예제 #8
0
파일: package.go 프로젝트: 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)))
}
예제 #9
0
파일: program.go 프로젝트: Dirbaio/gominer
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)
	}
}