-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add kp_functor_size: print parallel functor sizes #242
Open
cwpearson
wants to merge
7
commits into
kokkos:develop
Choose a base branch
from
cwpearson:profiling-functor-size
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ece668f
Add kp_functor_size: print parallel functor sizes
cwpearson 37ce052
Match Core profiling interface
cwpearson ff0d1c6
add functor-size tool to CMakeLists.txt
cwpearson 5a0be63
functor-size: add missing <vector> header
cwpearson 24a8d1f
functor-size: match signature in kp_core.hpp
cwpearson ecb8aa1
functor-size: change output format to csv, add KOKKOSP_FUNCTOR_SIZE_O…
cwpearson d88baa8
functor-sizes: formatting
cwpearson 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 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 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 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 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 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 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 @@ | ||
kp_add_library(kp_functor_size kp_functor_size.cpp) |
This file contains 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,14 @@ | ||
|
||
|
||
CXX=g++ | ||
CXXFLAGS=-shared -O3 -fPIC -std=c++17 | ||
|
||
MAKEFILE_PATH := $(subst Makefile,,$(abspath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
CXXFLAGS+=-I${MAKEFILE_PATH} -I${MAKEFILE_PATH}/../../common/makefile-only -I${MAKEFILE_PATH}../all | ||
|
||
kp_functor_size.so: ${MAKEFILE_PATH}kp_functor_size.cpp | ||
$(CXX) $(CXXFLAGS) -o $@ $< | ||
|
||
clean: | ||
rm *.so |
This file contains 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,160 @@ | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// Kokkos v. 4.0 | ||
// Copyright (2022) National Technology & Engineering | ||
// Solutions of Sandia, LLC (NTESS). | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, | ||
// the U.S. Government retains certain rights in this software. | ||
// | ||
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://kokkos.org/LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//@HEADER | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "kp_core.hpp" | ||
|
||
namespace KokkosTools { | ||
namespace FunctorSize { | ||
|
||
bool show_warnings = true; | ||
#define WARN(x) \ | ||
{ \ | ||
if (show_warnings) { \ | ||
std::cerr << "KokkosP: Functor Size: WARNING: " << x << std::endl; \ | ||
} \ | ||
} | ||
#define ERROR(x) \ | ||
{ std::cerr << "KokkosP: Functor Size: ERROR: " << x << std::endl; } | ||
|
||
std::unordered_map<uint64_t, uint64_t> anonCount; // [size] = count | ||
std::unordered_map<std::string, std::unordered_map<uint64_t, uint64_t>> | ||
nameCounts; // [name][size] = count | ||
std::vector<std::string> names; | ||
uint64_t uniqueID = 0; | ||
|
||
void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer, | ||
const uint32_t /*devInfoCount*/, | ||
Kokkos_Profiling_KokkosPDeviceInfo* /*deviceInfo*/) { | ||
std::cerr << "KokkosP: FunctorSize Library Initialized (sequence is " | ||
<< loadSeq << ", interface version: " << interfaceVer << std::endl; | ||
} | ||
|
||
void dump_csv(std::ostream& os, const std::string_view delim = ",") { | ||
os << "size" << delim << "count" << delim << "name" << std::endl; | ||
|
||
for (const auto& [name, counts] : nameCounts) { | ||
for (const auto& [size, count] : counts) { | ||
os << size << delim << count << delim << name << std::endl; | ||
} | ||
} | ||
for (const auto& [size, count] : anonCount) { | ||
os << size << delim << count << delim | ||
<< "KOKKOSP_FUNCTOR_SIZE_ANONYMOUS_FUNCTION" << std::endl; | ||
} | ||
} | ||
|
||
void kokkosp_finalize_library() { | ||
std::cout << std::endl | ||
<< "KokkosP: Finalization Functor Size profiling library." | ||
<< std::endl; | ||
|
||
const char* output_csv_path = | ||
std::getenv("KOKKOSP_FUNCTOR_SIZE_OUTPUT_CSV_PATH"); | ||
|
||
if (output_csv_path && std::string_view(output_csv_path) != "") { | ||
std::ofstream os(output_csv_path); | ||
if (os) { | ||
dump_csv(os); | ||
} else { | ||
ERROR(output_csv_path << " counldn't be opened"); | ||
} | ||
} | ||
dump_csv(std::cout, ","); | ||
} | ||
|
||
void begin_parallel(const char* name, uint64_t* kID) { | ||
*kID = uniqueID++; | ||
if (nullptr == name) { | ||
WARN("Ignording kernel ID " | ||
<< *kID << " with null name. Results may be incomplete"); | ||
return; | ||
} | ||
|
||
if (*kID < names.size()) { | ||
WARN("set new name \"" << name << "\" for previously-seen kernel ID " | ||
<< *kID); | ||
} else { | ||
names.resize((*kID) + 1); // may have skipped if name was null previously | ||
} | ||
names[*kID] = name; | ||
} | ||
|
||
void kokkosp_begin_parallel_for(const char* name, const uint32_t /*devID*/, | ||
uint64_t* kID) { | ||
begin_parallel(name, kID); | ||
} | ||
|
||
void kokkosp_begin_parallel_reduce(const char* name, const uint32_t /*devID*/, | ||
uint64_t* kID) { | ||
begin_parallel(name, kID); | ||
} | ||
|
||
void kokkosp_begin_parallel_scan(const char* name, const uint32_t /*devID*/, | ||
uint64_t* kID) { | ||
begin_parallel(name, kID); | ||
} | ||
|
||
void kokkosp_mark_kernel_static_info( | ||
const uint64_t kernelID, const Kokkos_Profiling_Kernel_Static_Info* info) { | ||
if (!info) { | ||
WARN("Kokkos provided null info"); | ||
return; | ||
} | ||
const uint64_t size = info->functor_size; | ||
|
||
if (kernelID < names.size()) { | ||
const std::string& name = names[kernelID]; | ||
if (0 == nameCounts.count(name)) { | ||
nameCounts[name] = {{size, 0}}; | ||
} | ||
std::unordered_map<uint64_t, uint64_t>& nameCount = nameCounts[name]; | ||
|
||
if (0 == nameCount.count(size)) { | ||
nameCount[size] = 0; | ||
} | ||
nameCount[size]++; | ||
} else { | ||
WARN("never-before seen kernel ID \"" << kernelID << "\"."); | ||
|
||
if (0 == anonCount.count(size)) { | ||
anonCount[size] = 0; | ||
} | ||
anonCount[size]++; | ||
} | ||
} | ||
|
||
} // namespace FunctorSize | ||
} // namespace KokkosTools | ||
|
||
extern "C" { | ||
|
||
namespace impl = KokkosTools::FunctorSize; | ||
|
||
EXPOSE_INIT(impl::kokkosp_init_library) | ||
EXPOSE_FINALIZE(impl::kokkosp_finalize_library) | ||
EXPOSE_BEGIN_PARALLEL_FOR(impl::kokkosp_begin_parallel_for) | ||
EXPOSE_BEGIN_PARALLEL_REDUCE(impl::kokkosp_begin_parallel_reduce) | ||
EXPOSE_BEGIN_PARALLEL_SCAN(impl::kokkosp_begin_parallel_scan) | ||
EXPOSE_MARK_KERNEL_STATIC_INFO(impl::kokkosp_mark_kernel_static_info) | ||
|
||
} // extern "C" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test so that:
To me, it's still a bit unclear at the moment...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See kokkos/kokkos#6844 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for the pointer.
Still, I think a test must be added in
Kokkos Tools
itself (even if the feature is considered experimental) 😉There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cwpearson I didn't say this in my review of your PR but yes @romintomasetti is right. We have recently been pushing for testing in other Kokkos Tools connectors. I think having a simple test using Google Test would be good. You can see the test from space time stack in Kokkos Tools
develop
branch by @romintomasetti. I can help you with this if you need.@romintomasetti I think @cwpearson has demonstrated the use cases reasonably well. The PR from @masterleinad, see the table of output that @cwpearson has put in.
Perhaps @cwpearson can check if he needs to update the
example
directory of Kokkos Tools, but I don't think he needs to. The Kokkos application programmer need not make any code changes to use this particular tools capability.