source: icGREP/icgrep-devel/icgrep/kernels/pdep_kernel.h @ 6184

Last change on this file since 6184 was 6184, checked in by nmedfort, 9 months ago

Initial version of PipelineKernel? + revised StreamSet? model.

File size: 3.9 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5#ifndef PDEP_KERNEL_H
6#define PDEP_KERNEL_H
7
8#include "kernel.h"
9#include <llvm/IR/Value.h>
10#include <string>
11#include <toolchain/driver.h>
12
13/*
14
15Conceptually, given an unbounded input stream set of k streams and a marker stream, this kernel uses the
16Parallel Bits Deposit (PDEP) instruction to copy the input items from the i-th input stream to the i-th
17output stream the positions indicated by the marker bits. All other output items are set to zero. E.g.,
18
19 SOURCE >  abcdefgh i0000000 00000000 00000000
20 MARKER >  ...1.1.1 .....11. ..1...1. ...1.1..
21 OUTPUT >  ...a.b.c .....de. ..f...g. ...h.i..
22
23The complicating factor of this Kernel is that it assumes the input streams are *swizzled*. I.e., it
24"divides" each block of the marker stream into k elements, M_1 ... M_k, and applies the PDEP operation
25using M_i to the each of the k elements in the i-th input (swizzled) stream.
26
27            CONCEPTUAL VIEW OF INPUT STREAM SET                    ACTUAL LAYOUT OF INPUT STREAM SET
28
29 STREAM 0  abcde...  fg......  hijklm..  nopqrst.     SWIZZLE 0  abcde...  uvwxy...  OPQRS...  89abc...
30 STREAM 1  uvwxy...  zA......  BCDEFG..  HIJKLMN.     SWIZZLE 1  fg......  zA......  TU......  de......
31 STREAM 2  OPQRS...  TU......  VWXYZ0..  1234567.     SWIZZLE 2  hijklm..  BCDEFG..  VWXYZ0..  fghijk..
32 STREAM 3  89abc...  de......  fghijk..  lmnopqr.     SWIZZLE 3  nopqrst.  HIJKLMN.  1234567.  lmnopqr.
33
34
35NOTE: this kernel does *NOT* unswizzle the output. This will eventually be the responsibility of the
36pipeline to ensure it is done when needed.
37
38*/
39
40namespace kernel {
41
42class PDEPkernel final : public MultiBlockKernel {
43public:
44    PDEPkernel(const std::unique_ptr<kernel::KernelBuilder> & b, const unsigned swizzleFactor = 4, std::string name = "PDEP");
45    bool isCachable() const override { return true; }
46    bool hasSignature() const override { return false; }
47private:
48    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & b, llvm::Value * const numOfStrides) final;
49private:
50    const unsigned mSwizzleFactor;
51};   
52
53class StreamExpandKernel final : public MultiBlockKernel {
54public:
55    StreamExpandKernel(const std::unique_ptr<kernel::KernelBuilder> & b
56                       , StreamSet * source, const unsigned base, StreamSet * mask
57                       , StreamSet * expanded
58                       , const unsigned FieldWidth = sizeof(size_t) * 8);
59    bool isCachable() const override { return true; }
60    bool hasSignature() const override { return false; }
61protected:
62    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfBlocks) override;
63private:
64    const unsigned mFieldWidth;
65    const unsigned mSelectedStreamBase;
66    const unsigned mSelectedStreamCount;
67};
68
69class FieldDepositKernel final : public MultiBlockKernel {
70public:
71    FieldDepositKernel(const std::unique_ptr<kernel::KernelBuilder> &, StreamSet * mask, StreamSet * input, StreamSet * output, const unsigned fieldWidth = 64);
72    bool isCachable() const override { return true; }
73    bool hasSignature() const override { return false; }
74protected:
75    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
76private:
77    const unsigned mFieldWidth;
78    const unsigned mStreamCount;
79};
80
81class PDEPFieldDepositKernel final : public MultiBlockKernel {
82public:
83    PDEPFieldDepositKernel(const std::unique_ptr<kernel::KernelBuilder> &, StreamSet * mask, StreamSet * expanded, StreamSet * outputs, const unsigned fieldWidth = 64);
84    bool isCachable() const override { return true; }
85    bool hasSignature() const override { return false; }
86protected:
87    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
88private:
89    const unsigned mPDEPWidth;
90    const unsigned mStreamCount;
91};
92
93}
94
95#endif
Note: See TracBrowser for help on using the repository browser.