diff options
author | Gustav Simonsson <gustav.simonsson@gmail.com> | 2015-06-12 13:45:23 +0800 |
---|---|---|
committer | Gustav Simonsson <gustav.simonsson@gmail.com> | 2015-10-07 19:19:30 +0800 |
commit | ec6a548ee3555813d83f86f82bd25694bfd9c303 (patch) | |
tree | 9d0ec5022dc952f7b1053b85382df07347bc48f0 /Godeps/_workspace/src/github.com/Gustav-Simonsson/go-opencl/cl/platform.go | |
parent | 8b865fa9bf75e728d5d76f5a1460e0c37d8b5f9e (diff) | |
download | go-tangerine-ec6a548ee3555813d83f86f82bd25694bfd9c303.tar go-tangerine-ec6a548ee3555813d83f86f82bd25694bfd9c303.tar.gz go-tangerine-ec6a548ee3555813d83f86f82bd25694bfd9c303.tar.bz2 go-tangerine-ec6a548ee3555813d83f86f82bd25694bfd9c303.tar.lz go-tangerine-ec6a548ee3555813d83f86f82bd25694bfd9c303.tar.xz go-tangerine-ec6a548ee3555813d83f86f82bd25694bfd9c303.tar.zst go-tangerine-ec6a548ee3555813d83f86f82bd25694bfd9c303.zip |
all: Add GPU mining, disabled by default
Diffstat (limited to 'Godeps/_workspace/src/github.com/Gustav-Simonsson/go-opencl/cl/platform.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/Gustav-Simonsson/go-opencl/cl/platform.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/Gustav-Simonsson/go-opencl/cl/platform.go b/Godeps/_workspace/src/github.com/Gustav-Simonsson/go-opencl/cl/platform.go new file mode 100644 index 000000000..fd1d162cf --- /dev/null +++ b/Godeps/_workspace/src/github.com/Gustav-Simonsson/go-opencl/cl/platform.go @@ -0,0 +1,83 @@ +package cl + +// #ifdef __APPLE__ +// #include "OpenCL/opencl.h" +// #else +// #include "cl.h" +// #endif +import "C" + +import "unsafe" + +const maxPlatforms = 32 + +type Platform struct { + id C.cl_platform_id +} + +// Obtain the list of platforms available. +func GetPlatforms() ([]*Platform, error) { + var platformIds [maxPlatforms]C.cl_platform_id + var nPlatforms C.cl_uint + if err := C.clGetPlatformIDs(C.cl_uint(maxPlatforms), &platformIds[0], &nPlatforms); err != C.CL_SUCCESS { + return nil, toError(err) + } + platforms := make([]*Platform, nPlatforms) + for i := 0; i < int(nPlatforms); i++ { + platforms[i] = &Platform{id: platformIds[i]} + } + return platforms, nil +} + +func (p *Platform) GetDevices(deviceType DeviceType) ([]*Device, error) { + return GetDevices(p, deviceType) +} + +func (p *Platform) getInfoString(param C.cl_platform_info) (string, error) { + var strC [2048]byte + var strN C.size_t + if err := C.clGetPlatformInfo(p.id, param, 2048, unsafe.Pointer(&strC[0]), &strN); err != C.CL_SUCCESS { + return "", toError(err) + } + return string(strC[:(strN - 1)]), nil +} + +func (p *Platform) Name() string { + if str, err := p.getInfoString(C.CL_PLATFORM_NAME); err != nil { + panic("Platform.Name() should never fail") + } else { + return str + } +} + +func (p *Platform) Vendor() string { + if str, err := p.getInfoString(C.CL_PLATFORM_VENDOR); err != nil { + panic("Platform.Vendor() should never fail") + } else { + return str + } +} + +func (p *Platform) Profile() string { + if str, err := p.getInfoString(C.CL_PLATFORM_PROFILE); err != nil { + panic("Platform.Profile() should never fail") + } else { + return str + } +} + +func (p *Platform) Version() string { + if str, err := p.getInfoString(C.CL_PLATFORM_VERSION); err != nil { + panic("Platform.Version() should never fail") + } else { + return str + } +} + +func (p *Platform) Extensions() string { + if str, err := p.getInfoString(C.CL_PLATFORM_EXTENSIONS); err != nil { + panic("Platform.Extensions() should never fail") + } else { + return str + } +} |