-
Notifications
You must be signed in to change notification settings - Fork 27
[Do-not-merge] PIM API fusion initial support #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
281ee9f
PIM API fusion code skeleton.
deyuan 91ba4f6
Add test-api-fusion test case.
deyuan 8895b3b
Merge branch 'main' of https://github.com/UVA-LavaLab/PIMeval-PIMbenc…
deyuan b8eab02
Merge branch 'main' of https://github.com/UVA-LavaLab/PIMeval-PIMbenc…
deyuan 724c40e
Create a new source file for pimCmdFuse.
deyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // File: pimCmdFuse.cpp | ||
| // PIMeval Simulator - PIM API Fusion | ||
| // Copyright (c) 2024 University of Virginia | ||
| // This file is licensed under the MIT License. | ||
| // See the LICENSE file in the root of this repository for more details. | ||
|
|
||
| #include "pimCmdFuse.h" | ||
| #include <cstdio> | ||
|
|
||
|
|
||
| //! @brief Pim CMD: PIM API Fusion | ||
| bool | ||
| pimCmdFuse::execute() | ||
| { | ||
| if (m_debugCmds) { | ||
| std::printf("PIM-Cmd: API Fusion\n"); | ||
| } | ||
|
|
||
| // Functional simulation | ||
| // TODO: skip original updateStats | ||
| bool success = true; | ||
| for (auto& api : m_prog.m_apis) { | ||
| PimStatus status = api(); | ||
| if (status != PIM_OK) { | ||
| success = false; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Analyze API fusion opportunities | ||
| success = success && updateStats(); | ||
| return success; | ||
| } | ||
|
|
||
| //! @brief Pim CMD: PIM API Fusion - update stats | ||
| bool | ||
| pimCmdFuse::updateStats() const | ||
| { | ||
| // TODO: Parse m_prog and update stats | ||
| return true; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // File: pimCmdFuse.h | ||
| // PIMeval Simulator - PIM API Fusion | ||
| // Copyright (c) 2024 University of Virginia | ||
| // This file is licensed under the MIT License. | ||
| // See the LICENSE file in the root of this repository for more details. | ||
|
|
||
| #ifndef LAVA_PIM_CMD_FUSE_H | ||
| #define LAVA_PIM_CMD_FUSE_H | ||
|
|
||
| #include "libpimeval.h" | ||
| #include "pimCmd.h" | ||
|
|
||
|
|
||
| //! @class pimCmdFuse | ||
| //! @brief Pim CMD: PIM API Fusion | ||
| class pimCmdFuse : public pimCmd | ||
| { | ||
| public: | ||
| pimCmdFuse(PimProg prog) : pimCmd(PimCmdEnum::NOOP), m_prog(prog) {} | ||
| virtual ~pimCmdFuse() {} | ||
| virtual bool execute() override; | ||
| virtual bool updateStats() const override; | ||
| private: | ||
| PimProg m_prog; | ||
| }; | ||
|
|
||
| #endif | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Makefile: Test PIM API Fusion | ||
| # Copyright (c) 2024 University of Virginia | ||
| # This file is licensed under the MIT License. | ||
| # See the LICENSE file in the root of this repository for more details. | ||
|
|
||
| PROJ_ROOT = ../.. | ||
| include ${PROJ_ROOT}/Makefile.common | ||
|
|
||
| EXEC := test-api-fusion.out | ||
| SRC := test-api-fusion.cpp | ||
|
|
||
| debug perf dramsim3_integ: $(EXEC) | ||
|
|
||
| $(EXEC): $(SRC) $(DEPS) | ||
| $(CXX) $< $(CXXFLAGS) -o $@ | ||
|
|
||
| clean: | ||
| rm -rf $(EXEC) *.dSYM | ||
|
|
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another test case should be overwriting the PIMobject data and pushing it to pim prog and pim prog should not fuse those. Just a sanity check! :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Test: Test PIM API Fusion | ||
| // Copyright (c) 2024 University of Virginia | ||
| // This file is licensed under the MIT License. | ||
| // See the LICENSE file in the root of this repository for more details. | ||
|
|
||
| #include "libpimeval.h" | ||
| #include <iostream> | ||
| #include <vector> | ||
| #include <algorithm> | ||
| #include <bitset> | ||
| #include <cassert> | ||
| #include <cstdlib> | ||
| #include <cstdio> | ||
|
|
||
|
|
||
| bool testFused(PimDeviceEnum deviceType) | ||
| { | ||
| // 1GB capacity | ||
| unsigned numRanks = 1; | ||
| unsigned numBankPerRank = 1; | ||
| unsigned numSubarrayPerBank = 8; | ||
| unsigned numRows = 1024; | ||
| unsigned numCols = 8192; | ||
|
|
||
| uint64_t numElements = 16 * 1024; | ||
|
|
||
| std::vector<int> src1(numElements); | ||
| std::vector<int> src2(numElements); | ||
| std::vector<int> dest1(numElements); | ||
| std::vector<int> dest2(numElements); | ||
| const int scalarVal = -123; | ||
|
|
||
| for (uint64_t i = 0; i < numElements; ++i) { | ||
| src1[i] = static_cast<int>(i); | ||
| src2[i] = static_cast<int>(i + 1); | ||
| } | ||
|
|
||
| PimStatus status = pimCreateDevice(deviceType, numRanks, numBankPerRank, numSubarrayPerBank, numRows, numCols); | ||
| assert(status == PIM_OK); | ||
|
|
||
| PimObjId objSrc1 = pimAlloc(PIM_ALLOC_AUTO, numElements, PIM_INT32); | ||
| PimObjId objSrc2 = pimAllocAssociated(objSrc1, PIM_INT32); | ||
| PimObjId objDest1 = pimAllocAssociated(objSrc1, PIM_INT32); | ||
| PimObjId objDest2 = pimAllocAssociated(objSrc1, PIM_INT32); | ||
| assert(objSrc1 != -1 && objSrc2 != -1 && objDest1 != -1 && objDest2 != -1); | ||
|
|
||
| // copy host to device | ||
| status = pimCopyHostToDevice((void*)src1.data(), objSrc1); | ||
| assert(status == PIM_OK); | ||
| status = pimCopyHostToDevice((void*)src2.data(), objSrc2); | ||
| assert(status == PIM_OK); | ||
|
|
||
|
|
||
| // Fused PIM APIs | ||
| PimProg prog; | ||
| prog.add(pimMulScalar, objSrc1, objDest1, static_cast<uint64_t>(scalarVal)); | ||
| prog.add(pimAdd, objDest1, objSrc2, objDest1); | ||
| status = pimFuse(prog); | ||
| assert(status == PIM_OK); | ||
|
|
||
| // Direct APIs | ||
| status = pimScaledAdd(objSrc1, objSrc2, objDest2, static_cast<uint64_t>(scalarVal)); | ||
| assert(status == PIM_OK); | ||
|
|
||
|
|
||
| status = pimCopyDeviceToHost(objDest1, (void*)dest1.data()); | ||
| assert(status == PIM_OK); | ||
| status = pimCopyDeviceToHost(objDest2, (void*)dest2.data()); | ||
| assert(status == PIM_OK); | ||
|
|
||
| bool ok = true; | ||
| for (uint64_t i = 0; i < numElements; ++i) { | ||
| if (dest1[i] != (src1[i] * scalarVal + src2[i]) || dest1[i] != dest2[i]) { | ||
| ok = false; | ||
| std::printf("Fused Test Error: src1 %d src2 %d dest1 %d dest2 %d\n", src1[i], src2[i], dest1[i], dest2[i]); | ||
| } | ||
| } | ||
|
|
||
| pimFree(objSrc1); | ||
| pimFree(objSrc2); | ||
| pimFree(objDest1); | ||
| pimFree(objDest2); | ||
|
|
||
| pimShowStats(); | ||
| pimResetStats(); | ||
| pimDeleteDevice(); | ||
|
|
||
| std::cout << "Fused Test " << (ok ? "PASSED" : "FAILED") << std::endl; | ||
| return ok; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| std::cout << "PIM Regression Test: PIM fused operations" << std::endl; | ||
|
|
||
| bool ok = true; | ||
| ok &= testFused(PIM_DEVICE_BITSIMD_V); | ||
| ok &= testFused(PIM_DEVICE_FULCRUM); | ||
| ok &= testFused(PIM_DEVICE_BANK_LEVEL); | ||
|
|
||
| std::cout << (ok ? "PASSED" : "FAILED") << std::endl; | ||
| return 0; | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.