Skip to content

Commit

Permalink
Add include_list.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
HGuillemet committed Nov 3, 2023
1 parent 2dfcc32 commit 4fc9e28
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions pytorch/include_list.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/perl

# Must be run at from javacpp-presets/pytorch after cppbuild.sh has been run
# for linux-x86_64-gpu

# Generate the lists of includes to parse, in order, from the output
# of g++ -H
# Used to update src/main/resources/org/bytedeco/pytorch/presets/*

use strict;
use warnings;

my %incs;
my @inc_per_depth;

sub flush($) {
my $min_depth = shift;
for (my $d = @inc_per_depth - 1; $d >= $min_depth; $d--) {
if ($inc_per_depth[$d]) {
foreach my $i (@{$inc_per_depth[$d]}) {
print "#include \"$i\"\n";
$incs{$i} = 1;
}
undef $inc_per_depth[$d];
}
}
}

sub go {
my $path = join ' ', @_;

my @inc = `g++ -I torch/csrc/api/include/ -I. -H $path -E 2>&1 > /dev/null`;
foreach my $i (@inc) {
chomp $i;
my ($depth, $f) = $i =~ /^(\.+)\s(.*\.h)$/;
next unless $depth;
$depth = length($depth);
$f =~ s#^\./##;
next if $f =~ m#^/
|^ATen/ops/\w+_native\.h$
|^ATen/ops/\w+_meta\.h$
|^ATen/ops/\w+_ops\.h$
|^ATen/ops/_\w+\.h$#x
or $incs{$f};
flush($depth);
my $incs = $inc_per_depth[$depth];
$incs = $inc_per_depth[$depth] = [] unless $incs;
push @$incs, $f;
}
flush(0);
}

chdir "cppbuild/linux-x86_64-gpu/pytorch/torch/include";

go('torch/csrc/api/include/torch/torch.h', 'torch/script.h');

print <<EOF;
// Included by
// ATen/cudnn/Descriptors.h
// ATen/cudnn/Types.h
// c10/cuda/CUDAGuard.h
EOF

go('ATen/cudnn/Descriptors.h', 'ATen/cudnn/Types.h', 'c10/cuda/CUDAGuard.h', '-I/opt/cuda/targets/x86_64-linux/include/');

0 comments on commit 4fc9e28

Please sign in to comment.