Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name = "Legate"
uuid = "1238f2cf-6593-4d60-9aca-2f5364e49909"
version = "0.1.2"

[workspace]
projects = ["test", "docs", "dev", "lib/LegatePreferences"]

[deps]
CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
Expand Down
146 changes: 1 addition & 145 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,135 +20,7 @@ using Preferences
using LegatePreferences

include("version.jl")

# Automatically pipes errors to new file
# and appends stdout to build.log
function run_sh(cmd::Cmd, filename::String)
println(cmd)

build_log = joinpath(@__DIR__, "build.log")
tmp_build_log = joinpath(@__DIR__, "$(filename).log")
err_log = joinpath(@__DIR__, "$(filename).err")

if isfile(err_log)
rm(err_log)
end

if isfile(tmp_build_log)
rm(tmp_build_log)
end

try
run(pipeline(cmd; stdout=tmp_build_log, stderr=err_log, append=false))
contents = read(tmp_build_log, String)
open(build_log, "a") do io
println(contents)
end
catch e
println("stderr log generated: ", err_log, '\n')
contents = read(err_log, String)
if !isempty(strip(contents))
println("---- Begin stderr log ----")
println(contents)
println("---- End stderr log ----")
end
end
end

# patch legion. The readme below talks about our compilation error
# https://github.com/ejmeitz/cuNumeric.jl/blob/main/scripts/README.md
function patch_legion(repo_root::String, legate_root::String)
if !check_if_patch(legate_root)
legion_patch = joinpath(repo_root, "scripts/patch_legion.sh")
@info "Legate.jl: Running legion patch script: $legion_patch"
run_sh(`bash $legion_patch $repo_root $legate_root`, "legion_patch")
end
end

function build_jlcxxwrap(repo_root, legate_root)
build_libcxxwrap = joinpath(repo_root, "scripts/install_cxxwrap.sh")
version_path = joinpath(DEPOT_PATH[1], "dev/libcxxwrap_julia_jll/override/LEGATE_INSTALL.txt")
if isfile(version_path)
version = VersionNumber(strip(read(version_path, String)))
@info "libcxxwrap: Found Legate $version"
if is_supported_version(version)
@info "libcxxwrap: Found supported version built with Legate.jl: $version"
return nothing
else
@info "libcxxwrap: Unsupported version found: $version. Rebuilding..."
end
else
@info "libcxxwrap: No version file found. Starting build..."
end

@info "libcxxwrap: Running build script: $build_libcxxwrap"
run_sh(`bash $build_libcxxwrap $repo_root`, "libcxxwrap")
open(version_path, "w") do io
write(io, string(get_legate_version(legate_root)))
end
end

function build_cpp_wrapper(repo_root, legate_root, install_root)
@info "liblegatewrapper: Building C++ Wrapper Library"
if isdir(install_root)
rm(install_root; recursive=true)
mkdir(install_root)
end

build_cpp_wrapper = joinpath(repo_root, "scripts/build_cpp_wrapper.sh")
nthreads = Threads.nthreads()

bld_command = `$build_cpp_wrapper $repo_root $legate_root $install_root $nthreads`

# write out a bash script for debugging
cmd_str = join(bld_command.exec, " ")
wrapper_path = joinpath(repo_root, "build_wrapper.sh")
open(wrapper_path, "w") do io
println(io, "#!/bin/bash")
println(io, "set -xe")
println(io, cmd_str)
end
chmod(wrapper_path, 0o755)

@info "Running build command: $bld_command"
run_sh(`bash $bld_command`, "cpp_wrapper")
end

function _find_jll_artifact_dir(jll)
eval(:(using $(jll)))
jll_mod = getfield(Main, jll)
root = jll_mod.artifact_dir
return root
end

function _start_build()
pkg_root = up_dir(@__DIR__)
deps_dir = joinpath(@__DIR__)

build_log = joinpath(deps_dir, "build.log")
open(build_log, "w") do io
println(io, "=== Build started ===")
end

@info "Legate.jl: Parsed Package Dir as: $(pkg_root)"
return pkg_root
end

"""
build CxxWrap and legate_jl_wrapper
"""
function build_deps(pkg_root, legate_root)
install_dir = joinpath(pkg_root, "lib", "legate_jl_wrapper", "build")
if !legate_valid(legate_root)
error(
"Legate.jl: Unsupported Legate version at $(legate_root). " *
"Installed version: $(installed_version) not in range supported: " *
"$(MIN_LEGATE_VERSION)-$(MAX_LEGATE_VERSION).",
)
end
build_jlcxxwrap(pkg_root, legate_root) # $pkg_root/lib/libcxxwrap-julia
build_cpp_wrapper(pkg_root, legate_root, install_dir) # $pkg_root/lib/legate_jl_wrapper
end
include("build_util.jl")

function build(::LegatePreferences.JLL)
@warn "No reason to Build on JLL mode. Exiting Build"
Expand All @@ -169,21 +41,5 @@ function build(::LegatePreferences.Conda)
build_deps(pkg_root, legate_root)
end

function build(::LegatePreferences.Developer)
pkg_root = _start_build()

# can be nothing so this errors if not set
legate_root = load_preference(LegatePreferences, "legate_path", nothing)
if isnothing(legate_root)
# we are using legate_jll for legate
legate_root = _find_jll_artifact_dir(:legate_jll)
else
# this means we have a custom path set
is_legate_installed(legate_root; throw_errors=true)
patch_legion(pkg_root, legate_root)
end
build_deps(pkg_root, legate_root)
end

const mode_str = load_preference(LegatePreferences, "legate_mode", LegatePreferences.MODE_JLL)
build(LegatePreferences.to_mode(mode_str))
25 changes: 25 additions & 0 deletions dev/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name = "LegateDev"
uuid = "cc362a5e-39f6-414f-9052-7e8059a70023"
authors = ["""David Krasowska <krasow@u.northwestern.edu\n> and Ethan Meitz <emeitz@andrew.cmu.edu\n>"""]
version = "0.1.0"

[deps]
CUDA_SDK_jll = "6cbf2f2e-7e60-5632-ac76-dca2274e0be0"
Legate = "1238f2cf-6593-4d60-9aca-2f5364e49909"
LegatePreferences = "8028f36a-2b64-49e9-aa04-2d0933fd2ed9"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[sources]
Legate = {path = ".."}

[compat]
CUDA_SDK_jll = "13.0"
LegatePreferences = "0.1.6"
Libdl = "1.11.0"
Preferences = "1.5.2"
Reexport = "1.2.2"

[extras]
LegatePreferences = "8028f36a-2b64-49e9-aa04-2d0933fd2ed9"
1 change: 1 addition & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This contains a wrapper around Legate that facilitates re-building and testing the C++ wrappers. This package installed the CUDA SDK which is needed when rebuilding the wrapper. This must be the same CUDA SDK as when we build legate_jll so we install the JLL. By default CMake will just look on the system path. This avoids bugs caused by that.
8 changes: 8 additions & 0 deletions dev/src/LegateDev.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module LegateDev

using CUDA_SDK_jll
using Reexport

@reexport using Legate

end
78 changes: 39 additions & 39 deletions lib/LegatePreferences/src/PreferenceBackend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ macro make_preferences(prefix, default_mode="jll",
esc(quote
abstract type Mode end
struct JLL <: Mode end # default
struct Developer <: Mode end # will compile wrappers from src
# struct Developer <: Mode end # will compile wrappers from src
struct Conda <: Mode end # not well tested, allows conda env install

function to_mode(m::String)
m_lower = lowercase(m)
if m_lower == "jll"
return JLL()
elseif m_lower == "developer"
return Developer()
# elseif m_lower == "developer"
# return Developer()
elseif m_lower == "conda"
return Conda()
else
Expand Down Expand Up @@ -121,42 +121,42 @@ esc(quote
end
end

"""
LegatePreferences.use_developer_mode(; use_jll=true, path=nothing, export_prefs = false, force = true)

Tells Legate.jl | cuNumeric.jl to enable developer mode. Developer mode allows you to build from source.

To disable using legate_jll or cupynumeric_jll: ```use_jll=false```
If you disable legate_jll or cupynumeric_jll, then you need to set a path to Legate|cuPyNumeric with ```path="/path/to/Legate|cuPyNumeric"```
"""
function use_developer_mode(;use_jll=$default_use_jll,
path=$default_path,
export_prefs=false, force=true)

if !use_jll && isnothing(path)
error("Must provide path when not using JLL")
end

same_mode = MODE == MODE_DEVELOPER
same_jll_usage = use_jll == _use_jll
same_path = path == _path

if same_mode && same_jll_usage && same_path
@info "Already using Developer mode with the same settings"
return
end

_PREFS_CHANGED[] = true
_set("mode" => MODE_DEVELOPER,
"use_jll" => use_jll,
"path" => path;
export_prefs, force)

@info "Developer mode enabled"
if _DEPS_LOADED[]
error("Developer Mode: Restart Julia for changes to take effect. You will need to run Pkg.build().")
end
end
# """
# LegatePreferences.use_developer_mode(; use_jll=true, path=nothing, export_prefs = false, force = true)

# Tells Legate.jl | cuNumeric.jl to enable developer mode. Developer mode allows you to build from source.

# To disable using legate_jll or cupynumeric_jll: ```use_jll=false```
# If you disable legate_jll or cupynumeric_jll, then you need to set a path to Legate|cuPyNumeric with ```path="/path/to/Legate|cuPyNumeric"```
# """
# function use_developer_mode(;use_jll=$default_use_jll,
# path=$default_path,
# export_prefs=false, force=true)

# if !use_jll && isnothing(path)
# error("Must provide path when not using JLL")
# end

# same_mode = MODE == MODE_DEVELOPER
# same_jll_usage = use_jll == _use_jll
# same_path = path == _path

# if same_mode && same_jll_usage && same_path
# @info "Already using Developer mode with the same settings"
# return
# end

# _PREFS_CHANGED[] = true
# _set("mode" => MODE_DEVELOPER,
# "use_jll" => use_jll,
# "path" => path;
# export_prefs, force)

# @info "Developer mode enabled"
# if _DEPS_LOADED[]
# error("Developer Mode: Restart Julia for changes to take effect. You will need to run Pkg.build().")
# end
# end
end)

end
Expand Down
2 changes: 1 addition & 1 deletion lib/legate_jl_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
project(LegateWrapper)

set(LegateWrapperVersion 0.0.1)
Expand Down
17 changes: 12 additions & 5 deletions scripts/build_cpp_wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
set -e

# Check if exactly one argument is provided
if [[ $# -ne 4 ]]; then
echo "Usage: $0 <legate-pkg> <legate-root> <install-dir> <nthreads>"
if [[ $# -ne 5 ]]; then
echo "Usage: $0 <legate-pkg> <legate-root> <ctk_root> <install-dir> <nthreads>"
exit 1
fi
LEGATEJL_PKG_ROOT_DIR=$1 # this is the repo root of legate.jl
LEGATE_ROOT=$2 # location of LEGATE_ROOT
INSTALL_DIR=$3
NTHREADS=$4
CUDA_TOOLKIT_ROOT=$3
INSTALL_DIR=$4
NTHREADS=$5

# Check if the provided argument is a valid directory
if [[ ! -d "$LEGATEJL_PKG_ROOT_DIR" ]]; then
Expand All @@ -21,6 +22,11 @@ if [[ ! -d "$LEGATE_ROOT" ]]; then
exit 1
fi

if [[ ! -d "$CUDA_TOOLKIT_ROOT" ]]; then
echo "Error: '$CUDA_TOOLKIT_ROOT' is not a valid directory."
exit 1
fi


LEGION_CMAKE_DIR=$LEGATE_ROOT/share/Legion/cmake
REALM_CMAKE_DIR=$LEGATE_ROOT/lib/cmake/realm
Expand All @@ -41,6 +47,7 @@ cmake -S $LEGATE_WRAPPER_SOURCE -B $BUILD_DIR \
-D CMAKE_INSTALL_PREFIX=$INSTALL_DIR \
-D BINARYBUILDER=OFF \
-D CMAKE_PREFIX_PATH="$LEGATE_CMAKE_DIR;$LEGION_CMAKE_DIR;$REALM_CMAKE_DIR" \
-D CMAKE_BUILD_TYPE=Debug
-D CMAKE_BUILD_TYPE=Release \
-D CUDAToolkit_ROOT=$CUDA_TOOLKIT_ROOT

cmake --build $BUILD_DIR --parallel $NTHREADS --verbose
Loading