示例#1
0
文件: ocl.go 项目: aa1214808834/go-cl
func CreateProgram(context *Context, sources []string) *Program {
	runtime.LockOSThread()
	var program Program
	var error C.cl_int

	csources := C.makeCharArray(C.int(len(sources)))
	clenghts := make([]C.size_t, len(sources))

	defer C.freeCharArray(csources, C.int(len(sources)))

	for i := 0; i < len(sources); i++ {
		C.setArrayString(csources, C.CString(sources[i]), C.int(i))
		clenghts[i] = C.size_t(len(sources[i]))
		fmt.Printf("Program log:%d %s\n", clenghts[i], sources[i])
	}

	program.item = C.clCreateProgramWithSource(
		context.item,
		C.cl_uint(len(sources)),
		csources,
		&clenghts[0],
		&error)

	fmt.Printf("Program error:%d\n", error)

	return &program
}
示例#2
0
func (c *Context) NewProgramFromSource(prog []byte) (*Program, error) {
	var c_program C.cl_program
	var err C.cl_int

	srcPtr := (*C.char)(unsafe.Pointer(&prog[0]))
	length := (C.size_t)(len(prog))
	if c_program = C.clCreateProgramWithSource(c.id, 1, &srcPtr, &length, &err); err != C.CL_SUCCESS {
		return nil, Cl_error(err)
	}

	program := &Program{id: c_program}
	runtime.SetFinalizer(program, (*Program).release)

	return program, nil
}
示例#3
0
func CLCreateProgramWithSource(context CL_context,
	count CL_uint,
	strings [][]byte,
	lengths []CL_size_t,
	errcode_ret *CL_int) CL_program {

	if count == 0 || len(strings) != int(count) || len(lengths) != int(count) {
		if errcode_ret != nil {
			*errcode_ret = CL_INVALID_VALUE
		}
		return CL_program{nil}
	}

	for i := 0; i < int(count); i++ {
		if strings[i] == nil || lengths[i] == 0 {
			if errcode_ret != nil {
				*errcode_ret = CL_INVALID_VALUE
			}
			return CL_program{nil}
		}
	}

	var c_program C.cl_program
	var c_lengths []C.size_t
	var c_strings []*C.char
	var c_errcode_ret C.cl_int

	c_lengths = make([]C.size_t, count)
	c_strings = make([]*C.char, count)
	for i := 0; i < int(count); i++ {
		c_lengths[i] = C.size_t(lengths[i])
		c_strings[i] = C.CString(string(strings[i]))
		defer C.free(unsafe.Pointer(c_strings[i]))
	}

	c_program = C.clCreateProgramWithSource(context.cl_context,
		C.cl_uint(count),
		&c_strings[0],
		&c_lengths[0],
		&c_errcode_ret)

	if errcode_ret != nil {
		*errcode_ret = CL_int(c_errcode_ret)
	}

	return CL_program{c_program}
}
示例#4
0
func (ctx *Context) CreateProgramWithSource(sources []string) (*Program, error) {
	cSources := make([]*C.char, len(sources))
	for i, s := range sources {
		cs := C.CString(s)
		cSources[i] = cs
		defer C.free(unsafe.Pointer(cs))
	}
	var err C.cl_int
	clProgram := C.clCreateProgramWithSource(ctx.clContext, C.cl_uint(len(sources)), &cSources[0], nil, &err)
	if err != C.CL_SUCCESS {
		return nil, toError(err)
	}
	if clProgram == nil {
		return nil, ErrUnknown
	}
	program := &Program{clProgram: clProgram, devices: ctx.devices}
	runtime.SetFinalizer(program, releaseProgram)
	return program, nil
}
示例#5
0
func (c *Context) NewProgramFromSource(prog string) (*Program, error) {
	var c_program C.cl_program
	var err C.cl_int

	cs := C.CString(prog)
	defer C.free(unsafe.Pointer(cs))

	if c_program = C.clCreateProgramWithSource(c.id, 1, &cs, (*C.size_t)(nil), &err); err != C.CL_SUCCESS {
		return nil, Cl_error(err)
	} else if err = C.clBuildProgram(c_program, 0, nil, nil, nil, nil); err != C.CL_SUCCESS {
		C.clReleaseProgram(c_program)
		return nil, Cl_error(err)
	}

	program := &Program{id: c_program}
	runtime.SetFinalizer(program, (*Program).release)

	return program, nil
}
示例#6
0
文件: package.go 项目: mantyr/cl
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateProgramWithSource.html
func CreateProgramWithSource(context Context, count uint32, src **uint8, lengths *uint64, errcode *ErrorCode) Program {
	return Program(C.clCreateProgramWithSource(context.clContext, C.cl_uint(count), (**C.char)(unsafe.Pointer(src)), (*C.size_t)(unsafe.Pointer(lengths)), (*C.cl_int)(unsafe.Pointer(errcode))))
}