-
Notifications
You must be signed in to change notification settings - Fork 699
Moved OpenCL memory allocation to runtime. #1958
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef GLOW_BACKENDS_BACKENDUTILS_H | ||
#define GLOW_BACKENDS_BACKENDUTILS_H | ||
|
||
#include "glow/Backends/CompiledFunction.h" | ||
#include "glow/IR/IR.h" | ||
|
||
namespace glow { | ||
/// At compile time condense constants to a single block of memory. | ||
/// This allows the graph to go away after compile time. | ||
/// Allocates a block of memory of size \p constantMaxSize then walks the given | ||
/// function \p F and and copies weights to their address as specified by | ||
/// offsets contained in \p symbolTable. | ||
uint8_t *collectConstants( | ||
const IRFunction *F, uint64_t constantMaxSize, | ||
const std::unordered_map<std::string, runtime::RuntimeSymbolInfo> | ||
&symbolTable); | ||
/// Helper function to retrieve offset for Value: \p v from \p symbolTable. | ||
size_t | ||
getValueOffset(Value *v, | ||
const std::unordered_map<std::string, runtime::RuntimeSymbolInfo> | ||
&symbolTable); | ||
} // end namespace glow | ||
|
||
#endif // GLOW_BACKENDS_BACKENDUTILS_H |
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,53 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "glow/Backends/BackendUtils.h" | ||
#include "glow/IR/Instrs.h" | ||
|
||
using namespace glow; | ||
using llvm::cast; | ||
using llvm::isa; | ||
|
||
uint8_t *glow::collectConstants( | ||
const IRFunction *F, uint64_t constantMaxSize, | ||
const std::unordered_map<std::string, runtime::RuntimeSymbolInfo> | ||
&symbolTable) { | ||
|
||
// At compile time condense constants to a single block of memory. | ||
// This allows the graph to go away after compile time. | ||
uint8_t *baseConstantWeightVarsStore = | ||
(uint8_t *)alignedAlloc(constantMaxSize, TensorAlignment); | ||
for (auto &v : F->getGraph()->getParent()->getConstants()) { | ||
assert(isa<WeightVar>(F->getWeightForNode(v))); | ||
auto *w = cast<WeightVar>(F->getWeightForNode(v)); | ||
auto payload = v->getPayload().getUnsafePtr(); | ||
auto numBytes = w->getSizeInBytes(); | ||
auto it = symbolTable.find(std::string(w->getName())); | ||
assert(it != symbolTable.end() && "Symbol not found."); | ||
auto addr = it->second.offset; | ||
// Copy weight to offset. | ||
memcpy(baseConstantWeightVarsStore + addr, payload, numBytes); | ||
} | ||
return baseConstantWeightVarsStore; | ||
} | ||
|
||
/// Helper function, gets offset of \p v from \p symbolTable. | ||
size_t glow::getValueOffset( | ||
Value *v, const std::unordered_map<std::string, runtime::RuntimeSymbolInfo> | ||
&symbolTable) { | ||
auto it = symbolTable.find(std::string(v->getName())); | ||
assert(it != symbolTable.end() && "Symbol not found."); | ||
return it->second.offset; | ||
} |
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
Oops, something went wrong.
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.