GithubHelp home page GithubHelp logo

architector1324 / easycl2 Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 36 KB

OpenCL based lightweight c computing library

License: GNU General Public License v3.0

C 100.00%
gpgpu gpgpu-computing heterogeneous-parallel-programming library lightweight opencl single-header single-header-lib single-header-library

easycl2's Introduction

Easy Computing Library v2

Overview

EasyCL v2 is open-source (GPL v3) header-only wrapper above OpenCL library. It's designed for easy and convenient use, allowing you to quickly write the host part of the program and flexibly use OpenCL kernels.

The library is built on the original OpenCL 2.0 C Specification. It allows you to bypass some of the inconveniences of the original OpenCL, providing work with abstractions of different levels, provides you to bypass the restriction of hard binding.

First version of this library was made for C++.

Installation

  1. Install OpenCL library on your system.
  2. Clone the repo $ git clone https://github.com/architector1324/EasyCL2.
  3. Copy easycl.h to your project

Hello, World

  1. Copy easycl.h to project folder
  2. Create main.c:
#include <stdio.h>
#include "easycl.h"


int main() {
    // setup program and kernel
    EclProgram_t prog = {};
    eclProgramLoad("main.cl", &prog);

    EclKernel_t kern = {.name = "test"};

    // get platform, setup the computer
    EclPlatform_t plat = {};
    eclGetPlatform(0, &plat);

    EclComputer_t gpu = {};
    eclComputer(0, ECL_DEVICE_GPU, &plat, &gpu);

    // setup data container
    ecl_array(int, a, 12, {}, ECL_BUFFER_WRITE); // ecl::array<int> a[12] = {};
    int b = 5;

    // setup compute frame
    EclFrame_t frame = {
        .prog = &prog,
        .kern = &kern,
        .args = {{ECL_ARG_BUFFER, &a}, {ECL_ARG_VAR, &b, sizeof(int)}},
        .argsCount = 2
    };

    // 12 compute units combined into 3 groups
    eclComputerSend(&a, &gpu, ECL_EXEC_SYNC);
    eclComputerGrid(&frame, (EclWorkSize_t){.dim = 1, .sizes={12}}, (EclWorkSize_t){.dim = 1, .sizes={3}}, &gpu, ECL_EXEC_SYNC);
    eclComputerReceive(&a, &gpu, ECL_EXEC_SYNC);

    // output
    for(size_t i = 0; i < 12; i++)
        printf("%d\n", ((const int*)a.data)[i]);

    // clean resources
    eclBufferClear(&a);

    eclComputerClear(&gpu);
    eclPlatformClear(&plat);

    eclKernelClear(&kern);
    eclProgramClear(&prog);

    return 0;
}
  1. Create main.cl:
kernel void test(global int* a, int b){
    size_t i = get_global_id(0);
    a[i] = b * ((int)get_group_id(0) + 1);
}
  1. Type in terminal:
$ gcc -O3 -lOpenCL main.c -o a.out
$ ./a.out

Output:

5
5
5
10
10
10
15
15
15
20
20
20

If you have any questions, feel free to contact me [email protected]

easycl2's People

Contributors

architector1324 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.