Commit 7e6199c6 authored by Brice Videau's avatar Brice Videau
Browse files

Fixed CUDA tracer to work on basic tests.

parent 3e18214b
......@@ -80,6 +80,7 @@ AC_CONFIG_FILES([opencl/babeltrace_opencl], [chmod +x opencl/babeltrace_opencl])
AC_CONFIG_FILES([ze/babeltrace_ze], [chmod +x ze/babeltrace_ze])
AC_CONFIG_FILES([ze/tracer_ze.sh], [chmod +x ze/tracer_ze.sh])
AC_CONFIG_FILES([ze/zeprof.sh], [chmod +x ze/zeprof.sh])
AC_CONFIG_FILES([cuda/babeltrace_cuda], [chmod +x cuda/babeltrace_cuda])
AC_CONFIG_FILES([cuda/tracer_cuda.sh], [chmod +x cuda/tracer_cuda.sh])
AC_CONFIG_FILES([xprof/iprof], [chmod +x xprof/iprof])
AC_OUTPUT
......@@ -11,6 +11,15 @@ CUDA_PROBES_INCL = \
CUDA_PROBES_SRC = \
cuda_tracepoints.c
CUDA_STATIC_PROBES_TP = \
cuda_args.tp
CUDA_STATIC_PROBES_INCL = \
cuda_args.h
CUDA_STATIC_PROBES_SRC = \
cuda_args.c
CUDART_PROBES_TP = \
cudart_tracepoints.tp
......@@ -24,6 +33,9 @@ CLEANFILES = \
$(CUDA_PROBES_TP) \
$(CUDA_PROBES_INCL) \
$(CUDA_PROBES_SRC) \
$(CUDA_STATIC_PROBES_TP) \
$(CUDA_STATIC_PROBES_INCL) \
$(CUDA_STATIC_PROBES_SRC) \
$(CUDART_PROBES_TP) \
$(CUDART_PROBES_INCL) \
$(CUDART_PROBES_SRC)
......@@ -131,17 +143,21 @@ cuda_tracepoints.tp: $(srcdir)/gen_cuda_tracepoints.rb $(CUDA_MODEL) gen_probe_b
cudart_tracepoints.tp: $(srcdir)/gen_cudart_tracepoints.rb $(CUDART_MODEL) gen_probe_base.rb
SRC_DIR=$(srcdir) $(RUBY) $(srcdir)/gen_cudart_tracepoints.rb > $@
cuda_args.tp: $(srcdir)/gen_cuda_custom_probes.rb $(CUDA_MODEL)
SRC_DIR=$(srcdir) $(RUBY) $(srcdir)/gen_cuda_custom_probes.rb lttng_ust_cuda_args > $@
%.h %.c: %.tp
$(LTTNG_GEN_TP) $< -o $*.c -o $*.h
EXTRA_DIST += \
gen_cuda_tracepoints.rb \
gen_cudart_tracepoints.rb \
gen_probe_base.rb
gen_probe_base.rb \
gen_cuda_custom_probes.rb
BUILT_SOURCES = $(CUDA_PROBES_INCL) $(CUDART_PROBES_INCL)
BUILT_SOURCES = $(CUDA_PROBES_INCL) $(CUDA_STATIC_PROBES_INCL) $(CUDART_PROBES_INCL)
tracer_cuda.c: $(srcdir)/gen_cuda.rb $(srcdir)/tracer_cuda_helpers.include.c $(CUDA_MODEL) $(CUDA_PROBES_INCL) cuda_export_tables.yaml
tracer_cuda.c: $(srcdir)/gen_cuda.rb $(srcdir)/tracer_cuda_helpers.include.c $(CUDA_MODEL) $(CUDA_PROBES_INCL) $(CUDA_STATIC_PROBES_INCL) cuda_export_tables.yaml
SRC_DIR=$(srcdir) $(RUBY) $< > $@
tracer_cudart.c: $(srcdir)/gen_cudart.rb $(srcdir)/tracer_cudart_helpers.include.c $(CUDART_MODEL) $(CUDART_PROBES_INCL)
......@@ -158,13 +174,15 @@ CLEANFILES += \
tracer_cuda.c \
tracer_cudart.c
bin_SCRIPTS = tracer_cuda.sh
bin_SCRIPTS = tracer_cuda.sh babeltrace_cuda
noinst_LTLIBRARIES = libcudatracepoints.la libcudarttracepoints.la
nodist_libcudatracepoints_la_SOURCES = \
$(CUDA_PROBES_INCL) \
$(CUDA_PROBES_SRC)
$(CUDA_PROBES_SRC) \
$(CUDA_STATIC_PROBES_INCL) \
$(CUDA_STATIC_PROBES_SRC)
libcudatracepoints_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS)
libcudatracepoints_la_LDFLAGS = $(LTTNG_UST_LIBS)
......
#!/usr/bin/env ruby
DATADIR = File.join("@prefix@", "share")
$:.unshift(DATADIR) if File::directory?(DATADIR)
$:.unshift("./")
require 'babeltrace'
require 'babeltrace/ctf'
require 'yaml'
require 'pp'
require 'babeltrace_cuda_lib'
c = Babeltrace::Context::new
traces = c.add_traces(path: ARGV[0])
puts "#{c.get_timestamp_begin.strftime("%Y-%m-%d %H:%M:%S.%9L %z")} -- #{c.get_timestamp_end.strftime("%Y-%m-%d %H:%M:%S.%9L %z")}"
events = {}
traces.each { |t|
events[t.handle_id] = t.get_event_decl_list.collect(&:name)
}
it = c.iter_create
it.each { |ev|
name = events[ev.handle_id][ev.id]
print "#{ev.timestamp.strftime("%H:%M:%S.%9L")} - #{name}: "
defi = ev.top_level_scope(:EVENT_FIELDS)
l = $event_lambdas[name]
if l
puts l.call(defi.value)
else
puts defi.value
end
}
---
{}
lttng_ust_cuda_args:
events:
- name: arg_count
args:
- [ CUfunction, f ]
- [ size_t, argCount ]
fields:
- [ ctf_integer_hex, uintptr_t, f, "(uintptr_t)f" ]
- [ ctf_integer, size_t, argCount, argCount ]
- name: arg_value
args:
- [ CUfunction, f ]
- [ "unsigned int", argIndex ]
- [ "void *", kernelParam ]
- [ size_t, argSize ]
fields:
- [ ctf_integer_hex, uintptr_t, f, "(uintptr_t)f" ]
- [ ctf_integer_hex, uintptr_t, kernelParam, "(uintptr_t)kernelParam" ]
- [ ctf_sequence_text, uint8_t, kernelParam_val, "(uint8_t *)kernelParam", size_t, "kernelParam ? argSize : 0" ]
......@@ -226,7 +226,7 @@ meta_parameters:
cuMipmappedArrayGetLevel:
- [OutScalar, pLevelArray]
cuPointerGetAttribute:
- [OutLTTng, data, ctf_sequence_text, uint8_t, data, data, size_t, "attribute == CU_POINTER_ATTRIBUTE_CONTEXT ? sizeof(CUcontext) : attribute == CU_POINTER_ATTRIBUTE_MEMORY_TYPE ? sizeof(unsigned int) : attribute == CU_POINTER_ATTRIBUTE_DEVICE_POINTER ? sizeof(CUdeviceptr) : attribute == CU_POINTER_ATTRIBUTE_HOST_POINTER ? sizeof(void *) : attribute == CU_POINTER_ATTRIBUTE_P2P_TOKENS ? sizeof(CUDA_POINTER_ATTRIBUTE_P2P_TOKENS) : attribute == CU_POINTER_ATTRIBUTE_SYNC_MEMOPS ? sizeof(uint8_t) : attribute == CU_POINTER_ATTRIBUTE_BUFFER_ID ? sizeof(unsigned long long) : attribute == CU_POINTER_ATTRIBUTE_IS_MANAGED ? sizeof(uint8_t) : attribute == CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL ? sizeof(int) : 0"]
- [OutLTTng, data, ctf_sequence_text, uint8_t, data_val, data, size_t, "attribute == CU_POINTER_ATTRIBUTE_CONTEXT ? sizeof(CUcontext) : attribute == CU_POINTER_ATTRIBUTE_MEMORY_TYPE ? sizeof(unsigned int) : attribute == CU_POINTER_ATTRIBUTE_DEVICE_POINTER ? sizeof(CUdeviceptr) : attribute == CU_POINTER_ATTRIBUTE_HOST_POINTER ? sizeof(void *) : attribute == CU_POINTER_ATTRIBUTE_P2P_TOKENS ? sizeof(CUDA_POINTER_ATTRIBUTE_P2P_TOKENS) : attribute == CU_POINTER_ATTRIBUTE_SYNC_MEMOPS ? sizeof(uint8_t) : attribute == CU_POINTER_ATTRIBUTE_BUFFER_ID ? sizeof(unsigned long long) : attribute == CU_POINTER_ATTRIBUTE_IS_MANAGED ? sizeof(uint8_t) : attribute == CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL ? sizeof(int) : 0"]
cuMemRangeGetAttribute:
- [OutArray, data, dataSize]
cuMemRangeGetAttributes:
......@@ -234,7 +234,7 @@ meta_parameters:
- [InArray, dataSizes, numAttributes]
- [OutArray, data, numAttributes]
cuPointerSetAttribute:
- [InLTTng, value, ctf_sequence_text, uint8_t, value, value, size_t, "attribute == CU_POINTER_ATTRIBUTE_SYNC_MEMOPS ? sizeof(uint8_t) : 0"]
- [InLTTng, value, ctf_sequence_text, uint8_t, value_val, value, size_t, "attribute == CU_POINTER_ATTRIBUTE_SYNC_MEMOPS ? sizeof(uint8_t) : 0"]
cuPointerGetAttributes:
- [InArray, attributes, numAttributes]
- [OutArray, data, numAttributes]
......
......@@ -50,7 +50,7 @@ all_types.select { |t| t.type.kind_of? YAMLCAst::Struct }.each { |t|
end
}
INIT_FUNCTIONS = /cuInit/
INIT_FUNCTIONS = /cuInit|cuDriverGetVersion/
FFI_TYPE_MAP = {
"unsigned char" => "ffi_type_uint8",
......
......@@ -56,7 +56,7 @@ EOF
fields = []
if dir == :start
if c.parameters
fields += (c.parameters+c.tracepoint_parameters).collect { |p|
fields += c.parameters.collect { |p|
case p.type
when YAMLCAst::Pointer
"s << \"#{p.name}: \#{\"0x%016x\" % defi[\"#{p.name}\"]}\""
......@@ -134,6 +134,21 @@ EOF
else
"s << \"#{field.name}: \#{defi[\"#{field.name}\"]}\""
end
when :ctf_sequence_text
arg = e["args"].find { |type, name|
name == field.expression
}
name = field.name
if arg
t = arg[0].sub("*","").strip
if $all_struct_names.include?(t)
"s << \"#{name}: \#{defi[\"#{name}\"].size > 0 ? CUDA::#{to_class_name(t)}.new(FFI::MemoryPointer.from_string(defi[\"#{name}\"])) : nil}\""
else
"s << \"#{name}: \#{defi[\"#{name}\"].inspect}\""
end
else
"s << \"#{name}: \#{defi[\"#{name}\"].inspect}\""
end
else
raise "Unsupported LTTng macro #{field.macro}!"
end
......
require_relative 'cuda_model'
namespace = ARGV[0]
raise "No namespace provided!" unless namespace
h = YAML::load_file(File.join(SRC_DIR,"cuda_events.yaml"))[namespace]
raise "Invalid namespace!" unless h
puts <<EOF
#include <cuda.h>
EOF
enums = h["enums"]
if enums
enums.each { |e|
LTTng.print_enum(namespace, e)
}
end
h["events"].each { |e|
LTTng.print_tracepoint(namespace, e)
}
......@@ -181,18 +181,18 @@ module CUDA
module UUID
def to_s
a = self[:bytes].to_a
a = self[:bytes].to_a.collect { |v| v < 0 ? 0x100 + v : v }
s = "{ id: "
s << "%02x" % a[3]
s << "%02x" % a[2]
s << "%02x" % a[1]
s << "%02x" % a[0]
s << "%02x" % a[1]
s << "%02x" % a[2]
s << "%02x" % a[3]
s << "-"
s << "%02x" % a[5]
s << "%02x" % a[4]
s << "%02x" % a[5]
s << "-"
s << "%02x" % a[7]
s << "%02x" % a[6]
s << "%02x" % a[7]
s << "-"
s << "%02x" % a[8]
s << "%02x" % a[9]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment