Commit 5752ac88 by Philipp Adolf

Enable creating and releasing kernels

parent d23f7968
...@@ -31,7 +31,7 @@ It is mainly developed and tested on Linux and with Intel and Nvidia GPUs. It sh ...@@ -31,7 +31,7 @@ It is mainly developed and tested on Linux and with Intel and Nvidia GPUs. It sh
- [ ] unloading the compiler - [ ] unloading the compiler
- [ ] querying program (build) info - [ ] querying program (build) info
- [ ] kernel objects - [ ] kernel objects
- [ ] creating and releasing kernels - [x] creating and releasing kernels
- [ ] setting arguments - [ ] setting arguments
- [ ] querying kernel, work group and argument info - [ ] querying kernel, work group and argument info
- [ ] executing kernels - [ ] executing kernels
......
package opencl
/*
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
#include <stdlib.h>
*/
import "C"
import (
"fmt"
"unsafe"
)
type Kernel struct {
kernel C.cl_kernel
}
func createKernel(program Program, name string) (*Kernel, error) {
clName := C.CString(name)
defer C.free(unsafe.Pointer(clName))
var err C.cl_int
kernel := C.clCreateKernel(program.program, clName, &err)
if err != C.CL_SUCCESS {
return nil, fmt.Errorf("failed to create kernel: %d", err)
}
return &Kernel{kernel}, nil
}
func (k Kernel) Release() error {
err := C.clReleaseKernel(k.kernel)
if err != C.CL_SUCCESS {
return fmt.Errorf("failed to release kernel: %d", err)
}
return nil
}
...@@ -56,3 +56,7 @@ func (p Program) BuildLog(device Device) (string, error) { ...@@ -56,3 +56,7 @@ func (p Program) BuildLog(device Device) (string, error) {
return C.GoString(&result[0]), nil return C.GoString(&result[0]), nil
} }
func (p Program) CreateKernel(name string) (*Kernel, error) {
return createKernel(p, name)
}
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