Skip to content

Instantly share code, notes, and snippets.

View ArchRobison's full-sized avatar

Arch D. Robison ArchRobison

  • Nvidia
  • Champaign, IL
View GitHub Profile
@ArchRobison
ArchRobison / input.jl
Created May 26, 2015 22:13
Example input and output from Julia using LLVM 3.6.1 and JULIA_LLVM_ARGS=-debug-only=loop-vectorize
function mysum!{T}(F, A::AbstractArray{T})
for j = 1:size(A,2)
@simd for i = 1:size(A,1)
@inbounds F[i,j] += A[i,j]
end
end
return F
end
@ArchRobison
ArchRobison / gist:9310cb019b4974219bf7
Created April 13, 2015 14:47
Build of adr/threading branch using kf/tlsrebase5 version of LLVM
make[1]: Leaving directory `/localdisk/adrobiso/tmp/julia/ui'
make[1]: Entering directory `/localdisk/adrobiso/tmp/julia/base'
clang -m64 -E -dM ../usr/include/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?(0x[0-9a-fA-F]+|[-+]?\s*[0-9]+)\)?\s*$/ and print "const $1 = Int32($2)"' | sort > pcre_h.jl
echo '#include "errno.h"' | clang -m64 -E -dM - | perl -nle 'print "const $1 = Int32($2)" if /^#define\s+(E\w+)\s+(\d+)\s*$/' | sort > errno_h.jl
clang -m64 -E -P -DJULIA ../src/file_constants.h | perl -nle 'print "$1 0o$2" if /^(\s*const\s+[A-z_]+\s+=)\s+(0[0-9]*)\s*$/; print "$1" if /^\s*(const\s+[A-z_]+\s+=\s+([1-9]|0x)[0-9A-z]*)\s*$/' > file_constants.jl
clang -m64 -E -P "-I../deps/libuv/include" -DJULIA ../src/uv_constants.h | tail -n 16 > uv_constants.jl
make[1]: Leaving directory `/localdisk/adrobiso/tmp/julia/base'
@ArchRobison
ArchRobison / gist:e695fcb9d6361914b1e7
Created April 9, 2015 16:30
Sample failure of build of adr/threading branch of Julia
$ make
JULIA usr/lib/julia/sys0.o
exports.jl
base.jl
reflection.jl
build_h.jl
version_git.jl
c.jl
options.jl
promotion.jl
*** IR Dump After Combine redundant instructions ***
; Function Attrs: sspreq
define %jl_value_t* @julia_unoptimized_42298(%jl_value_t*, %jl_value_t**, i32) #0 {
top:
%3 = load %jl_value_t** %1, align 8, !dbg !15
%4 = getelementptr %jl_value_t** %1, i64 1, !dbg !15
%5 = load %jl_value_t** %4, align 8, !dbg !15
%6 = getelementptr inbounds %jl_value_t* %5, i64 4, i32 0, !dbg !16
%7 = load %jl_value_t** %6, align 8, !dbg !16, !tbaa %jtbaa_arraysize
%8 = ptrtoint %jl_value_t* %7 to i64, !dbg !16
$ clang -v
clang version 3.7.0 (trunk 227196)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
$ cat truncloop.jl
# use floating point AND instructions (andps/andpd)
# https://github.com/JuliaLang/julia/issues/9868
function and_float(x::Float64,y::Float64)
Base.llvmcall("""%av = insertelement<2 x double> undef, double %0, i32 0
%bv = insertelement<2 x double> undef, double %1, i32 0
%ai = bitcast <2 x double> %av to <2 x i64>
%bi = bitcast <2 x double> %bv to <2 x i64>
%and.i = and <2 x i64> %ai, %bi
%cf = bitcast <2 x i64> %and.i to <2 x double>
@ArchRobison
ArchRobison / gist:a340bc43c8fabb02e739
Created January 20, 2015 22:30
LLVM not doing loop-local scalar replacment
julia> ind4=CartesianIndex((1,1,1,1))
Base.IteratorsMD.CartesianIndex_4(1,1,1,1)
julia> @code_llvm(mymul(ind4,N,1))
define %CartesianIndex_4 @julia_mymul_43376(%CartesianIndex_4, i64, i64) {
top:
%3 = icmp slt i64 %1, 2, !dbg !8
br i1 %3, label %L3, label %L.preheader, !dbg !8
@ArchRobison
ArchRobison / gist:1442861e2e062ff10309
Created January 19, 2015 15:19
Demo of vectorizing sqrt using LLVM 3.5.0
julia> function f(x,y,z)
@fastmath @inbounds @simd for i=1:length(z)
z[i] = sqrt(x[i]^2+y[i]^2)
end
end
f (generic function with 1 method)
julia> code_native(f,(Vector{Float32},Vector{Float32},Vector{Float32}))
.text
Filename: none
$ cat toivoh.jl
module TestSLP
function rmw!{T}(dest::Ptr{T}, src::Ptr{T})
s1 = unsafe_load(src, 1)
s2 = unsafe_load(src, 2)
d1 = unsafe_load(dest, 1)
d2 = unsafe_load(dest, 2)
d1 $= s1
d2 $= s2
@ArchRobison
ArchRobison / gist:34a021a5d668026e35b3
Created October 17, 2014 21:35
Running MPI.jl examples
$ for f in *.jl; do echo $f; mpiexec -np 4 julia $f; done
01-hello.jl
Hello world, I am 1 of 4Hello world, I am 3 of 4Hello world, I am 2 of 4Hello world, I am 0 of 4
02-broadcast.jl
------------------------------------------------------------------------------
Running on 4 processes
------------------------------------------------------------------------------