Commit 090941a5 by Philipp Adolf

Enable reading and writing buffers (blocking)

parent bf5ebeab
...@@ -21,8 +21,8 @@ It is mainly developed and tested on Linux and with Intel and Nvidia GPUs. It sh ...@@ -21,8 +21,8 @@ It is mainly developed and tested on Linux and with Intel and Nvidia GPUs. It sh
- [ ] querying info - [ ] querying info
- [ ] buffers - [ ] buffers
- [*] creating and releasing buffers - [*] creating and releasing buffers
- [ ] writing buffers - [x] writing buffers (blocking only for now)
- [ ] reading buffers - [x] reading buffers (blocking only for now)
- [ ] querying info - [ ] querying info
- [ ] program objects - [ ] program objects
- [ ] creating and releasing program objects - [ ] creating and releasing program objects
......
...@@ -8,7 +8,10 @@ package opencl ...@@ -8,7 +8,10 @@ package opencl
#endif #endif
*/ */
import "C" import "C"
import "fmt" import (
"fmt"
"unsafe"
)
type CommandQueue struct { type CommandQueue struct {
queue C.cl_command_queue queue C.cl_command_queue
...@@ -61,3 +64,25 @@ func (q CommandQueue) Release() error { ...@@ -61,3 +64,25 @@ func (q CommandQueue) Release() error {
} }
return nil return nil
} }
func (q CommandQueue) EnqueueReadBuffer(memory Memory, offset uintptr, buffer []byte, waitList []Event) error {
var clEventsPtr unsafe.Pointer
if len(waitList) > 0 {
clEventsPtr = unsafe.Pointer(&asCLEventList(waitList)[0])
}
if err := C.clEnqueueReadBuffer(q.queue, memory.memory, C.CL_TRUE, C.size_t(offset), C.size_t(len(buffer)), unsafe.Pointer(&buffer[0]), C.cl_uint(len(waitList)), clEventsPtr, nil); err != C.CL_SUCCESS {
return fmt.Errorf("failed to enqueue read: %d", err)
}
return nil
}
func (q CommandQueue) EnqueueWriteBuffer(memory Memory, offset uintptr, buffer []byte, waitList []Event) error {
var clEventsPtr unsafe.Pointer
if len(waitList) > 0 {
clEventsPtr = unsafe.Pointer(&asCLEventList(waitList)[0])
}
if err := C.clEnqueueWriteBuffer(q.queue, memory.memory, C.CL_TRUE, C.size_t(offset), C.size_t(len(buffer)), unsafe.Pointer(&buffer[0]), C.cl_uint(len(waitList)), clEventsPtr, nil); err != C.CL_SUCCESS {
return fmt.Errorf("Failed to enqueue write: %d", err)
}
return nil
}
package opencl
/*
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
*/
import "C"
import "fmt"
type Event struct {
event C.cl_event
}
func (e Event) Release() error {
err := C.clReleaseEvent(e.event)
if err != C.CL_SUCCESS {
return fmt.Errorf("failed to release event: %d", err)
}
return nil
}
func asCLEventList(events []Event) []C.cl_event {
result := make([]C.cl_event, len(events))
for i, e := range events {
result[i] = e.event
}
return result
}
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