Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
opencl
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mastersthesis-philipp
opencl
Commits
c02b04cb
Commit
c02b04cb
authored
Feb 25, 2017
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable enumeration of devices
parent
689c905d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
1 deletion
+82
-1
main.go
cmd/go-opencl-info/main.go
+9
-0
device.go
device.go
+66
-0
platform.go
platform.go
+7
-1
No files found.
cmd/go-opencl-info/main.go
View file @
c02b04cb
...
...
@@ -41,5 +41,14 @@ func main() {
log
.
Printf
(
" Profile: %s"
,
profile
)
log
.
Printf
(
" Version: %s"
,
version
)
log
.
Printf
(
" Extensions: %s"
,
strings
.
Join
(
extensions
,
", "
))
devices
,
err
:=
p
.
Devices
(
opencl
.
DeviceTypeAll
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
for
i
:=
range
devices
{
log
.
Printf
(
" Device %d"
,
i
)
}
}
}
device.go
0 → 100644
View file @
c02b04cb
package
opencl
/*
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
*/
import
"C"
import
(
"fmt"
"unsafe"
)
type
Device
struct
{
id
C
.
cl_device_id
}
type
DeviceType
C
.
cl_device_type
const
(
DeviceTypeCPU
=
DeviceType
(
C
.
CL_DEVICE_TYPE_CPU
)
DeviceTypeGPU
=
DeviceType
(
C
.
CL_DEVICE_TYPE_GPU
)
DeviceTypeAccelerator
=
DeviceType
(
C
.
CL_DEVICE_TYPE_ACCELERATOR
)
DeviceTypeCustom
=
DeviceType
(
C
.
CL_DEVICE_TYPE_CUSTOM
)
DeviceTypeDefault
=
DeviceType
(
C
.
CL_DEVICE_TYPE_DEFAULT
)
DeviceTypeAll
=
DeviceType
(
C
.
CL_DEVICE_TYPE_ALL
)
)
func
(
t
DeviceType
)
String
()
string
{
switch
t
{
case
DeviceTypeCPU
:
return
"CPU"
case
DeviceTypeGPU
:
return
"GPU"
case
DeviceTypeAccelerator
:
return
"accelereator"
case
DeviceTypeCustom
:
return
"custom"
case
DeviceTypeDefault
:
return
"default"
case
DeviceTypeAll
:
return
"all"
}
return
fmt
.
Sprintf
(
"unknown type %d"
,
t
)
}
func
getDevices
(
platform
Platform
,
deviceType
DeviceType
)
([]
Device
,
error
)
{
var
n
C
.
cl_uint
if
err
:=
C
.
clGetDeviceIDs
(
platform
.
id
,
C
.
cl_device_type
(
deviceType
),
0
,
nil
,
&
n
);
err
!=
C
.
CL_SUCCESS
{
return
nil
,
fmt
.
Errorf
(
"error getting number of devices: %d"
,
err
)
}
ids
:=
make
([]
C
.
cl_device_id
,
n
)
if
err
:=
C
.
clGetDeviceIDs
(
platform
.
id
,
C
.
cl_device_type
(
deviceType
),
n
,
unsafe
.
Pointer
(
&
ids
[
0
]),
nil
);
err
!=
C
.
CL_SUCCESS
{
return
nil
,
fmt
.
Errorf
(
"error getting devices: %d"
,
err
)
}
devices
:=
make
([]
Device
,
n
)
for
i
,
id
:=
range
ids
{
devices
[
i
]
.
id
=
id
}
return
devices
,
nil
}
platform.go
View file @
c02b04cb
...
...
@@ -8,7 +8,9 @@ package opencl
#endif
*/
import
"C"
import
"fmt"
import
(
"fmt"
)
type
Platform
struct
{
id
C
.
cl_platform_id
...
...
@@ -32,3 +34,7 @@ func GetPlatforms() ([]Platform, error) {
return
platforms
,
nil
}
func
(
p
Platform
)
Devices
(
deviceType
DeviceType
)
([]
Device
,
error
)
{
return
getDevices
(
p
,
deviceType
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment