Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1001 commits
Select commit Hold shift + click to select a range
d336d6a
Updated tests.
May 27, 2026
7a197f9
added nan tests
May 27, 2026
d9bbabb
updated methods to take in dloat or double
May 27, 2026
fb1cfc0
updated tests
May 27, 2026
48c3112
added a facade bicgstab solver actor
May 27, 2026
f2fa5bc
implemented facade actor for CGS solver
May 27, 2026
1fd80ff
accomdatedf changes made to cgs actor
May 27, 2026
0c81b14
changed cgs actor to be more like actor facade and added more tests
May 27, 2026
aac227d
updated solver facade to be more like actor facade and adjusted tests…
May 27, 2026
bb03ce2
made private methods protected so child classes can access them and m…
May 28, 2026
9fedddb
added cache tables for program_ptr
May 28, 2026
df6e070
imlpemented CGS solver with jacobio preconditioner
May 28, 2026
52336e9
updated Cmakelists to auto compile .cu files found in the caf directoryu
May 28, 2026
482b7bb
fixed bug in s_elementwise_multiply
May 28, 2026
e1abe38
updated tests to test the jacobi actor facade
May 28, 2026
66bd1d9
implemented jacobi preconditioner solver
May 28, 2026
9207f72
modified jacobi actor to pass tests
May 28, 2026
56bd1f3
added more tests
May 28, 2026
ad15c8e
Updated cmakelists to compile correctly.
May 28, 2026
1124f8b
Fixed build.
May 28, 2026
dc83f2d
created initial version of GMRES actor
May 28, 2026
b653ae3
updated includes
May 28, 2026
a313b1b
Initial commit.
May 28, 2026
9428abc
added sscal and dscal operations to this call
May 28, 2026
a489e36
moved atom declaration into global.hpp
May 29, 2026
30b4149
updated actors to return metadata reguarding the solver and their dev…
May 29, 2026
b7218f6
updated test to accomodate changes in message passing interface
May 29, 2026
1847b68
Initial commit.
May 29, 2026
46c3df7
added real world matirx test
May 29, 2026
17295b4
updated CGS actor to accomodate doubles
May 29, 2026
5982872
added x vector to robust solver state.
May 29, 2026
aa7127b
put actor facades in array to increase efficieny
May 29, 2026
ff72047
Initial commit.
May 29, 2026
e77398e
updated test to actually work
May 29, 2026
72031b3
updated script to handle the gmres actor correctly.
May 29, 2026
97de8b7
updated cmakelists
Jun 1, 2026
aefee89
updated tests to work on a batch system where we add a sleep timer an…
Jun 1, 2026
07fa41b
updated cmakelists
Jun 1, 2026
8bf70b0
fixed compiler errors
Jun 1, 2026
200d486
updated workload generation to be equal
Jun 1, 2026
b77fb47
added parameter for batches
Jun 1, 2026
cb48b95
putting fault tolerance tests in here
Jun 1, 2026
597d8a1
updated implementations
Jun 1, 2026
4a0f7ca
updated code
Jun 1, 2026
96e8434
updated test
Jun 1, 2026
648408f
Implemented an optimized CG solver actor facade
Jun 1, 2026
6668882
updated tests to test optmized CG actor
Jun 1, 2026
57ac2bb
fixed complier errors
Jun 1, 2026
4039e9d
made changes to dispatch method to fix issue with the optmizied actor…
Jun 1, 2026
d9616c9
updated test to use a better CG actor
Jun 1, 2026
fe4ba17
made changes to optimized CGS actor so it can distinguish format, adj…
Jun 1, 2026
2d55914
updated paths of files being read to point to a better dataset
Jun 1, 2026
5817710
refactored code to keep everything in the same file where possible
Jun 2, 2026
8e53135
updated test to be produced consumer
Jun 2, 2026
2f14daa
updated cuda to be a stream worker model instead of a single device …
Jun 2, 2026
dc49f7c
updated producer thread to have a batch model where it dispatches ba…
Jun 2, 2026
3e4e4b2
updated batch size to be bigger
Jun 2, 2026
22b0bf2
refactored code by moving batch generation and sleep interval generat…
Jun 2, 2026
677604f
modified actor test to be more producer consumer like and similar to …
Jun 2, 2026
02ee344
moved actor facade into worker actor state to prevent creation overhead
Jun 2, 2026
645c464
removed device actor to see if there is a bottleneck
Jun 3, 2026
a5e98e0
updated exampel to align with changes made to asynchronous message pa…
Jun 3, 2026
ffdba5d
updated cmakelists
Jun 3, 2026
6c9fd03
updated cmakelists
Jun 3, 2026
ba77cf5
updated examples to work again
Jun 3, 2026
3dfeb63
Intial commit
Jun 3, 2026
9673d37
added parition logic
Jun 3, 2026
63f4f43
updated parsing logic
Jun 3, 2026
a8873f1
added commented out implementation
Jun 3, 2026
aa3cd5b
added logic for actors to create interact and message pass events
Jun 3, 2026
ad4a852
commented out hot potatoe
Jun 4, 2026
04d4ea2
made work stealing model
Jun 4, 2026
2c5a541
broke circular dependency between global.hpp and this file
Jun 4, 2026
3ab301d
fixed deadlock
Jun 4, 2026
f7965b4
initial commit
Jun 4, 2026
9d211ec
saving
Jun 4, 2026
cd2a5d2
created supervisor
Jun 4, 2026
f5ff827
added statfuel cgs actor
Jun 4, 2026
db8b30a
moved sparse utils
Jun 4, 2026
0cd4e94
SAVIONG>
Jun 4, 2026
e4550c2
got code working (somewhat)
Jun 4, 2026
6c0cef4
added kernel compilation
Jun 4, 2026
b52fe84
fixed issues
Jun 4, 2026
ddc87e3
saving
Jun 4, 2026
57a6af6
fixed illegal memory access issues
Jun 4, 2026
f7e64a4
added better logging
Jun 4, 2026
6187bb9
uped the iteration count
Jun 4, 2026
a15ca04
added timer values
Jun 4, 2026
454f012
updated solvers to match
Jun 4, 2026
a12958e
Incorporate methods to copy back to host on other streams other than …
Jun 4, 2026
bd36925
added makespan timer
Jun 4, 2026
4b446cf
implemented a free memory command
Jun 4, 2026
3c65424
made changes to memory cleanup
Jun 4, 2026
f3b06a3
fixed syntax error
Jun 4, 2026
928527e
fixed syntax errors
Jun 4, 2026
b01f68f
updated code to fix an exit race condition where actor id was being r…
Jun 5, 2026
c2445ac
updated stream allocation logic to prevent crashes
Jun 5, 2026
bce84ca
fixed premature shutdown error
Jun 5, 2026
0a1ae60
created a sorted version of the producer consumer problem. modified f…
Jun 5, 2026
6e9ef88
fixed compiler errors
Jun 5, 2026
89ce705
updated formats
Jun 5, 2026
1afc0f3
updated formating
Jun 5, 2026
93cf9b8
turned this into round robin I guess
Jun 5, 2026
e302b27
added task failed and succeded count here
Jun 5, 2026
1d321b0
updated round robin iteration to fix bug where crossing streams lead …
Jun 5, 2026
bca773d
updated counting
Jun 5, 2026
754932f
updated a bunch of stuff
Jun 8, 2026
15fe4da
added a three strikes policy for work, since it may recover
Jun 8, 2026
6817bee
expanded code to be multiple GPU
Jun 8, 2026
8b5c873
added job statistics tracking
Jun 8, 2026
9bb7912
updated code to trakc job progress
Jun 8, 2026
84e2a2f
updated report format at the end
Jun 8, 2026
0df5429
added more stats
Jun 8, 2026
243e6c9
updated actor facade tests
Jun 8, 2026
2ede92d
updated scripts to include new actor facade
Jun 8, 2026
119933f
updated title
Jun 8, 2026
79b3d12
updated
Jun 8, 2026
fb1eb14
updated to be better
Jun 8, 2026
163e8b6
added producer actor
Jun 8, 2026
c1cb8d7
fixed issues
Jun 8, 2026
2e2add8
added timing logic
Jun 8, 2026
5775bff
fixed exit deadlock
Jun 8, 2026
34be706
updated facade to take in mem_ptrs
Jun 8, 2026
7050482
implemented prefetching
Jun 8, 2026
1f4559f
fixed oom issue
Jun 8, 2026
0afb549
really fixed oom this time
Jun 8, 2026
1196608
Updated makefile to link with cublas and cusparse.
Jun 9, 2026
4f8f870
Updated filepaths to mmul.cubin to fix filenotfounderror.
Jun 9, 2026
99b06e9
updated cuda to contain the proper experiment and updated the filepat…
Jun 9, 2026
a4dd0f6
updated script to parse output file
Jun 9, 2026
ffe6d96
updated script to draw cuda native plot
Jun 9, 2026
791e01e
Updated makefile to build correctly.
Jun 9, 2026
0601dbb
Updated file paths.
Jun 9, 2026
816459d
updated test and filepaths
Jun 9, 2026
74575ca
updated tests and filepaths
Jun 9, 2026
96b3eb6
refactored scheduler actor to have a cleaner interface
Jun 9, 2026
c4d14a6
updated stream management to manage depth of stream
Jun 9, 2026
41458ee
updated manager to create the new scheduler actor
Jun 9, 2026
703f8e0
updated script to parse data
Jun 9, 2026
5c001f4
inital commit
Jun 9, 2026
33cdb34
moved file to right location
Jun 9, 2026
fa1009b
updated tests to be more alike
Jun 9, 2026
b11827b
updated cmakelists
Jun 9, 2026
1e6371d
fixed compiler errors
Jun 9, 2026
6f78d6c
updated test
Jun 9, 2026
d34b608
exporting to make visibile
Jun 9, 2026
d978709
fixed test
Jun 9, 2026
7352b97
fixed oom error
Jun 10, 2026
6fd59e1
fixed errors with the timer
Jun 10, 2026
9218736
split actors into seperate files
Jun 10, 2026
da501e5
fixed compiler errors
Jun 10, 2026
c37be31
fixed errors
Jun 10, 2026
38794cc
fixed illegal operation error
Jun 10, 2026
6059c2d
Intial commit.
Jun 10, 2026
0144d8f
updated cmakelists to build with changes
Jun 10, 2026
b324348
Saving.
Jun 10, 2026
442942d
Initial commit.
Jun 10, 2026
88000c1
Added jacobi fallback.
Jun 10, 2026
2a7ea73
made some changes to that if the actor decides to go jacobi, its iter…
Jun 10, 2026
702b9a2
Reverting changes.
Jun 10, 2026
150a017
added jacobi fallback mechanism
Jun 10, 2026
114f26e
updated worker to keep memory on device if it uses jacobi fallback
Jun 10, 2026
c5e06ab
made changes to work stealing policy in an attempt to reduce thrashing
Jun 10, 2026
2ed6371
fixed invalid memory access
Jun 10, 2026
09f8b9a
updated giveaway threshold
Jun 10, 2026
99370b5
updated work stealing thresholds
Jun 10, 2026
220439c
moved capacity back to what it was
Jun 11, 2026
c9fe798
added error codes
Jun 11, 2026
18323e3
removed while loop that dictated that solve cg async must be performe…
Jun 11, 2026
dac8b0c
updated some values
Jun 11, 2026
154b27d
updated logging and filepaths
Jun 11, 2026
729a07b
updated filepath
Jun 11, 2026
ff5fc5e
added more logs
Jun 11, 2026
1d618ac
updated min giveaway threshold
Jun 11, 2026
2a9cd4f
updated giveawaythreshold
Jun 11, 2026
3df8808
implemented an exponential backoff polocy to try and reduce overhead …
Jun 11, 2026
1b796ca
updated timer values
Jun 11, 2026
ad7ef45
updated log messages
Jun 11, 2026
1cb4e2c
made changes to limit the number of actors within the system
Jun 12, 2026
850709f
reverting back since the worker actors will act as bottleneck
Jun 12, 2026
cad0170
updated test to partiton the worklaod based on number of GPUs
Jun 12, 2026
a18ece3
added method to send scheduler actor a single message
Jun 16, 2026
7622908
updated methosd to return custreams and cucontexts if the user wants
Jun 16, 2026
c43c2e8
updated mmul actor to be more efficient with CPU-GPU synchronization
Jun 16, 2026
795d711
updated kerenl done atom to fix deadlock occurance
Jun 16, 2026
1537d9b
made copying to host more efficient
Jun 16, 2026
2254715
Initial commit.
Jun 17, 2026
77c39dd
Updated cmakelists to build properly
Jun 17, 2026
4ae8902
Updated script
Jun 17, 2026
d6fede9
Updated test to almost work correctly.
Jun 17, 2026
e6ab2d2
Made changes to fix intial OOM errors and attempt to add more memory …
Jun 17, 2026
9170d30
made out size be sizet type to prevent integer overflow errors
Jun 17, 2026
8bb6477
Updated test to have memory checks.
Jun 17, 2026
b625800
Saving current test. In theory recovery is possible but in practice.
Jun 17, 2026
c76ffef
Added random exponential backoff as a means of coordinating retries.
Jun 17, 2026
21b38b5
Added restart limits and statistics tracking to bad jobs.
Jun 17, 2026
8d1ac0f
Moved data reporting to stats actor and put memory pressure to all GP…
Jun 17, 2026
4b44295
Added job retry stats tracking.
Jun 17, 2026
6573f63
Updated test to track stats better.
Jun 17, 2026
caa3867
update matrix sizes to introduce more variability
Jun 17, 2026
63506b4
updated documentation to include info about the scheduler actor
Jun 17, 2026
639834f
added compiler flags to remove compiler warnings
Jun 17, 2026
b611421
updated tests to align more with the new scheduler actors functionality
Jun 18, 2026
241b222
updated test to align with new scheduler actor changes
Jun 18, 2026
f158bc4
Removed legacy tests.
Jun 18, 2026
7b5e017
updated docs to contain section with Native CUDA compatability
Jun 19, 2026
0def0c5
added cuda variant to this for comparisions
Jun 19, 2026
0937ba3
updated the number of streams
Jun 19, 2026
7a7f523
updated test to increase GPU performance by making supervisor actors …
Jun 19, 2026
0cc8699
updated test to be multidevice compatablie
Jun 19, 2026
9cb6ebf
fixed issue in scheduling logic where supervisor would release their …
Jun 19, 2026
f63c371
updated code to be more multi device friendly
Jun 19, 2026
c4c1a20
updated worker to use driver api
Jun 19, 2026
2e1b53d
updated type id registration to reduce possibility of collisions
Jun 19, 2026
025e7db
Deleted redundant files and modified existing files to no longer refe…
Jun 19, 2026
6d677a5
updated experiment to use the new scheduler actor
Jun 22, 2026
46c7bd7
updated scripts
Jun 22, 2026
3c775e4
Moved files from workloadA over here.
Jun 22, 2026
023c7c9
Moved files into this directory.
Jun 22, 2026
3215412
added script to download matrix from suitesparse collection
Jun 22, 2026
4ec637d
add scripts to download workloadB matrices from suitesparse collection
Jun 22, 2026
4aa7e8b
Updated scripts.
Jun 22, 2026
3eb82c7
Fixed build issues.
Jun 22, 2026
c12bf18
fixed build issues
Jun 22, 2026
fd5190e
updated filepaths
Jun 22, 2026
d227bdc
updated file paths
Jun 22, 2026
ebcc3ea
implemented different levels of memory pressure testing
Jun 22, 2026
59daabf
fixed synchronization error between runs where memory would still be …
Jun 22, 2026
73812df
updated pressure levels to trigger more faults
Jun 22, 2026
9587a73
added throughput counter
Jun 22, 2026
c32f3bd
Updated cuda baseline to be like static round robin partioning of 500…
Jun 23, 2026
429d231
Fixed cuda error.
Jun 23, 2026
b33a443
Fixing invalid moduel error.
Jun 23, 2026
b9a7097
Fixing invalid moduel error.
Jun 23, 2026
8e088fb
Fixing invalid moduel error.
Jun 23, 2026
11dce8f
Changed test to do static round robin partitioning of the GPUs.
Jun 23, 2026
996a270
Fixed rng issue.
Jun 23, 2026
99c6137
Fixed rng issue.
Jun 23, 2026
0be82c9
Fixed rng issue.
Jun 23, 2026
62c1e79
Fixed tests to make more rigourous.
Jun 23, 2026
a524cbd
Fixed error in stream and device allocation.
Jun 23, 2026
d49e28f
CHANGED stream settings to match caf cuda.
Jun 23, 2026
9813f34
updated to make setting more identical to caf cuda
Jun 23, 2026
ad0ab66
made changes to hopefully alleviate CPU bottleneck
Jun 23, 2026
bbdee31
Fixed errors with device and steram selection.
Jun 23, 2026
c8a9e78
corrected filepath
Jun 24, 2026
235db4b
Updated stuff to actually compile in accordance to AD.
Jun 24, 2026
839e747
Removed directory since not being used.
Jun 24, 2026
62238a4
updated paths to work with AD build process.
Jun 24, 2026
8d811fa
Updated filepaths.
Jun 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 23 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.make-release-steps.bash
.push-doxygen-steps.bash
Makefile
# Makefile
bin/*
build/*
doxygen-log.txt
Expand All @@ -11,3 +11,25 @@ manual/libcaf_core
manual/libcaf_io
manual/libcaf_net
manual/libcaf_openssl
libcaf_cuda/sc26/Runtime-Overhead/compile.sh
libcaf_cuda/sc26/Runtime-Overhead/cuda_native
libcaf_cuda/sc26/Runtime-Overhead/mmul.cubin
libcaf_cuda/sc26/Sequence-Independent-Tasks/compile.sh
libcaf_cuda/sc26/Runtime-Overhead/command_runner
libcaf_cuda/sc26/Fault-Tolerance/compile.sh
libcaf_cuda/sc26/Fault-Tolerance/main
libcaf_cuda/sc26/Runtime-Overhead/actor_facade
libcaf_cuda/sc26/Fault-Tolerance/monte_carlo.cubin
libcaf_cuda/sc26/Sequence-Independent-Tasks/main_actor_facade
libcaf_cuda/sc26/Sequence-Independent-Tasks/main_command_runner
libcaf_cuda/sc26/Sequence-Independent-Tasks/main_cuda_native
libcaf_cuda/sc26/Sequence-Independent-Tasks/mmul.cubin
libcaf_cuda/sc26/Fault-Tolerance/run.log
libcaf_cuda/sc26/Fault-Tolerance/baseline.log
libcaf_cuda/sc26/benchmarks/__pycache__/
libcaf_cuda/sc26/scripts/Fault-Tolerance/.venv/
libcaf_cuda/sc26/scripts/Fault-Tolerance/plots
libcaf_cuda/sc26/Runtime-Overhead/results/benchmark_results.txt
libcaf_cuda/sc26/Runtime-Overhead/results/benchmark_results_1.txt
libcaf_cuda/sc26/Sequence-Independent-Tasks/results/cleaned.txt
libcaf_cuda/sc26/Sequence-Independent-Tasks/results/benchmark_results.txt
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ option(CAF_ENABLE_QT6_EXAMPLES "Build examples with the Qt6 framework" OFF)
option(CAF_ENABLE_ROBOT_TESTS "Add the Robot tests to CTest " OFF)
option(CAF_ENABLE_RUNTIME_CHECKS "Build CAF with extra runtime assertions" OFF)
option(CAF_USE_STD_FORMAT "Enable std::format support" OFF)
option(CAF_ENABLE_CUDA "Build caf with cuda support" OFF)
option(CAF_ENABLE_CUDA "Build caf with cuda support" ON)

# -- CAF options that are on by default ----------------------------------------

Expand Down
50 changes: 40 additions & 10 deletions libcaf_cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
#project(caf_opencl C CXX)
include(CMakePrintHelpers)


#get the cuda related dependencies
# Get the cuda related dependencies first so we have the nvcc path
find_package(CUDAToolkit REQUIRED)

# Set the GPU architecture. 'native' detects the local GPU capability.
# You can override this with -DCAF_CUDA_ARCH=sm_80 for example.
set(CAF_CUDA_ARCH "native" CACHE STRING "Target CUDA architecture (e.g., sm_70, native)")

# Find all .cu files recursively in the caf/ directory relative to this CMakeLists.txt
file(GLOB_RECURSE CAF_CUDA_KERNELS "${CMAKE_CURRENT_SOURCE_DIR}/caf/*.cu")

foreach(CU_FILE ${CAF_CUDA_KERNELS})
# Get the base name of the .cu file (e.g., "some_kernel")
get_filename_component(BASENAME ${CU_FILE} NAME_WE)
# Get the directory of the .cu file (e.g., "/path/to/libcaf_cuda/caf/cuda")
get_filename_component(DIRNAME ${CU_FILE} DIRECTORY)

# Construct the output .cubin file path (e.g., "/path/to/libcaf_cuda/caf/cuda/some_kernel.cubin")
set(CUBIN_FILE "${DIRNAME}/${BASENAME}.cubin")

# Create a unique target name based on the relative path to avoid collisions
file(RELATIVE_PATH REL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/caf" ${CU_FILE})
string(MAKE_C_IDENTIFIER "cubin_${REL_PATH}" TARGET_NAME)

# Add a custom command to compile the .cu file into a .cubin
add_custom_command(
OUTPUT ${CUBIN_FILE}
COMMAND ${CUDAToolkit_NVCC_EXECUTABLE}
-cubin
-arch=${CAF_CUDA_ARCH}
-o ${CUBIN_FILE}
${CU_FILE}
DEPENDS ${CU_FILE}
COMMENT "Compiling CUDA kernel ${CU_FILE} to ${CUBIN_FILE}"
VERBATIM
)

# Add a custom target to ensure the cubin is built.
add_custom_target(${TARGET_NAME} ALL DEPENDS ${CUBIN_FILE})
endforeach()

# get header files; only needed by CMake generators,
# e.g., for creating proper Xcode projects
file(GLOB_RECURSE CAF_CUDA_HEADERS "caf/*.hpp")
Expand All @@ -14,14 +50,8 @@ file(GLOB_RECURSE CAF_CUDA_HEADERS "caf/*.hpp")


# list cpp files excluding platform-dependent files
set(LIBCAF_CUDA_SRCS
src/manager.cpp
src/platform.cpp
src/program.cpp
src/helpers.cpp
src/test.cpp
src/scheduler.cpp
src/streampool.cpp
file(GLOB_RECURSE LIBCAF_CUDA_SRCS
src/*.cpp
)

# -- add targets ---------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions libcaf_cuda/caf/actorBLAS/actorBLAS.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
#include "caf/actorBLAS/gemv-actor/gemv-actor.hpp"
#include "caf/actorBLAS/syrk-actor/syrk-actor.hpp"
#include "caf/actorBLAS/axpy-actor/axpy-actor.hpp"
130 changes: 130 additions & 0 deletions libcaf_cuda/caf/actorBLAS/axpy-actor/axpy-actor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#pragma once

#include <caf/actor.hpp>
#include <caf/actor_cast.hpp>
#include <caf/actor_config.hpp>
#include <caf/actor_system.hpp>
#include <caf/anon_mail.hpp>
#include <caf/event_based_actor.hpp>

#include "caf/cuda/device.hpp"
#include "caf/cuda/mem_ref.hpp"
#include "caf/cuda/command_runner.hpp"
#include "caf/cuda/platform.hpp"
#include "caf/cuda/types.hpp"

namespace caf::cuda {

/// AXPY Actor for single-precision vector-vector addition.
/// Message Signature: (in<float> x, in_out<float> y, int n, float alpha)
class axpy_actor : public event_based_actor {
public:
static caf::actor spawn(caf::actor_system& sys, int reply_id = 0) {
return sys.spawn<axpy_actor>(reply_id);
}

axpy_actor(caf::actor_config& cfg, int reply_id = 0)
: event_based_actor(cfg), reply_id_(reply_id) {
actor_id_ = static_cast<int>(this->id());
}

~axpy_actor() override {
command_runner<> runner;
runner.release_stream_for_actor(actor_id_);
}

caf::behavior make_behavior() override {
return {
// Standard host buffer based calls
[this](in<float> x, in_out<float> y, int n, float alpha) {
enqueue_axpy(-1, actor_id_, x, y, n, alpha, false);
},
// Routing control overloads
[this](int device_num, int stream_id, in<float> x, in_out<float> y, int n, float alpha) {
enqueue_axpy(device_num, stream_id, x, y, n, alpha, false);
},
// mem_ptr based calls (useful for pipelines)
[this](mem_ptr<float> x, mem_ptr<float> y, int n, float alpha) {
enqueue_axpy(-1, actor_id_, x, y, n, alpha, false);
},
[this](int device_num, int stream_id, mem_ptr<float> x, mem_ptr<float> y, int n, float alpha) {
enqueue_axpy(device_num, stream_id, x, y, n, alpha, false);
},
// Mem ptr return overloads
[this](return_mem_ptr_atom, in<float> x, in_out<float> y, int n, float alpha) {
enqueue_axpy(-1, actor_id_, x, y, n, alpha, true);
},
[this](return_mem_ptr_atom, int device_num, int stream_id, in<float> x, in_out<float> y, int n, float alpha) {
enqueue_axpy(device_num, stream_id, x, y, n, alpha, true);
},
[this](return_mem_ptr_atom, mem_ptr<float> x, mem_ptr<float> y, int n, float alpha) {
enqueue_axpy(-1, actor_id_, x, y, n, alpha, true);
}, [this](return_mem_ptr_atom,int device_num, int stream_id,mem_ptr<float> x, mem_ptr<float> y, int n, float alpha) {
enqueue_axpy(device_num, stream_id, x, y, n, alpha, true);
},
};
}

private:
// Overload for Host-wrapped buffers
void enqueue_axpy(int device_num, int stream_id,
in<float> x_arg, in_out<float> y_arg,
int n, float alpha, bool return_ptrs) {
command_runner<in<float>, in_out<float>> runner;

// Allocate/Transfer memory.
auto results = runner.transfer_memory(device_num, stream_id, x_arg, y_arg);
execute_and_reply(device_num, stream_id, std::get<0>(results),
std::get<1>(results), n, alpha, return_ptrs);
}

// Overload for already-existing Device buffers
void enqueue_axpy(int device_num, int stream_id,
mem_ptr<float> x_ptr, mem_ptr<float> y_ptr,
int n, float alpha, bool return_ptrs) {
// Pass through command_runner to ensure proper ref-counting/scheduling
command_runner<mem_ptr<float>, mem_ptr<float>> runner;
auto results = runner.transfer_memory(device_num, stream_id, x_ptr, y_ptr);
execute_and_reply(device_num, stream_id, std::get<0>(results),
std::get<1>(results), n, alpha, return_ptrs);
}

void execute_and_reply(int device_num, int stream_id,
mem_ptr<float> x, mem_ptr<float> y,
int n, float alpha, bool return_ptrs) {
auto plat = platform::create();
device_ptr dev;
if (device_num == -1)
dev = plat->schedule(stream_id);
else
dev = plat->schedule(stream_id, device_num);

// Perform cuBLAS operation
dev->saxpy(stream_id, n, alpha, x, y);

handle_reply(device_num, stream_id, x, y, return_ptrs);
}

void handle_reply(int, int, mem_ptr<float> x_ptr, mem_ptr<float> y_ptr, bool return_ptrs) {
command_runner<mem_ptr<float>> runner;
auto sender = actor_cast<actor>(this->current_sender());
if (!sender) return;

auto r_id = reply_id_;

if (return_ptrs) {
caf::anon_mail(r_id, x_ptr, y_ptr).send(sender);
} else {
runner.copy_to_host_async(y_ptr, [sender, r_id](std::vector<float>&& data) {
if (sender) {
caf::anon_mail(r_id, 1, std::move(data)).send(sender);
}
});
}
}

int actor_id_;
int reply_id_;
};

} // namespace caf::cuda
150 changes: 150 additions & 0 deletions libcaf_cuda/caf/actorBLAS/batched-gemm-actor/batched-gemm-actor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#pragma once

#include <caf/actor.hpp>
#include <caf/actor_cast.hpp>
#include <caf/actor_config.hpp>
#include <caf/actor_system.hpp>
#include <caf/anon_mail.hpp>
#include <caf/event_based_actor.hpp>

#include "caf/cuda/device.hpp"
#include "caf/cuda/mem_ref.hpp"
#include "caf/cuda/command_runner.hpp"
#include "caf/cuda/platform.hpp"
#include "caf/cuda/types.hpp"

namespace caf::cuda {

/// GEMM Batched Actor for performing matrix-matrix multiplication on batches of matrices.
/// Uses Strided Batched cuBLAS calls.
template <typename T>
class batched_gemm_actor : public event_based_actor {
public:
static caf::actor spawn(caf::actor_system& sys, int reply_id = 0) {
return sys.spawn<batched_gemm_actor<T>>(reply_id);
}

batched_gemm_actor(caf::actor_config& cfg, int reply_id = 0)
: event_based_actor(cfg), reply_id_(reply_id) {
actor_id_ = static_cast<int>(this->id());
}

~batched_gemm_actor() override {
command_runner<> runner;
runner.release_stream_for_actor(actor_id_);
}

caf::behavior make_behavior() override {
return {
// Standard host buffer based calls (alpha=1.0, beta=0.0)
[this](in<T> A, in<T> B, out<T> C, int m, int n, int k, int batchCount) {
enqueue_gemm_batched(-1, actor_id_, A, B, C, m, n, k, batchCount, static_cast<T>(1.0), static_cast<T>(0.0), false);
},
// mem_ptr based calls (Zero-copy Pipelines)
[this](mem_ptr<T> A, mem_ptr<T> B, mem_ptr<T> C, int m, int n, int k, int batchCount) {
enqueue_gemm_batched(-1, actor_id_, A, B, C, m, n, k, batchCount, static_cast<T>(1.0), static_cast<T>(0.0), false);
},
// Return mem_ptr atom overloads
[this](return_mem_ptr_atom, in<T> A, in<T> B, out<T> C, int m, int n, int k, int batchCount) {
enqueue_gemm_batched(-1, actor_id_, A, B, C, m, n, k, batchCount, static_cast<T>(1.0), static_cast<T>(0.0), true);
},
[this](return_mem_ptr_atom, mem_ptr<T> A, mem_ptr<T> B, mem_ptr<T> C, int m, int n, int k, int batchCount) {
enqueue_gemm_batched(-1, actor_id_, A, B, C, m, n, k, batchCount, static_cast<T>(1.0), static_cast<T>(0.0), true);
},
// Routing control (Explicit device/stream)
[this](int device_num, int stream_id, in<T> A, in<T> B, out<T> C, int m, int n, int k, int batchCount) {
enqueue_gemm_batched(device_num, stream_id, A, B, C, m, n, k, batchCount, static_cast<T>(1.0), static_cast<T>(0.0), false);
},
[this](int device_num, int stream_id, mem_ptr<T> A, mem_ptr<T> B, mem_ptr<T> C, int m, int n, int k, int batchCount) {
enqueue_gemm_batched(device_num, stream_id, A, B, C, m, n, k, batchCount, static_cast<T>(1.0), static_cast<T>(0.0), false);
},
[this](return_mem_ptr_atom, int device_num, int stream_id, in<T> A, in<T> B, out<T> C, int m, int n, int k, int batchCount) {
enqueue_gemm_batched(device_num, stream_id, A, B, C, m, n, k, batchCount, static_cast<T>(1.0), static_cast<T>(0.0), true);
},
[this](return_mem_ptr_atom, int device_num, int stream_id, mem_ptr<T> A, mem_ptr<T> B, mem_ptr<T> C, int m, int n, int k, int batchCount) {
enqueue_gemm_batched(device_num, stream_id, A, B, C, m, n, k, batchCount, static_cast<T>(1.0), static_cast<T>(0.0), true);
},
// Full Parameter GEMM (custom alpha/beta)
[this](in<T> A, in<T> B, out<T> C, int m, int n, int k, int batchCount, T alpha, T beta) {
enqueue_gemm_batched(-1, actor_id_, A, B, C, m, n, k, batchCount, alpha, beta, false);
},
[this](return_mem_ptr_atom, in<T> A, in<T> B, out<T> C, int m, int n, int k, int batchCount, T alpha, T beta) {
enqueue_gemm_batched(-1, actor_id_, A, B, C, m, n, k, batchCount, alpha, beta, true);
}
};
}

private:
// Logic for host-wrapped buffers
template <typename OutType>
void enqueue_gemm_batched(int device_num, int stream_id,
in<T> A_arg, in<T> B_arg, OutType C_arg,
int m, int n, int k, int batchCount, T alpha, T beta, bool return_ptrs) {
command_runner<in<T>, in<T>, OutType> runner;
auto results = runner.transfer_memory(device_num, stream_id, A_arg, B_arg, C_arg);
execute_and_reply(device_num, stream_id, std::get<0>(results),
std::get<1>(results), std::get<2>(results),
m, n, k, batchCount, alpha, beta, return_ptrs);
}

// Logic for existing Device buffers
void enqueue_gemm_batched(int device_num, int stream_id,
mem_ptr<T> A_ptr, mem_ptr<T> B_ptr, mem_ptr<T> C_ptr,
int m, int n, int k, int batchCount, T alpha, T beta, bool return_ptrs) {
command_runner<mem_ptr<T>, mem_ptr<T>, mem_ptr<T>> runner;
auto results = runner.transfer_memory(device_num, stream_id, A_ptr, B_ptr, C_ptr);
execute_and_reply(device_num, stream_id, std::get<0>(results),
std::get<1>(results), std::get<2>(results),
m, n, k, batchCount, alpha, beta, return_ptrs);
}

void execute_and_reply(int device_num, int stream_id,
mem_ptr<T> A, mem_ptr<T> B, mem_ptr<T> C,
int m, int n, int k, int batchCount, T alpha, T beta, bool return_ptrs) {
auto plat = platform::create();
device_ptr dev = (device_num == -1) ? plat->schedule(stream_id) : plat->schedule(stream_id, device_num);

// Default packed strides
long long int strideA = static_cast<long long int>(m) * k;
long long int strideB = static_cast<long long int>(k) * n;
long long int strideC = static_cast<long long int>(m) * n;

if constexpr (std::is_same_v<T, float>) {
dev->sgemm_strided_batched(stream_id, m, n, k, alpha, A, strideA, B, strideB, beta, C, strideC, batchCount);
} else if constexpr (std::is_same_v<T, double>) {
dev->dgemm_strided_batched(stream_id, m, n, k, alpha, A, strideA, B, strideB, beta, C, strideC, batchCount);
} else {
static_assert(std::is_same_v<T, float> || std::is_same_v<T, double>,
"Unsupported type for GEMM batched actor. Only float and double are supported.");
}

handle_reply(A, B, C, return_ptrs);
}

void handle_reply(mem_ptr<T> A_ptr, mem_ptr<T> B_ptr, mem_ptr<T> C_ptr, bool return_ptrs) {
command_runner<mem_ptr<T>> runner;
auto sender = actor_cast<actor>(this->current_sender());
if (!sender) return;

auto r_id = reply_id_;

if (return_ptrs) {
// Requirement: Always 1 message.
// We bundle all pointers into a single message.
caf::anon_mail(r_id, A_ptr, B_ptr, C_ptr).send(sender);
} else {
// Requirement: Always 1 message.
// We only copy back the result matrix (index 2) and send it.
runner.copy_to_host_async(C_ptr, [sender, r_id](std::vector<T>&& data) {
if (sender) {
caf::anon_mail(r_id, 2, std::move(data)).send(sender);
}
});
}
}

int actor_id_;
int reply_id_;
};

} // namespace caf::cuda
Loading
Loading