All Projects → agency-library → Agency

agency-library / Agency

Licence: other
Execution primitives for C++

Programming Languages

cpp
1120 projects

Projects that are alternatives of or similar to Agency

Threadly
A library of tools to assist with safe concurrent java development. Providing unique priority based thread pools, and ways to distrbute threaded work safely.
Stars: ✭ 196 (+54.33%)
Mutual labels:  concurrency, threading, thread-pool
Floyd
The Floyd programming language
Stars: ✭ 133 (+4.72%)
Mutual labels:  concurrency, parallelism, threading
thread-pool
A modern thread pool implementation based on C++20
Stars: ✭ 104 (-18.11%)
Mutual labels:  concurrency, threading, thread-pool
Pht
A new threading extension for PHP
Stars: ✭ 175 (+37.8%)
Mutual labels:  concurrency, parallelism, threading
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+51.97%)
Mutual labels:  concurrency, parallelism, thread-pool
thread-pool
BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library
Stars: ✭ 1,043 (+721.26%)
Mutual labels:  concurrency, threading, thread-pool
Hamsters.js
100% Vanilla Javascript Multithreading & Parallel Execution Library
Stars: ✭ 517 (+307.09%)
Mutual labels:  concurrency, parallelism, thread-pool
Async Techniques Python Course
Async Techniques and Examples in Python Course
Stars: ✭ 314 (+147.24%)
Mutual labels:  parallelism, threading
Concurrencpp
Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all
Stars: ✭ 340 (+167.72%)
Mutual labels:  concurrency, threading
Rust Threadpool
A very simple thread pool for parallel task execution
Stars: ✭ 374 (+194.49%)
Mutual labels:  parallelism, thread-pool
Start
🔴 Functional task runner for Node.js
Stars: ✭ 478 (+276.38%)
Mutual labels:  concurrency, parallelism
Bild
Image processing algorithms in pure Go
Stars: ✭ 3,431 (+2601.57%)
Mutual labels:  concurrency, parallelism
Concurrency Glossary
🦑 Informal definitions of terms used in concurrency modeling
Stars: ✭ 276 (+117.32%)
Mutual labels:  concurrency, parallelism
Crossbeam
Tools for concurrent programming in Rust
Stars: ✭ 4,180 (+3191.34%)
Mutual labels:  concurrency, parallelism
Onetbb
oneAPI Threading Building Blocks (oneTBB)
Stars: ✭ 3,284 (+2485.83%)
Mutual labels:  parallelism, threading
Fetch
Simple & Efficient data access for Scala and Scala.js
Stars: ✭ 453 (+256.69%)
Mutual labels:  concurrency, parallelism
vercors
The VerCors verification toolset for verifying parallel and concurrent software
Stars: ✭ 30 (-76.38%)
Mutual labels:  concurrency, parallelism
Thread Pool
Thread pool implementation using c++11 threads
Stars: ✭ 417 (+228.35%)
Mutual labels:  concurrency, thread-pool
Concurrency
Java 并发编程知识梳理以及常见处理模式 features and patterns
Stars: ✭ 495 (+289.76%)
Mutual labels:  concurrency, thread-pool
Concurrent Programming
🌵《实战java高并发程序设计》源码整理
Stars: ✭ 562 (+342.52%)
Mutual labels:  concurrency, thread-pool

What is Agency?

Agency is an experimental C++ template library for parallel programming. Unlike higher-level parallel algorithms libraries like Thrust, Agency provides lower-level primitives for creating execution. Agency interoperates with standard components like execution policies and executors to enable the creation of portable parallel algorithms.

Examples

Agency is best-explained through examples. The following program implements a parallel sum.

#include <agency/agency.hpp>
#include <agency/experimental.hpp>
#include <vector>
#include <numeric>
#include <iostream>
#include <cassert>

int parallel_sum(int* data, int n)
{
  // create a view of the input
  agency::experimental::span<int> input(data, n);

  // divide the input into 8 tiles
  int num_agents = 8;
  auto tiles = agency::experimental::tile_evenly(input, num_agents);

  // create 8 agents to sum each tile in parallel
  auto partial_sums = agency::bulk_invoke(agency::par(num_agents), [=](agency::parallel_agent& self)
  {
    // get this parallel agent's tile
    auto this_tile = tiles[self.index()];

    // return the sum of this tile
    return std::accumulate(this_tile.begin(), this_tile.end(), 0);
  });

  // return the sum of partial sums
  return std::accumulate(partial_sums.begin(), partial_sums.end(), 0);
}

int main()
{
  // create a large vector filled with 1s
  std::vector<int> vec(32 << 20, 1);

  int sum = parallel_sum(vec.data(), vec.size());

  std::cout << "sum is " << sum << std::endl;

  assert(sum == vec.size());

  return 0;
}

This code example implements a vector sum operation and executes it sequentially, in parallel, in parallel on a single GPU, and finally multiple GPUs:

#include <agency/agency.hpp>
#include <agency/cuda.hpp>
#include <vector>
#include <cassert>
#include <iostream>
#include <algorithm>

int main()
{
  using namespace agency;

  // allocate data in GPU memory
  using vector = std::vector<float, cuda::managed_allocator<float>>;

  size_t n = 1 << 20;
  float a = 13;
  vector x(n, 1);
  vector y(n, 2);
  vector z(n, 0);

  vector reference(n, 13 * 1 + 2);

  float* x_ptr = x.data();
  float* y_ptr = y.data();
  float* z_ptr = z.data();


  // execute sequentially in the current thread
  bulk_invoke(seq(n), [=](sequenced_agent& self)
  {
    int i = self.index();
    z_ptr[i] = a * x_ptr[i] + y_ptr[i];
  });

  assert(z == reference);
  std::fill(z.begin(), z.end(), 0);


  // execute in parallel on the CPU
  bulk_invoke(par(n), [=](parallel_agent& self)
  {
    int i = self.index();
    z_ptr[i] = a * x_ptr[i] + y_ptr[i];
  });

  assert(z == reference);
  std::fill(z.begin(), z.end(), 0);


  // execute in parallel on a GPU
  cuda::grid_executor gpu;
  bulk_invoke(par(n).on(gpu), [=] __device__ (parallel_agent& self)
  {
    int i = self.index();
    z_ptr[i] = a * x_ptr[i] + y_ptr[i];
  });

  assert(z == reference);
  std::fill(z.begin(), z.end(), 0);
  

  // execute in parallel on all GPUs in the system
  cuda::multidevice_executor all_gpus;
  bulk_invoke(par(n).on(all_gpus), [=] __device__ (parallel_agent& self)
  {
    int i = self.index();
    z_ptr[i] = a * x_ptr[i] + y_ptr[i];
  });

  assert(z == reference);
  std::fill(z.begin(), z.end(), 0);


  std::cout << "OK" << std::endl;
  return 0;
}

Discover the Library

Agency is an NVIDIA Research project.

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].