-
Notifications
You must be signed in to change notification settings - Fork 64
/
convenience.go
45 lines (39 loc) · 1.15 KB
/
convenience.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cu
// #include <cuda.h>
import "C"
import (
"log"
"unsafe"
"github.com/pkg/errors"
)
// This file lists all the convenience functions and methods, not necessarily stuff that is covered in the API
// MemoryType returns the MemoryType of the memory
func (mem DevicePtr) MemoryType() (typ MemoryType, err error) {
var p unsafe.Pointer
if p, err = mem.PtrAttribute(MemoryTypeAttr); err != nil {
return
}
t := *(*uint64)(p)
typ = MemoryType(byte(t))
return
}
// MemSize returns the size of the memory slab in bytes. Returns 0 if errors occured
func (mem DevicePtr) MemSize() uintptr {
size, _, err := mem.AddressRange()
if err != nil {
log.Printf("MEMSIZE ERR %v", err)
}
return uintptr(size)
}
// ComputeCapability returns the compute capability of the device.
// This method is a convenience method for the deprecated API call cuDeviceComputeCapability.
func (d Device) ComputeCapability() (major, minor int, err error) {
var attrs []int
if attrs, err = d.Attributes(ComputeCapabilityMajor, ComputeCapabilityMinor); err != nil {
err = errors.Wrapf(err, "Failed to get ComputeCapability")
return
}
major = attrs[0]
minor = attrs[1]
return
}