All Projects → damienpontifex → SwiftOpenCL

damienpontifex / SwiftOpenCL

Licence: MIT license
A swift wrapper around OpenCL. Modelled off the cpp wrapper

Programming Languages

swift
15916 projects

Labels

Projects that are alternatives of or similar to SwiftOpenCL

Opencl.jl
OpenCL Julia bindings
Stars: ✭ 216 (+1170.59%)
Mutual labels:  opencl
gpuowl
GPU Mersenne primality test.
Stars: ✭ 77 (+352.94%)
Mutual labels:  opencl
CLBLAS.jl
CLBLAS integration for Julia
Stars: ✭ 20 (+17.65%)
Mutual labels:  opencl
Occa
JIT Compilation for Multiple Architectures: C++, OpenMP, CUDA, HIP, OpenCL, Metal
Stars: ✭ 230 (+1252.94%)
Mutual labels:  opencl
mcxcl
Monte Carlo eXtreme for OpenCL (MCXCL)
Stars: ✭ 36 (+111.76%)
Mutual labels:  opencl
coriander-dnn
Partial implementation of NVIDIA® cuDNN API for Coriander, OpenCL 1.2
Stars: ✭ 22 (+29.41%)
Mutual labels:  opencl
Cuetools.net
CD image processing suite with optimized lossless encoders in C#
Stars: ✭ 208 (+1123.53%)
Mutual labels:  opencl
ck-clsmith
Collective Knowledge extension to crowdsource bug detection in OpenCL compilers using CLSmith tool from Imperial College London
Stars: ✭ 26 (+52.94%)
Mutual labels:  opencl
PengueeBot
Automation tool, visit our discord channel if you have anything to ask
Stars: ✭ 27 (+58.82%)
Mutual labels:  opencl
OpenCLRenderer
3D renderer built in C++/OpenCL
Stars: ✭ 29 (+70.59%)
Mutual labels:  opencl
Computecpp Sdk
Collection of samples and utilities for using ComputeCpp, Codeplay's SYCL implementation
Stars: ✭ 239 (+1305.88%)
Mutual labels:  opencl
fahbench
Folding@home GPU benchmark
Stars: ✭ 32 (+88.24%)
Mutual labels:  opencl
CUDAfy.NET
CUDAfy .NET allows easy development of high performance GPGPU applications completely from the .NET. It's developed in C#.
Stars: ✭ 56 (+229.41%)
Mutual labels:  opencl
Pysph
A framework for Smoothed Particle Hydrodynamics in Python
Stars: ✭ 223 (+1211.76%)
Mutual labels:  opencl
fluctus
An interactive OpenCL wavefront path tracer
Stars: ✭ 55 (+223.53%)
Mutual labels:  opencl
Bohrium
Automatic parallelization of Python/NumPy, C, and C++ codes on Linux and MacOSX
Stars: ✭ 209 (+1129.41%)
Mutual labels:  opencl
BruteForce
A simple brute forcer written in GO for SHA1, SHA256, SHA512, MD5 and bcrypt
Stars: ✭ 49 (+188.24%)
Mutual labels:  opencl
vexed-generation
Polymorphic helper functions & geometry ops for Houdini VEX / OpenCL
Stars: ✭ 32 (+88.24%)
Mutual labels:  opencl
hpc
Learning and practice of high performance computing (CUDA, Vulkan, OpenCL, OpenMP, TBB, SSE/AVX, NEON, MPI, coroutines, etc. )
Stars: ✭ 39 (+129.41%)
Mutual labels:  opencl
opencl-in-action-swift
Generating OpenCL code using Swift and Grand Central Dispatch's OpenCL integration with Xcode. A direct reimplementation of the source code from the book 'OpenCL in Action' by Matthew Scarpino
Stars: ✭ 15 (-11.76%)
Mutual labels:  opencl

SwiftOpenCL

Build Status

A swift wrapper around OpenCL inspired the C++ object wrapper.

Interfacing with C libraries from Swift is a pain. Alongside this, the OpenCL library is quite verbose to setup a working environment. This is the start of a Swift wrapper around the OpenCL API.

Developers

To generate an Xcode project for development run

swift package generate-xcodeproj

Using Swift Package Manager

Sample Package.swift file

import PackageDescription

let package = Package(
    name: "<Project Name>",
    dependencies: [
        .Package(url: "https://github.com/damienpontifex/SwiftOpenCL.git", majorVersion: 0)
    ]
)

Sample main.swift file

import SwiftOpenCL
#if os(Linux)
//TODO: Add OpenCL module import for Linux
#else
import OpenCL
#endif

let platforms = Platform.all

for platform in platforms {
    guard let extensions = platform.getInfo(CL_PLATFORM_EXTENSIONS) else {
        continue
    }
    
    print(extensions)
}

Sample usage

A simple vector addition kernel.

guard let device = Device.default() else {
    exit(EXIT_FAILURE)
}

do {
    print("Using device \(device)")
    let context = try Context(device: device)
    
    let aInput: [cl_float] = [1, 2, 3, 4]
    let bInput: [cl_float] = [5, 6, 7, 8]
    
    let a = try Buffer<cl_float>(context: context, readOnlyData: aInput)
    let b = try Buffer<cl_float>(context: context, readOnlyData: bInput)
    let c = try Buffer<cl_float>(context: context, count: 4)
    
    let source =
    "__kernel void add(__global const float *a," +
    "                  __global const float *b," +
    "                  __global float *c)" +
    "{" +
    "    const uint i = get_global_id(0);" +
    "    c[i] = a[i] + b[i];" +
    "}";
    
    let program = try Program(context: context, programSource: source)
    try program.build(device)
    
    let kernel = try Kernel(program: program, kernelName: "add")
    
    try kernel.setArgs(a, b, c)
    
    let queue = try CommandQueue(context: context, device: device)
    
    let range = NDRange(size: 4)
    try queue.enqueueNDRangeKernel(kernel, offset: NDRange(size: 0), global: range)
    
    let cResult = c.enqueueRead(queue)
    
    print("a: \(aInput)")
    print("b: \(bInput)")
    print("c: \(cResult)")
    
} catch let error as ClError {
    print("Error \(error.err). \(error.errString)")
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].