source: icGREP/icgrep-devel/icgrep/kernels/callback.h

Last change on this file was 6214, checked in by cameron, 7 months ago

abort-on-null functionality for s2p

File size: 1.9 KB
Line 
1/*
2 *  Copyright (c) 2018 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6#ifndef CALLBACK_H
7#define CALLBACK_H
8
9/* This file defines the callback interface from Parabix kernels
10   to C++ routines for the purpose of sending signals.  */
11
12#include <stdint.h>
13
14namespace kernel {
15   
16/*  To implement a callback, the following steps are required.
17 
18    1.  A suitable handle_signal method is required.   The default
19        handle_signal method simply counts the number of signals
20        received and the value of the last signal received.
21        If different behaviour is needed, define a subclass of SignallingObject
22        with a suitable overridden handle_signal method.
23 
24    2.  Pass the address of your callback object as an input scalar
25        to the kernel.
26 
27    3.  Create a LLVM Call to the signal dispatcher.  Assume the address
28        of the call back object is stored in "handler_address".  The
29        following code is illustrative.
30        Value * handler = b->getScalarField("handler_address");
31        Function * const dispatcher = m->getFunction("signal_dispatcher");
32        b->CreateCall(dispatcher, {handler, theSignal});
33 
34    4.  Ensure that the address of the signal_dispatcher is available
35        to the JIT engine (should be automatic with LoadDynamicLibraryPermanently).
36        driver->LinkFunction(theKernel, "signal_dispatcher", &signal_dispatcher);
37 
38*/
39   
40enum {NULL_SIGNAL = 0};
41 
42class SignallingObject {
43public:
44    SignallingObject() : mSignalCount(0), mLastSignal(0) {}
45    virtual ~SignallingObject() {}
46    virtual void handle_signal(unsigned signal);
47    unsigned getSignalCount();
48    unsigned getLastSignal();
49private:
50    unsigned mSignalCount;
51    unsigned mLastSignal;
52};
53
54extern "C" void signal_dispatcher(intptr_t callback_object_addr, unsigned signal);
55
56}
57
58#endif
Note: See TracBrowser for help on using the repository browser.