Skip to content

Commit

Permalink
Adress requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonelm committed Apr 10, 2024
1 parent dd27051 commit 826026d
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 27 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ endif()

check_function_exists(clock_gettime CLOCK_GETTIME_FOUND)
if(NOT CLOCK_GETTIME_FOUND)
set(CMAKE_REQUIRED_LIBRARIES "rt")
check_function_exists(clock_gettime CLOCK_GETTIME_FOUND_WITH_RT)
unset(CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_LIBRARIES "rt")
check_function_exists(clock_gettime CLOCK_GETTIME_FOUND_WITH_RT)
unset(CMAKE_REQUIRED_LIBRARIES)
endif()

CHECK_STRUCT_HAS_BITFIELD("struct perf_event_attr" context_switch linux/perf_event.h HAVE_PERF_RECORD_SWITCH)
Expand Down
2 changes: 1 addition & 1 deletion include/lo2s/cupti/events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace cupti
{
enum class EventType : uint64_t
{
CUPTI_KERNEL = 0,
CUPTI_KERNEL = 1,
};

struct event_header
Expand Down
15 changes: 8 additions & 7 deletions include/lo2s/cupti/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class Reader
public:
Reader(trace::Trace& trace, Process process)
: process_(process), trace_(trace), time_converter_(perf::time::Converter::instance()),
ringbuf_reader_(std::to_string(process.as_pid_t()), true, config().nvidia_ringbuf_size),
timer_fd_(timerfd_from_ns(config().userspace_read_interval)), exe(get_process_exe(process))
ringbuf_reader_("cupti", process.as_pid_t(), true, config().nvidia_ringbuf_size),
timer_fd_(timerfd_from_ns(config().userspace_read_interval)),
executable_name_(get_process_exe(process))
{
}

Expand All @@ -69,11 +70,11 @@ class Reader
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);
auto& cu_cctx = trace_.cuda_calling_context(executable_name_, 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);
writer.write_calling_context_enter(time_converter_(kernel->start), cu_cctx.ref(),
2);
writer.write_calling_context_leave(time_converter_(kernel->end), cu_cctx.ref());
}

ringbuf_reader_.pop(header->size);
Expand All @@ -91,7 +92,7 @@ class Reader
perf::time::Converter& time_converter_;
RingBufReader ringbuf_reader_;
int timer_fd_;
std::string exe;
std::string executable_name_;
};
} // namespace cupti
} // namespace lo2s
4 changes: 2 additions & 2 deletions include/lo2s/pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Pipe
void fd_flags(std::size_t fd, int flags);
void close_fd(std::size_t fd);

int fds_[2];
bool fd_open_[2];
int fds_[2] = { 0, 0 };
bool fd_open_[2] = { false, false };
};
} // namespace lo2s
12 changes: 7 additions & 5 deletions include/lo2s/ringbuf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ class Mmap
class ShmRingbuf
{
public:
ShmRingbuf(std::string filename, bool create, size_t pages)
ShmRingbuf(std::string component, pid_t pid, bool create, size_t pages)
{
std::string filename = "/lo2s-" + component + "-" + std::to_string(pid);

fd_ = shm_open(filename.c_str(), create ? O_RDWR | O_CREAT | O_EXCL : O_RDWR, 0600);
if (fd_ == -1)
{
Expand Down Expand Up @@ -195,8 +197,8 @@ class ShmRingbuf
class RingBufWriter : public ShmRingbuf
{
public:
RingBufWriter(std::string filename, bool create, size_t pages = 0)
: ShmRingbuf(filename, create, pages)
RingBufWriter(std::string component, pid_t pid, bool create, size_t pages = 0)
: ShmRingbuf(component, pid, create, pages)
{
}

Expand Down Expand Up @@ -233,8 +235,8 @@ class RingBufWriter : public ShmRingbuf
class RingBufReader : public ShmRingbuf
{
public:
RingBufReader(std::string filename, bool create, size_t pages = 0)
: ShmRingbuf(filename, create, pages)
RingBufReader(std::string component, pid_t pid, bool create, size_t pages = 0)
: ShmRingbuf(component, pid, create, pages)
{
}
std::byte* get(size_t size)
Expand Down
11 changes: 6 additions & 5 deletions src/cupti/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ static void CUPTIAPI bufferCompleted(CUcontext ctx, uint32_t streamId, uint8_t*
case CUPTI_ACTIVITY_KIND_KERNEL:
case CUPTI_ACTIVITY_KIND_CONCURRENT_KERNEL:
{
CUpti_ActivityKernel6* kernel = static_cast<CUpti_ActivityKernel6*>(record);
CUpti_ActivityKernel6* kernel = reinterpret_cast<CUpti_ActivityKernel6*>(record);

uint64_t name_len = strlen(kernel->name);

struct lo2s::cupti::event_kernel* ev = static_cast<struct lo2s::cupti::event_kernel*>(
rb_writer->reserve(sizeof(struct lo2s::cupti::event_kernel) + name_len));
struct lo2s::cupti::event_kernel* ev =
reinterpret_cast<struct lo2s::cupti::event_kernel*>(
rb_writer->reserve(sizeof(struct lo2s::cupti::event_kernel) + name_len));

if (ev == nullptr)
{
Expand Down Expand Up @@ -127,7 +128,7 @@ void CUPTIAPI callbackHandler(void* userdata, CUpti_CallbackDomain domain, CUpti
{
if (cbInfo->callbackSite == CUPTI_API_EXIT)
{
cupttiActivityEnableContext(cbInfo->context, CUPTI_ACTIVITY_KIND_CONCURRENT_KERNEL);
cuptiActivityEnableContext(cbInfo->context, CUPTI_ACTIVITY_KIND_CONCURRENT_KERNEL);
}
}
else if (cbid == CUPTI_DRIVER_TRACE_CBID_cuProfilerStop)
Expand Down Expand Up @@ -168,7 +169,7 @@ extern "C" int InitializeInjection(void)
{

std::string rb_size_str;
rb_writer = std::make_unique<lo2s::RingBufWriter>(std::to_string(getpid()), false);
rb_writer = std::make_unique<lo2s::RingBufWriter>("cupti", getpid(), false);
char* clockid_str = getenv("LO2S_CLOCKID");

if (clockid_str != nullptr)
Expand Down
6 changes: 3 additions & 3 deletions src/monitor/process_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void ProcessMonitor::insert_thread(Process process, Thread thread, std::string n
{
try
{
auto inserted =
threads_.emplace(std::piecewise_construct, std::forward_as_tuple(thread),
std::forward_as_tuple(ExecutionScope(thread), *this, spawn, is_process));
auto inserted = threads_.emplace(
std::piecewise_construct, std::forward_as_tuple(thread),
std::forward_as_tuple(ExecutionScope(thread), *this, spawn, is_process));
assert(inserted.second);
// actually start thread
inserted.first->second.start();
Expand Down
2 changes: 1 addition & 1 deletion src/monitor/process_monitor_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ std::vector<char*> to_vector_of_c_str(std::vector<std::string> vec)
if (config().use_nvidia)
{
env = { "CUDA_INJECTION64_PATH=" + config().cuda_path };
Log::error() << config().cuda_path;

if (config().use_clockid)
{
env.push_back("LO2S_CLOCKID=" + std::to_string(config().clockid));
Expand Down

0 comments on commit 826026d

Please sign in to comment.