source: icGREP/icgrep-devel/icgrep/kernels/streams_merge.cpp @ 6034

Last change on this file since 6034 was 5960, checked in by cameron, 18 months ago

StreamsIntersect? kernel

File size: 2.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
6#include "streams_merge.h"
7#include <kernels/kernel_builder.h>
8
9using namespace llvm;
10
11namespace kernel {
12
13StreamsMerge::StreamsMerge(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned streamsPerSet, unsigned inputSets)
14    : BlockOrientedKernel("streamsMerge" + std::to_string(streamsPerSet) + "_" + std::to_string(inputSets) , {}, {}, {}, {}, {})
15, mStreamsPerSet(streamsPerSet)
16, mInputSets(inputSets) {
17    for (unsigned i = 0; i < mInputSets; i++) {
18        mStreamSetInputs.push_back(Binding{iBuilder->getStreamSetTy(streamsPerSet, 1), "inputGroup" + std::to_string(i)});
19    }
20    mStreamSetOutputs.push_back(Binding{iBuilder->getStreamSetTy(streamsPerSet, 1), "output"});
21}
22
23void StreamsMerge::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> &iBuilder) {
24
25    std::vector<Value *> resultStreams;
26
27    for (unsigned j = 0; j < mStreamsPerSet; j++) {
28        resultStreams.push_back(iBuilder->loadInputStreamBlock("inputGroup" + std::to_string(0), iBuilder->getInt32(j)));
29    }
30
31    for (unsigned i = 1; i < mInputSets; i++) {
32        for (unsigned j = 0; j < mStreamsPerSet; j++) {
33            resultStreams[j] = iBuilder->CreateOr(resultStreams[j], iBuilder->loadInputStreamBlock("inputGroup" + std::to_string(i), iBuilder->getInt32(j)));
34        }
35    }
36    for (unsigned j = 0; j < mStreamsPerSet; j++) {
37        iBuilder->storeOutputStreamBlock("output", iBuilder->getInt32(j), resultStreams[j]);
38    }
39}
40
41StreamsIntersect::StreamsIntersect(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned streamsPerSet, unsigned inputSets)
42: BlockOrientedKernel("streamsIntersect" + std::to_string(streamsPerSet) + "_" + std::to_string(inputSets) , {}, {}, {}, {}, {})
43, mStreamsPerSet(streamsPerSet)
44, mInputSets(inputSets) {
45    for (unsigned i = 0; i < mInputSets; i++) {
46        mStreamSetInputs.push_back(Binding{iBuilder->getStreamSetTy(streamsPerSet, 1), "inputGroup" + std::to_string(i)});
47    }
48    mStreamSetOutputs.push_back(Binding{iBuilder->getStreamSetTy(streamsPerSet, 1), "output"});
49}
50
51void StreamsIntersect::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> &iBuilder) {
52   
53    std::vector<Value *> resultStreams;
54   
55    for (unsigned j = 0; j < mStreamsPerSet; j++) {
56        resultStreams.push_back(iBuilder->loadInputStreamBlock("inputGroup" + std::to_string(0), iBuilder->getInt32(j)));
57    }
58   
59    for (unsigned i = 1; i < mInputSets; i++) {
60        for (unsigned j = 0; j < mStreamsPerSet; j++) {
61            resultStreams[j] = iBuilder->CreateAnd(resultStreams[j], iBuilder->loadInputStreamBlock("inputGroup" + std::to_string(i), iBuilder->getInt32(j)));
62        }
63    }
64    for (unsigned j = 0; j < mStreamsPerSet; j++) {
65        iBuilder->storeOutputStreamBlock("output", iBuilder->getInt32(j), resultStreams[j]);
66    }
67}
68   
69
70}
Note: See TracBrowser for help on using the repository browser.