cuda

package
v3.5.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2014 License: CC-BY-3.0, Freetype, GPL-3.0-or-later Imports: 13 Imported by: 0

README

PACKAGE

package cu
    import "github.com/barnex/cuda5/cu"

    Go bindings for the CUDA driver API.

CONSTANTS

const (
    // If  the number of contexts > number of CPUs, yield to other OS threads when waiting for the GPU, otherwise CUDA spin on the processor.
    CTX_SCHED_AUTO = C.CU_CTX_SCHED_AUTO
    // Spin when waiting for results from the GPU. 
    CTX_SCHED_SPIN = C.CU_CTX_SCHED_SPIN
    // Yield its thread when waiting for results from the GPU.
    CTX_SCHED_YIELD = C.CU_CTX_SCHED_YIELD
    // Bock the CPU thread on a synchronization primitive when waiting for the GPU to finish work.
    CTX_BLOCKING_SYNC
    // Support mapped pinned allocations. This flag must be set in order to allocate pinned host memory that is accessible to the GPU.
    CTX_MAP_HOST = C.CU_CTX_MAP_HOST
    //Do not reduce local memory after resizing local memory for a kernel. 
    CTX_LMEM_RESIZE_TO_MAX = C.CU_CTX_LMEM_RESIZE_TO_MAX
)
    Flags for CtxCreate
const (
    SIZEOF_FLOAT32    = 4
    SIZEOF_FLOAT64    = 8
    SIZEOF_COMPLEX64  = 8
    SIZEOF_COMPLEX128 = 16
)
    Type size in bytes


FUNCTIONS

func CtxDestroy(ctx *Context)
    Destroys the CUDA context specified by ctx. If the context usage count
    is not equal to 1, or the context is current to any CPU thread other
    than the current one, this function fails. Floating contexts (detached
    from a CPU thread via cuCtxPopCurrent()) may be destroyed by this
    function.

func CtxDisablePeerAccess(peer Context)
    Reverses CtxEnablePeerAccess().

func CtxEnablePeerAccess(peer Context)
    Make allocations from the peer Context available to the current context.

func CtxGetApiVersion(ctx Context) (version int)
    Returns the API version to create the context.

func CtxSetCurrent(ctx Context)
    Sets the current active context.

func CtxSynchronize()
    Blocks until the device has completed all preceding requested tasks, if
    the context was created with the CU_CTX_SCHED_BLOCKING_SYNC flag.

func DeviceCanAccessPeer(dev, peer Device) bool
    Returns true if CtxEnablePeerAccess can be called on a context for dev
    and peerDev.

func DeviceComputeCapability(device Device) (major, minor int)
    Returns the compute capability of the device.

func DeviceGetAttribute(attrib DeviceAttribute, dev Device) int
    Gets the value of a device attribute.

func DeviceGetCount() int
    Returns the number of devices with compute capability greater than or
    equal to 1.0 that are available for execution.

func DeviceGetName(dev Device) string
    Gets the name of the device.

func DeviceTotalMem(device Device) int64
    Returns the total amount of memory available on the device in bytes.

func FuncGetAttribute(attrib FunctionAttribute, function Function) int

func Init(flags int)
    Initialize the CUDA driver API. Currently, flags must be 0. If Init()
    has not been called, any function from the driver API will panic with
    ERROR_NOT_INITIALIZED.

func LaunchKernel(f Function, gridDimX, gridDimY, gridDimZ int, blockDimX, blockDimY, blockDimZ int, sharedMemBytes int, stream Stream, kernelParams []unsafe.Pointer)

func MemAllocHost(bytes int64) unsafe.Pointer

func MemFree(ptr *DevicePtr)
    Frees device memory allocated by MemAlloc(). Overwrites the pointer with
    NULL. It is safe to double-free.

func MemFreeHost(ptr unsafe.Pointer)

func MemGetAddressRange(ptr DevicePtr) (bytes int64, base DevicePtr)
    Returns the base address and size of the allocation (by MemAlloc) that
    contains the input pointer ptr.

func MemGetInfo() (free, total int64)
    Returns the free and total amount of memroy in the current Context (in
    bytes).

func MemHostRegister(ptr unsafe.Pointer, bytes int64, flags MemHostRegisterFlag)
    Page-locks memory specified by the pointer and bytes. The pointer and
    byte size must be aligned to the host page size (4KB) See also:
    MemHostUnregister()

func MemHostUnregister(ptr unsafe.Pointer)
    Unmaps memory locked by MemHostRegister().

func Memcpy(dst, src DevicePtr, bytes int64)
    Copies a number of bytes on the current device. Requires unified
    addressing to be supported. See also: MemcpyDtoD(). TODO(a): is actually
    an auto copy for device and/or host memory

func MemcpyAsync(dst, src DevicePtr, bytes int64, stream Stream)
    Asynchronously copies a number of bytes on the current device.

func MemcpyDtoD(dst, src DevicePtr, bytes int64)
    Copies a number of bytes from host to device.

func MemcpyDtoDAsync(dst, src DevicePtr, bytes int64, stream Stream)
    Asynchronously copies a number of bytes from host to device.

func MemcpyDtoH(dst unsafe.Pointer, src DevicePtr, bytes int64)
    Copies a number of bytes from device to host.

func MemcpyDtoHAsync(dst unsafe.Pointer, src DevicePtr, bytes int64, stream Stream)
    Asynchronously copies a number of bytes device host to host. The host
    memory must be page-locked (see MemRegister)

func MemcpyHtoD(dst DevicePtr, src unsafe.Pointer, bytes int64)
    Copies a number of bytes from host to device.

func MemcpyHtoDAsync(dst DevicePtr, src unsafe.Pointer, bytes int64, stream Stream)
    Asynchronously copies a number of bytes from host to device. The host
    memory must be page-locked (see MemRegister)

func MemcpyPeer(dst DevicePtr, dstCtx Context, src DevicePtr, srcCtx Context, bytes int64)
    Copies from device memory in one context (device) to another.

func MemcpyPeerAsync(dst DevicePtr, dstCtx Context, src DevicePtr, srcCtx Context, bytes int64, stream Stream)
    Asynchronously copies from device memory in one context (device) to
    another.

func MemsetD32(deviceptr DevicePtr, value uint32, N int64)
    Sets the first N 32-bit values of dst array to value. Asynchronous.

func MemsetD32Async(deviceptr DevicePtr, value uint32, N int64, stream Stream)
    Asynchronously sets the first N 32-bit values of dst array to value.

func MemsetD8(deviceptr DevicePtr, value uint8, N int64)
    Sets the first N 8-bit values of dst array to value. Asynchronous.

func MemsetD8Async(deviceptr DevicePtr, value uint8, N int64, stream Stream)
    Asynchronously sets the first N 32-bit values of dst array to value.

func StreamDestroy(stream *Stream)
    Destroys an asynchronous stream

func StreamSynchronize(stream Stream)
    Blocks until the stream has completed.

func Version() int
    Returns the CUDA driver version.


TYPES

type Context uintptr
    CUDA context.

func CtxCreate(flags uint, dev Device) Context
    Create a CUDA context.

func CtxGetCurrent() Context
    Gets the current active context.

func (ctx Context) ApiVersion() (version int)
    Returns the API version to create the context.

func (ctx *Context) Destroy()
    Destroys the CUDA context.

func (peer Context) DisablePeerAccess()
    Reverses EnablePeerAccess().

func (peer Context) EnablePeerAccess()
    Make allocations from the peer Context available to the current context.

func (ctx Context) SetCurrent()
    Sets the current active context.

type DevProp struct {
    MaxThreadsPerBlock  int
    MaxThreadsDim       [3]int
    MaxGridSize         [3]int
    SharedMemPerBlock   int
    TotalConstantMemory int
    SIMDWidth           int
    MemPitch            int
    RegsPerBlock        int
    ClockRate           int
    TextureAlign        int
}
    Device properties

func DeviceGetProperties(dev Device) (prop DevProp)
    Returns the device's properties.

type Device int
    CUDA Device number.

func CtxGetDevice() Device
    Returns the ordinal of the current context's device.

func DeviceGet(ordinal int) Device
    Returns in a device handle given an ordinal in the range [0,
    DeviceGetCount()-1].

func (dev Device) Attribute(attrib DeviceAttribute) int
    Gets the value of a device attribute.

func (dev Device) CanAccessPeer(peer Device) bool
    Returns true if CtxEnablePeerAccess can be called on a context for dev
    and peerDev.

func (device Device) ComputeCapability() (major, minor int)
    Returns the compute capability of the device.

func (dev Device) Name() string
    Gets the name of the device.

func (dev Device) Properties() DevProp
    Returns the device's properties.

func (device Device) TotalMem() int64
    Returns the total amount of memory available on the device in bytes.

type DeviceAttribute int

const (
    MAX_THREADS_PER_BLOCK            DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK            // Maximum number of threads per block
    MAX_BLOCK_DIM_X                  DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X                  // Maximum block dimension X
    MAX_BLOCK_DIM_Y                  DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y                  // Maximum block dimension Y
    MAX_BLOCK_DIM_Z                  DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z                  // Maximum block dimension Z
    MAX_GRID_DIM_X                   DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X                   // Maximum grid dimension X
    MAX_GRID_DIM_Y                   DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y                   // Maximum grid dimension Y
    MAX_GRID_DIM_Z                   DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z                   // Maximum grid dimension Z
    MAX_SHARED_MEMORY_PER_BLOCK      DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK      // Maximum shared memory available per block in bytes
    TOTAL_CONSTANT_MEMORY            DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY            // Memory available on device for __constant__ variables in a CUDA C kernel in bytes
    WARP_SIZE                        DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_WARP_SIZE                        // Warp size in threads
    MAX_PITCH                        DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_PITCH                        // Maximum pitch in bytes allowed by memory copies
    MAX_REGISTERS_PER_BLOCK          DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK          // Maximum number of 32-bit registers available per block
    CLOCK_RATE                       DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_CLOCK_RATE                       // Peak clock frequency in kilohertz
    TEXTURE_ALIGNMENT                DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT                // Alignment requirement for textures
    MULTIPROCESSOR_COUNT             DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT             // Number of multiprocessors on device
    KERNEL_EXEC_TIMEOUT              DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT              // Specifies whether there is a run time limit on kernels
    INTEGRATED                       DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_INTEGRATED                       // Device is integrated with host memory
    CAN_MAP_HOST_MEMORY              DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY              // Device can map host memory into CUDA address space
    COMPUTE_MODE                     DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_COMPUTE_MODE                     // Compute mode (See ::CUcomputemode for details)
    MAXIMUM_TEXTURE1D_WIDTH          DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH          // Maximum 1D texture width
    MAXIMUM_TEXTURE2D_WIDTH          DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_WIDTH          // Maximum 2D texture width
    MAXIMUM_TEXTURE2D_HEIGHT         DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_HEIGHT         // Maximum 2D texture height
    MAXIMUM_TEXTURE3D_WIDTH          DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH          // Maximum 3D texture width
    MAXIMUM_TEXTURE3D_HEIGHT         DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT         // Maximum 3D texture height
    MAXIMUM_TEXTURE3D_DEPTH          DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH          // Maximum 3D texture depth
    MAXIMUM_TEXTURE2D_LAYERED_WIDTH  DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_WIDTH  // Maximum 2D layered texture width
    MAXIMUM_TEXTURE2D_LAYERED_HEIGHT DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_HEIGHT // Maximum 2D layered texture height
    MAXIMUM_TEXTURE2D_LAYERED_LAYERS DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_LAYERS // Maximum layers in a 2D layered texture
    SURFACE_ALIGNMENT                DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_SURFACE_ALIGNMENT                // Alignment requirement for surfaces
    CONCURRENT_KERNELS               DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS               // Device can possibly execute multiple kernels concurrently
    ECC_ENABLED                      DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_ECC_ENABLED                      // Device has ECC support enabled
    PCI_BUS_ID                       DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_PCI_BUS_ID                       // PCI bus ID of the device
    PCI_DEVICE_ID                    DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID                    // PCI device ID of the device
    TCC_DRIVER                       DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_TCC_DRIVER                       // Device is using TCC driver model
    MEMORY_CLOCK_RATE                DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE                // Peak memory clock frequency in kilohertz
    GLOBAL_MEMORY_BUS_WIDTH          DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH          // Global memory bus width in bits
    L2_CACHE_SIZE                    DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_L2_CACHE_SIZE                    // Size of L2 cache in bytes
    MAX_THREADS_PER_MULTIPROCESSOR   DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR   // Maximum resident threads per multiprocessor
    ASYNC_ENGINE_COUNT               DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT               // Number of asynchronous engines
    UNIFIED_ADDRESSING               DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING               // Device uses shares a unified address space with the host 
    MAXIMUM_TEXTURE1D_LAYERED_WIDTH  DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_LAYERED_WIDTH  // Maximum 1D layered texture width
    MAXIMUM_TEXTURE1D_LAYERED_LAYERS DeviceAttribute = C.CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_LAYERED_LAYERS // Maximum layers in a 1D layered texture
)

type DevicePtr uintptr

func MemAlloc(bytes int64) DevicePtr
    Allocates a number of bytes of device memory.

func (ptr DevicePtr) Bytes() (bytes int64)
    Returns the size of the allocation (by MemAlloc) that contains the input
    pointer ptr.

func (ptr *DevicePtr) Free()
    Frees device memory allocated by MemAlloc(). Overwrites the pointer with
    NULL. It is safe to double-free.

func (ptr DevicePtr) GetAddressRange() (bytes int64, base DevicePtr)
    Returns the base address and size of the allocation (by MemAlloc) that
    contains the input pointer ptr.

func (ptr DevicePtr) MemoryType() MemoryType
    Returns the physical memory type that ptr addresses.

func (p DevicePtr) String() string

type Dim3 struct {
    X, Y, Z int
}

type Function uintptr
    Represents a CUDA CUfunction, a reference to a function within a module.

func ModuleGetFunction(module Module, name string) Function
    Returns a Function handle.

func (f Function) GetAttribute(attrib FunctionAttribute) int

type FunctionAttribute int

const (
    FUNC_A_MAX_THREADS_PER_BLOCK FunctionAttribute = C.CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK // The maximum number of threads per block, beyond which a launch of the function would fail.
    FUNC_A_SHARED_SIZE_BYTES     FunctionAttribute = C.CU_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES     // The size in bytes of statically-allocated shared memory required by this function. 
    FUNC_A_CONST_SIZE_BYTES      FunctionAttribute = C.CU_FUNC_ATTRIBUTE_CONST_SIZE_BYTES      // The size in bytes of user-allocated constant memory required by this function.
    FUNC_A_LOCAL_SIZE_BYTES      FunctionAttribute = C.CU_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES      // The size in bytes of local memory used by each thread of this function.
    FUNC_A_NUM_REGS              FunctionAttribute = C.CU_FUNC_ATTRIBUTE_NUM_REGS              // The number of registers used by each thread of this function.
    FUNC_A_PTX_VERSION           FunctionAttribute = C.CU_FUNC_ATTRIBUTE_PTX_VERSION           // The PTX virtual architecture version for which the function was compiled. 
    FUNC_A_BINARY_VERSION        FunctionAttribute = C.CU_FUNC_ATTRIBUTE_BINARY_VERSION        // The binary architecture version for which the function was compiled.
)

type MemHostRegisterFlag int

const (
    // Memory is pinned in all CUDA contexts.
    MEMHOSTREGISTER_PORTABLE MemHostRegisterFlag = C.CU_MEMHOSTREGISTER_PORTABLE
    // Maps the allocation in CUDA address space. TODO(a): cuMemHostGetDevicePointer()
    MEMHOSTREGISTER_DEVICEMAP MemHostRegisterFlag = C.CU_MEMHOSTREGISTER_DEVICEMAP
)
    Flag for MemHostRegister

type MemoryType uint
    Physical memory type of device pointer.

const (
    MemoryTypeHost    MemoryType = C.CU_MEMORYTYPE_HOST
    MemoryTypeDevice  MemoryType = C.CU_MEMORYTYPE_DEVICE
    MemoryTypeArray   MemoryType = C.CU_MEMORYTYPE_ARRAY
    MemoryTypeUnified MemoryType = C.CU_MEMORYTYPE_UNIFIED
)

func PointerGetAttributeMemoryType(ptr DevicePtr) (t MemoryType, err Result)
    Returns the physical memory type that ptr addresses.

func (t MemoryType) String() string

type Module uintptr
    Represents a CUDA CUmodule, a reference to executable device code.

func ModuleLoad(fname string) Module
    Loads a compute module from file

func ModuleLoadData(image string) Module
    Loads a compute module from string

func (m Module) GetFunction(name string) Function
    Returns a Function handle.

type Result int
    CUDA error status. CUDA error statuses are not returned by functions but
    checked and passed to panic() when not successful. If desired, they can
    be caught by recover().

const (
    SUCCESS                              Result = C.CUDA_SUCCESS
    ERROR_INVALID_VALUE                  Result = C.CUDA_ERROR_INVALID_VALUE
    ERROR_OUT_OF_MEMORY                  Result = C.CUDA_ERROR_OUT_OF_MEMORY
    ERROR_NOT_INITIALIZED                Result = C.CUDA_ERROR_NOT_INITIALIZED
    ERROR_DEINITIALIZED                  Result = C.CUDA_ERROR_DEINITIALIZED
    ERROR_PROFILER_DISABLED              Result = C.CUDA_ERROR_PROFILER_DISABLED
    ERROR_PROFILER_NOT_INITIALIZED       Result = C.CUDA_ERROR_PROFILER_NOT_INITIALIZED
    ERROR_PROFILER_ALREADY_STARTED       Result = C.CUDA_ERROR_PROFILER_ALREADY_STARTED
    ERROR_PROFILER_ALREADY_STOPPED       Result = C.CUDA_ERROR_PROFILER_ALREADY_STOPPED
    ERROR_NO_DEVICE                      Result = C.CUDA_ERROR_NO_DEVICE
    ERROR_INVALID_DEVICE                 Result = C.CUDA_ERROR_INVALID_DEVICE
    ERROR_INVALID_IMAGE                  Result = C.CUDA_ERROR_INVALID_IMAGE
    ERROR_INVALID_CONTEXT                Result = C.CUDA_ERROR_INVALID_CONTEXT
    ERROR_CONTEXT_ALREADY_CURRENT        Result = C.CUDA_ERROR_CONTEXT_ALREADY_CURRENT
    ERROR_MAP_FAILED                     Result = C.CUDA_ERROR_MAP_FAILED
    ERROR_UNMAP_FAILED                   Result = C.CUDA_ERROR_UNMAP_FAILED
    ERROR_ARRAY_IS_MAPPED                Result = C.CUDA_ERROR_ARRAY_IS_MAPPED
    ERROR_ALREADY_MAPPED                 Result = C.CUDA_ERROR_ALREADY_MAPPED
    ERROR_NO_BINARY_FOR_GPU              Result = C.CUDA_ERROR_NO_BINARY_FOR_GPU
    ERROR_ALREADY_ACQUIRED               Result = C.CUDA_ERROR_ALREADY_ACQUIRED
    ERROR_NOT_MAPPED                     Result = C.CUDA_ERROR_NOT_MAPPED
    ERROR_NOT_MAPPED_AS_ARRAY            Result = C.CUDA_ERROR_NOT_MAPPED_AS_ARRAY
    ERROR_NOT_MAPPED_AS_POINTER          Result = C.CUDA_ERROR_NOT_MAPPED_AS_POINTER
    ERROR_ECC_UNCORRECTABLE              Result = C.CUDA_ERROR_ECC_UNCORRECTABLE
    ERROR_UNSUPPORTED_LIMIT              Result = C.CUDA_ERROR_UNSUPPORTED_LIMIT
    ERROR_CONTEXT_ALREADY_IN_USE         Result = C.CUDA_ERROR_CONTEXT_ALREADY_IN_USE
    ERROR_INVALID_SOURCE                 Result = C.CUDA_ERROR_INVALID_SOURCE
    ERROR_FILE_NOT_FOUND                 Result = C.CUDA_ERROR_FILE_NOT_FOUND
    ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND Result = C.CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND
    ERROR_SHARED_OBJECT_INIT_FAILED      Result = C.CUDA_ERROR_SHARED_OBJECT_INIT_FAILED
    ERROR_OPERATING_SYSTEM               Result = C.CUDA_ERROR_OPERATING_SYSTEM
    ERROR_INVALID_HANDLE                 Result = C.CUDA_ERROR_INVALID_HANDLE
    ERROR_NOT_FOUND                      Result = C.CUDA_ERROR_NOT_FOUND
    ERROR_NOT_READY                      Result = C.CUDA_ERROR_NOT_READY
    ERROR_LAUNCH_FAILED                  Result = C.CUDA_ERROR_LAUNCH_FAILED
    ERROR_LAUNCH_OUT_OF_RESOURCES        Result = C.CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES
    ERROR_LAUNCH_TIMEOUT                 Result = C.CUDA_ERROR_LAUNCH_TIMEOUT
    ERROR_LAUNCH_INCOMPATIBLE_TEXTURING  Result = C.CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING
    ERROR_PEER_ACCESS_ALREADY_ENABLED    Result = C.CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED
    ERROR_PEER_ACCESS_NOT_ENABLED        Result = C.CUDA_ERROR_PEER_ACCESS_NOT_ENABLED
    ERROR_PRIMARY_CONTEXT_ACTIVE         Result = C.CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE
    ERROR_CONTEXT_IS_DESTROYED           Result = C.CUDA_ERROR_CONTEXT_IS_DESTROYED
    ERROR_ASSERT                         Result = C.CUDA_ERROR_ASSERT
    ERROR_TOO_MANY_PEERS                 Result = C.CUDA_ERROR_TOO_MANY_PEERS
    ERROR_HOST_MEMORY_ALREADY_REGISTERED Result = C.CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED
    ERROR_HOST_MEMORY_NOT_REGISTERED     Result = C.CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED
    ERROR_UNKNOWN                        Result = C.CUDA_ERROR_UNKNOWN
)

func StreamQuery(stream Stream) Result
    Returns Success if all operations have completed, ErrorNotReady
    otherwise

func (err Result) String() string
    Message string for the error

type Stream uintptr
    CUDA stream.

func StreamCreate() Stream
    Creates an asynchronous stream

func (stream *Stream) Destroy()
    Destroys the asynchronous stream

func (stream Stream) Query() Result
    Returns Success if all operations have completed, ErrorNotReady
    otherwise

func (stream Stream) Synchronize()
    Blocks until the stream has completed.


Documentation

Overview

Package cuda provides GPU interaction

Index

Constants

View Source
const (
	BlockSize    = 512
	TileX, TileY = 32, 32
	MaxGridSize  = 65535
)

CUDA Launch parameters. there might be better choices for recent hardware, but it barely makes a difference in the end.

View Source
const (
	X = 0
	Y = 1
	Z = 2
)
View Source
const CONV_TOLERANCE = 1e-6

Maximum tolerable error on demag convolution self-test.

View Source
const FFT_IMAG_TOLERANCE = 1e-6

Maximum tolerable imaginary/real part for demag kernel in Fourier space. Assures kernel has correct symmetry.

View Source
const REDUCE_BLOCKSIZE = C.REDUCE_BLOCKSIZE

Block size for reduce kernels.

Variables

View Source
var (
	Version     float32 // cuda version
	DevName     string  // GPU name
	TotalMem    int64   // total GPU memory
	GPUInfo     string  // Human-readable GPU description
	Synchronous bool    // for debug: synchronize stream0 at every kernel launch

)

Functions

func AddCubicAnisotropy

func AddCubicAnisotropy(Beff, m *data.Slice, k1_red, k2_red LUTPtr, c1, c2 LUTPtrs, regions *Bytes)

Adds cubic anisotropy field to Beff. see cubicanisotropy.cu

func AddDMI

func AddDMI(Beff *data.Slice, m *data.Slice, Aex_red, Dex_red SymmLUT, regions *Bytes, mesh *data.Mesh)

Add effective field of Dzyaloshinskii-Moriya interaction to Beff (Tesla). According to Bagdanov and Röβler, PRL 87, 3, 2001. eq.8 (out-of-plane symmetry breaking). See dmi.cu

func AddDMIBulk

func AddDMIBulk(Beff *data.Slice, m *data.Slice, Aex_red, Dx_red, Dy_red, Dz_red SymmLUT, regions *Bytes, mesh *data.Mesh)

func AddDotProduct

func AddDotProduct(dst *data.Slice, prefactor float32, a, b *data.Slice)

dst += prefactor * dot(a, b), as used for energy density

func AddExchange

func AddExchange(B, m *data.Slice, Aex_red SymmLUT, regions *Bytes, mesh *data.Mesh)

Add exchange field to Beff.

m: normalized magnetization
B: effective field in Tesla
Aex_red: Aex / (Msat * 1e18 m2)

see exchange.cu

func AddSlonczewskiTorque

func AddSlonczewskiTorque(torque, m, J *data.Slice, fixedP LUTPtrs, Msat, alpha, pol, λ, ε_prime LUTPtr, regions *Bytes, mesh *data.Mesh)

Add Slonczewski ST torque to torque (Tesla). see slonczewski.cu

func AddUniaxialAnisotropy

func AddUniaxialAnisotropy(Beff, m *data.Slice, k1_red LUTPtr, u LUTPtrs, regions *Bytes)

Add uniaxial magnetocrystalline anisotropy field to Beff. see uniaxialanisotropy.cu

func AddZhangLiTorque

func AddZhangLiTorque(torque, m, J *data.Slice, bsat, alpha, xi, pol LUTPtr, regions *Bytes, mesh *data.Mesh)

Add Zhang-Li ST torque (Tesla) to torque. see zhangli.cu

func Buffer

func Buffer(nComp int, size [3]int) *data.Slice

Returns a GPU slice for temporary use. To be returned to the pool with Recycle

func Crop

func Crop(dst, src *data.Slice, offX, offY, offZ int)

Crop stores in dst a rectangle cropped from src at given offset position. dst size may be smaller than src.

func Dot

func Dot(a, b *data.Slice) float32

Dot product.

func ExchangeDecode

func ExchangeDecode(dst *data.Slice, Aex_red SymmLUT, regions *Bytes, mesh *data.Mesh)

func FreeBuffers

func FreeBuffers()

Frees all buffers. Called after mesh resize.

func GPUCopy

func GPUCopy(in *data.Slice) *data.Slice

Returns a copy of in, allocated on GPU.

func GetCell

func GetCell(s *data.Slice, comp, ix, iy, iz int) float32

func GetElem

func GetElem(s *data.Slice, comp int, index int) float32

func Init

func Init(gpu int)

Locks to an OS thread and initializes CUDA for that thread.

func LLNoPrecess

func LLNoPrecess(torque, m, B *data.Slice)

func LLTorque

func LLTorque(torque, m, B *data.Slice, alpha LUTPtr, regions *Bytes)

Landau-Lifshitz torque divided by gamma0:

  • 1/(1+α²) [ m x B + α m x (m x B) ] torque in Tesla m normalized B in Tesla

see lltorque.cu

func Madd2

func Madd2(dst, src1, src2 *data.Slice, factor1, factor2 float32)

multiply-add: dst[i] = src1[i] * factor1 + src2[i] * factor2

func Madd3

func Madd3(dst, src1, src2, src3 *data.Slice, factor1, factor2, factor3 float32)

multiply-add: dst[i] = src1[i] * factor1 + src2[i] * factor2 + src3 * factor3

func MaxAbs

func MaxAbs(in *data.Slice) float32

Maximum of absolute values of all elements.

func MaxVecDiff

func MaxVecDiff(x, y *data.Slice) float64

Maximum of the norms of the difference between all vectors (x1,y1,z1) and (x2,y2,z2)

(dx, dy, dz) = (x1, y1, z1) - (x2, y2, z2)
max_i sqrt( dx[i]*dx[i] + dy[i]*dy[i] + dz[i]*dz[i] )

func MaxVecNorm

func MaxVecNorm(v *data.Slice) float64

Maximum of the norms of all vectors (x[i], y[i], z[i]).

max_i sqrt( x[i]*x[i] + y[i]*y[i] + z[i]*z[i] )

func MemAlloc

func MemAlloc(bytes int64) unsafe.Pointer

Wrapper for cu.MemAlloc, fatal exit on out of memory.

func Memset

func Memset(s *data.Slice, val ...float32)

Memset sets the Slice's components to the specified values. To be carefully used on unified slice (need sync)

func Mul

func Mul(dst, a, b *data.Slice)

multiply: dst[i] = a[i] * b[i]

func NewSlice

func NewSlice(nComp int, size [3]int) *data.Slice

Make a GPU Slice with nComp components each of size length.

func Normalize

func Normalize(vec, vol *data.Slice)

Normalize vec to unit length, unless length or vol are zero.

func Recycle

func Recycle(s *data.Slice)

Returns a buffer obtained from GetBuffer to the pool.

func RegionAddV

func RegionAddV(dst *data.Slice, lut LUTPtrs, regions *Bytes)

dst += LUT[region], for vectors. Used to add terms to excitation.

func RegionDecode

func RegionDecode(dst *data.Slice, lut LUTPtr, regions *Bytes)

decode the regions+LUT pair into an uncompressed array

func RegionSelect

func RegionSelect(dst, src *data.Slice, regions *Bytes, region byte)

select the part of src within the specified region, set 0's everywhere else.

func Resize

func Resize(dst, src *data.Slice, layer int)

Select and resize one layer for interactive output

func SetCell

func SetCell(s *data.Slice, comp int, ix, iy, iz int, value float32)

func SetElem

func SetElem(s *data.Slice, comp int, index int, value float32)

func SetTemperature

func SetTemperature(Bth, noise *data.Slice, temp_red LUTPtr, k2mu0_VgammaDt float64, regions *Bytes)

Set Bth to thermal noise (Brown). see temperature.cu

func ShiftBytes

func ShiftBytes(dst, src *Bytes, m *data.Mesh, shiftX int, clamp byte)

Like Shift, but for bytes

func ShiftX

func ShiftX(dst, src *data.Slice, shiftX int, clampL, clampR float32)

shift dst by shx cells (positive or negative) along X-axis. new edge value is clampL at left edge or clampR at right edge.

func Sum

func Sum(in *data.Slice) float32

Sum of all elements.

func Sync

func Sync()

Synchronize the global stream (usually not needed, done automatically with -sync)

func Zero

func Zero(s *data.Slice)

Set all elements of all components to zero.

Types

type Bytes

type Bytes struct {
	Ptr unsafe.Pointer
	Len int
}

3D byte slice, used for region lookup.

func NewBytes

func NewBytes(Len int) *Bytes

Construct new byte slice with given length.

func (*Bytes) Copy

func (dst *Bytes) Copy(src *Bytes)

Copy on device: dst = src.

func (*Bytes) Download

func (src *Bytes) Download(dst []byte)

Copy to host: dst = src.

func (*Bytes) Free

func (b *Bytes) Free()

Frees the GPU memory and disables the slice.

func (*Bytes) Get

func (src *Bytes) Get(index int) byte

Set one element to value

func (*Bytes) Set

func (dst *Bytes) Set(index int, value byte)

Set one element to value

func (*Bytes) Upload

func (dst *Bytes) Upload(src []byte)

Upload src (host) to dst (gpu).

type DemagConvolution

type DemagConvolution struct {
	// contains filtered or unexported fields
}

Stores the necessary state to perform FFT-accelerated convolution with magnetostatic kernel (or other kernel of same symmetry).

func NewDemag

func NewDemag(inputSize, PBC [3]int, kernel [3][3]*data.Slice) *DemagConvolution

Initializes a convolution to evaluate the demag field for the given mesh geometry.

func (*DemagConvolution) Exec

func (c *DemagConvolution) Exec(B, m, vol *data.Slice, Bsat LUTPtr, regions *Bytes)

Calculate the demag field of m * vol * Bsat, store result in B.

m:    magnetization normalized to unit length
vol:  unitless mask used to scale m's length, may be nil
Bsat: saturation magnetization in Tesla
B:    resulting demag field, in Tesla

func (*DemagConvolution) Free

func (c *DemagConvolution) Free()

type LUTPtr

type LUTPtr unsafe.Pointer // points to 256 float32's

type LUTPtrs

type LUTPtrs []unsafe.Pointer // elements point to 256 float32's

type MFMConvolution

type MFMConvolution struct {
	// contains filtered or unexported fields
}

Stores the necessary state to perform FFT-accelerated convolution

func NewMFM

func NewMFM(mesh *data.Mesh, lift, tipsize float64) *MFMConvolution

Initializes a convolution to evaluate the demag field for the given mesh geometry.

func (*MFMConvolution) Exec

func (c *MFMConvolution) Exec(outp, inp, vol *data.Slice, Bsat LUTPtr, regions *Bytes)

store MFM image in output, based on magnetization in inp.

func (*MFMConvolution) Free

func (c *MFMConvolution) Free()

func (*MFMConvolution) Reinit

func (c *MFMConvolution) Reinit(lift, tipsize float64)

type SymmLUT

type SymmLUT unsafe.Pointer // points to 256x256 symmetric matrix, only lower half stored. See exchange.cu

Directories

Path Synopsis
Go bindings for the CUDA driver API.
Go bindings for the CUDA driver API.
Go bindings for the CUDA CUFFT API.
Go bindings for the CUDA CUFFT API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL