Skip to content

Commit

Permalink
Save changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonelm committed Mar 8, 2024
1 parent 1dd5225 commit 9750d3c
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 48 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include(CheckIncludeFiles)
include(CheckStructHasMember)
include(CheckFunctionExists)
include(FeatureSummary)
include(GNUInstallDirs)

SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")

Expand Down Expand Up @@ -199,6 +200,7 @@ if (CUDAToolkit_FOUND)
add_library(lo2s_injection SHARED src/cupti/lib.cpp)
target_link_libraries(lo2s_injection PUBLIC CUDA::cupti)
target_include_directories(lo2s_injection PRIVATE include)
install(TARGETS lo2s_injection LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif ()

# define lo2s target
Expand Down Expand Up @@ -313,7 +315,7 @@ else()
set(LO2S_VERSION_STRING ${lo2s_VERSION})
endif()
configure_file(include/lo2s/version.hpp.in include/lo2s/version.hpp @ONLY)

configure_file(include/lo2s/monitor/process_monitor_main.hpp.in include/lo2s/monitor/process_monitor_main.hpp @ONLY)

# check for version dependent features and generate a build config

Expand Down
24 changes: 0 additions & 24 deletions include/lo2s/cupti/lib.hpp

This file was deleted.

6 changes: 4 additions & 2 deletions include/lo2s/cupti/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@
#include <chrono>
#include <cstdlib>
#include <string>

extern "C"
{
#include <sys/timerfd.h>
#include <unistd.h>
}

namespace lo2s
{
namespace cupti
{

class Reader
{
public:
Expand Down Expand Up @@ -80,15 +83,14 @@ class Reader
struct cupti_event_kernel* kernel = (struct cupti_event_kernel*)kernel_rb.get();

auto& writer = trace_.cuda_writer(Thread(process_.as_thread()));

std::string kernel_name = kernel->name;
auto& cu_cctx = trace_.cuda_calling_context(exe, kernel_name);

writer << otf2::event::calling_context_enter(time_converter_(kernel->start), cu_cctx,
2);

writer << otf2::event::calling_context_leave(time_converter_(kernel->end), cu_cctx);

Log::error() << kernel->start << ":" << kernel->end << ":" << kernel->name;
ringbuf_reader_.pop(header->size);
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/lo2s/measurement_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct MeasurementScope
case MeasurementScopeType::SYSCALL:
return fmt::format("syscall events for {}", scope.name());
case lo2s::MeasurementScopeType::CUDA:
return fmt::format("cuda kernel events for", scope.name());
return fmt::format("cuda kernel events for {}", scope.name());
default:
throw new std::runtime_error("Unknown ExecutionScopeType!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace lo2s
{
namespace monitor
{
const std::string cuda_path = "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/liblo2s_injection.so";

void process_monitor_main(monitor::AbstractProcessMonitor& monitor);
}
} // namespace lo2s
1 change: 0 additions & 1 deletion include/lo2s/monitor/scope_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#pragma once

#include "lo2s/cupti/ringbuf.hpp"
#include <lo2s/monitor/fwd.hpp>
#include <lo2s/monitor/main_monitor.hpp>
#include <lo2s/monitor/poll_monitor.hpp>
Expand Down
16 changes: 5 additions & 11 deletions src/cupti/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extern "C"
#include <unistd.h>
}

std::mutex initializeInjectionMutex;
std::unique_ptr<RingBufWriter> rb_writer;
CUpti_SubscriberHandle subscriber = NULL;

Expand All @@ -53,7 +52,7 @@ static void CUPTIAPI bufferRequested(uint8_t** buffer, size_t* size, size_t* max

if (*buffer == NULL)
{
printf("Error: Out of memory.\n");
std::cerr << "Error: Out of memory.\n";
exit(-1);
}
}
Expand Down Expand Up @@ -95,7 +94,7 @@ static void CUPTIAPI bufferCompleted(CUcontext ctx, uint32_t streamId, uint8_t*
cuptiActivityGetNumDroppedRecords(ctx, streamId, &dropped);
if (dropped != 0)
{
printf("Dropped %u activity records.\n", (unsigned int)dropped);
std::cerr << "Dropped %u activity records.\n", (unsigned int)dropped;
}

free(buffer);
Expand Down Expand Up @@ -162,17 +161,12 @@ uint64_t timestampfunc()
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
uint64_t res = ts.tv_sec * 1000000 + ts.tv_nsec;
std::cerr << res << std::endl;
uint64_t res = ts.tv_sec * 1000000000 + ts.tv_nsec;
return res;
}

extern "C" int InitializeInjection(void)
{
std::cerr << "INJECTING!" << std::endl;
// TODO: multiprocessing and RingBufWriter
initializeInjectionMutex.lock();

std::string rb_size_str;
try
{
Expand All @@ -187,10 +181,11 @@ extern "C" int InitializeInjection(void)
}

atexit(&atExitHandler);
cuptiActivityRegisterTimestampCallback(timestampfunc);

cuptiSubscribe(&subscriber, (CUpti_CallbackFunc)callbackHandler, NULL);

cuptiActivityRegisterTimestampCallback(timestampfunc);

cuptiEnableCallback(1, subscriber, CUPTI_CB_DOMAIN_DRIVER_API,
CUPTI_DRIVER_TRACE_CBID_cuProfilerStart);
cuptiEnableCallback(1, subscriber, CUPTI_CB_DOMAIN_DRIVER_API,
Expand All @@ -200,6 +195,5 @@ extern "C" int InitializeInjection(void)
// Register buffer callbacks
cuptiActivityRegisterCallbacks(bufferRequested, bufferCompleted);

initializeInjectionMutex.unlock();
return 1;
}
3 changes: 1 addition & 2 deletions src/monitor/process_monitor_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ namespace monitor
auto current_path = std::filesystem::current_path();
Log::error() << current_path;

std::vector<std::string> env = { "CUDA_INJECTION64_PATH=" + current_path.string() +
"/liblo2s_injection.so",
std::vector<std::string> env = { "CUDA_INJECTION64_PATH=" + cuda_path,
"LO2S_RINGBUF_SIZE=1024" };

std::vector<char*> c_env;
Expand Down
6 changes: 0 additions & 6 deletions src/trace/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
* along with lo2s. If not, see <http://www.gnu.org/licenses/>.
*/

#include "lo2s/measurement_scope.hpp"
#include "lo2s/trace/reg_keys.hpp"
#include "otf2xx/chrono/duration.hpp"
#include "otf2xx/common.hpp"
#include "otf2xx/definition/calling_context.hpp"
#include "otf2xx/definition/pre_fwd.hpp"
#include <lo2s/trace/trace.hpp>

#include <lo2s/address.hpp>
Expand Down

0 comments on commit 9750d3c

Please sign in to comment.