Commit 0d8be358 by Philipp Adolf

Enable creating and releasing command queues

parent a248256f
...@@ -17,7 +17,7 @@ It is mainly developed and tested on Linux and with Intel and Nvidia GPUs. It sh ...@@ -17,7 +17,7 @@ It is mainly developed and tested on Linux and with Intel and Nvidia GPUs. It sh
- [x] creating and releasing contexts - [x] creating and releasing contexts
- [ ] querying info - [ ] querying info
- [ ] command queues - [ ] command queues
- [ ] creating and releasing command queues - [x] creating and releasing command queues
- [ ] querying info - [ ] querying info
- [ ] buffers - [ ] buffers
- [ ] creating and releasing buffers - [ ] creating and releasing buffers
......
...@@ -10,6 +10,10 @@ package opencl ...@@ -10,6 +10,10 @@ package opencl
import "C" import "C"
import "fmt" import "fmt"
type CommandQueue struct {
queue C.cl_command_queue
}
type CommandQueueProperties struct { type CommandQueueProperties struct {
OutOfOrderExec bool OutOfOrderExec bool
Profiling bool Profiling bool
...@@ -22,6 +26,38 @@ func fromCLProperties(properties C.cl_command_queue_properties) CommandQueueProp ...@@ -22,6 +26,38 @@ func fromCLProperties(properties C.cl_command_queue_properties) CommandQueueProp
return result return result
} }
func (p CommandQueueProperties) toCLProperties() C.cl_command_queue_properties {
var result C.cl_command_queue_properties
if p.OutOfOrderExec {
result |= C.CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE
}
if p.Profiling {
result |= C.CL_QUEUE_PROFILING_ENABLE
}
return result
}
func (p CommandQueueProperties) String() string { func (p CommandQueueProperties) String() string {
return fmt.Sprintf("QueueProperties{OutOfOrderExec: %t, Profiling: %t}", p.OutOfOrderExec, p.Profiling) return fmt.Sprintf("QueueProperties{OutOfOrderExec: %t, Profiling: %t}", p.OutOfOrderExec, p.Profiling)
} }
func createCommandQueue(context Context, device Device, properties *CommandQueueProperties) (*CommandQueue, error) {
var clProperties C.cl_command_queue_properties
if properties != nil {
clProperties = properties.toCLProperties()
}
var err C.cl_int
queue := C.clCreateCommandQueue(context.context, device.id, clProperties, &err)
if err != C.CL_SUCCESS {
return nil, fmt.Errorf("failed to create command queue: %d", err)
}
return &CommandQueue{queue}, nil
}
func (q CommandQueue) Release() error {
err := C.clReleaseCommandQueue(q.queue)
if err != C.CL_SUCCESS {
return fmt.Errorf("falied to release command queue: %d", err)
}
return nil
}
...@@ -19,6 +19,7 @@ type Context struct { ...@@ -19,6 +19,7 @@ type Context struct {
context C.cl_context context C.cl_context
callback func(string, unsafe.Pointer, uintptr, interface{}) callback func(string, unsafe.Pointer, uintptr, interface{})
userdata interface{} userdata interface{}
devices []*Device
} }
type ContextProperties struct { type ContextProperties struct {
...@@ -31,7 +32,7 @@ func contextCallback(errinfo *C.char, private_info unsafe.Pointer, cb C.size_t, ...@@ -31,7 +32,7 @@ func contextCallback(errinfo *C.char, private_info unsafe.Pointer, cb C.size_t,
} }
func CreateContext(properties *ContextProperties, devices []*Device, notify func(string, unsafe.Pointer, uintptr, interface{}), userdata interface{}) (*Context, error) { func CreateContext(properties *ContextProperties, devices []*Device, notify func(string, unsafe.Pointer, uintptr, interface{}), userdata interface{}) (*Context, error) {
context := Context{nil, notify, userdata} context := Context{nil, notify, userdata, devices}
ids := make([]C.cl_device_id, len(devices)) ids := make([]C.cl_device_id, len(devices))
for i, d := range devices { for i, d := range devices {
...@@ -60,3 +61,11 @@ func (c Context) Release() error { ...@@ -60,3 +61,11 @@ func (c Context) Release() error {
} }
return nil return nil
} }
func (c Context) Devices() []*Device {
return c.devices
}
func (c Context) CreateCommandQueue(device Device, properties *CommandQueueProperties) (*CommandQueue, error) {
return createCommandQueue(c, device, properties)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment