Skip to content
Draft
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 .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# See https://github.com/actions/labeler
port-to-master: '**'
port-to-v1.10: '**'
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!---
PRs to RelationalAI/julia must be opened to the correct branch (see
https://github.com/RelationalAI/raicode/blob/master/nix/julia-version.json).
-->
## PR Description

_What does this PR do?_

## Checklist

Requirements for merging:
- [ ] I have opened an issue or PR upstream on JuliaLang/julia: <link to JuliaLang/julia>
- [ ] I have removed the `port-to-*` labels that don't apply.
- [ ] I have opened a PR on raicode to test these changes: <link to raicode>
17 changes: 17 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://github.com/actions/labeler
name: "Pull Request Labeler"
on:
pull_request_target:
types:
- opened

jobs:
triage:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v4
with:
dot: true
16 changes: 16 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Close stale PRs"
on:
schedule:
- cron: "0 0 * * *" # every night at midnight

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v8
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Comment or remove stale label, or this PR will be closed in 5 days.'
days-before-stale: 30
days-before-close: 5
stale-pr-label: 'stale'
28 changes: 28 additions & 0 deletions .github/workflows/update-upstream-branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Update upstream branches"
on:
schedule:
- cron: "0 0 * * *" # every night at midnight
workflow_dispatch:

jobs:
PullUpstream:
runs-on: ubuntu-latest
strategy:
fail-fast: false # run all jobs in the matrix even if one fails
matrix:
branch:
- "master"
- "backports-release-1.10"
steps:
- name: Checkout RAI/julia
uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}
- name: Update ${{ matrix.branch }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "RAI CI (GitHub Action Automation)"

git remote add upstream https://github.com/JuliaLang/julia
git pull upstream ${{ matrix.branch }}
git push origin ${{ matrix.branch }}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.1
1.12.1+RAI
14 changes: 14 additions & 0 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4183,6 +4183,20 @@ function expand_compiler_path(tup)
end
compiler_chi(tup::Tuple) = CacheHeaderIncludes(expand_compiler_path(tup))

"""
isprecompilable(f, argtypes::Tuple{Vararg{Any}})

Check, as far as is possible without actually compiling, if the given
function `f` can be compiled for the argument tuple (of types) `argtypes`.
"""
function isprecompilable(@nospecialize(f), @nospecialize(argtypes::Tuple))
isprecompilable(Tuple{Core.Typeof(f), argtypes...})
end

function isprecompilable(@nospecialize(argt::Type))
ccall(:jl_is_compilable, Int32, (Any,), argt) != 0
end

"""
precompile(f, argtypes::Tuple{Vararg{Any}})

Expand Down
1 change: 1 addition & 0 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct JLOptions
trim::Int8
task_metrics::Int8
timeout_for_safepoint_straggler_s::Int16
safe_crash_log_file::Ptr{UInt8}
end

# This runs early in the sysimage != is not defined yet
Expand Down
2 changes: 1 addition & 1 deletion base/partr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function multiq_sift_down(heap::taskheap, idx::Int32)
child = Int(child)
child > length(heap.tasks) && break
if isassigned(heap.tasks, child) &&
heap.tasks[child].priority < heap.tasks[idx].priority
heap.tasks[child].priority <= heap.tasks[idx].priority
t = heap.tasks[idx]
heap.tasks[idx] = heap.tasks[child]
heap.tasks[child] = t
Expand Down
2 changes: 1 addition & 1 deletion deps/openblas.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ OPENBLAS_CFLAGS := -O2

# Decide whether to build for 32-bit or 64-bit arch
ifneq ($(XC_HOST),)
OPENBLAS_BUILD_OPTS += OSNAME=$(OS) CROSS=1 HOSTCC=$(HOSTCC) CROSS_SUFFIX=$(CROSS_COMPILE)
OPENBLAS_BUILD_OPTS += OSNAME=$(OS) CROSS=1 HOSTCC="$(HOSTCC)" CROSS_SUFFIX=$(CROSS_COMPILE)
endif
ifeq ($(OS),WINNT)
ifneq ($(ARCH),x86_64)
Expand Down
30 changes: 29 additions & 1 deletion src/gc-pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ JL_DLLEXPORT uint64_t jl_get_pg_size(void)

static int block_pg_cnt = DEFAULT_BLOCK_PG_ALLOC;

// Julia allocates large blocks (64M) with mmap. These are never
// unmapped but the underlying physical memory may be released
// with calls to madvise(MADV_DONTNEED).
static uint64_t poolmem_blocks_allocated_total = 0;

JL_DLLEXPORT uint64_t jl_poolmem_blocks_allocated_total(void)
{
return poolmem_blocks_allocated_total;
}

JL_DLLEXPORT uint64_t jl_poolmem_bytes_allocated(void)
{
return jl_atomic_load_relaxed(&gc_heap_stats.bytes_resident);
}

JL_DLLEXPORT uint64_t jl_current_pg_count(void)
{
assert(jl_page_size == GC_PAGE_SZ && "RAI fork of Julia should be running on platforms for which jl_page_size == GC_PAGE_SZ");
size_t nb = jl_atomic_load_relaxed(&gc_heap_stats.bytes_resident);
return nb / GC_PAGE_SZ; // exact division
}

void jl_gc_init_page(void)
{
if (GC_PAGE_SZ * block_pg_cnt < jl_page_size)
Expand Down Expand Up @@ -55,13 +77,19 @@ char *jl_gc_try_alloc_pages_(int pg_cnt) JL_NOTSAFEPOINT
MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (mem == MAP_FAILED)
return NULL;

#ifdef MADV_NOHUGEPAGE
madvise(mem, pages_sz, MADV_NOHUGEPAGE);
#endif

#endif
if (GC_PAGE_SZ > jl_page_size)
// round data pointer up to the nearest gc_page_data-aligned
// boundary if mmap didn't already do so.
mem = (char*)gc_page_data(mem + GC_PAGE_SZ - 1);
jl_atomic_fetch_add_relaxed(&gc_heap_stats.bytes_mapped, pages_sz);
jl_atomic_fetch_add_relaxed(&gc_heap_stats.bytes_resident, pages_sz);
poolmem_blocks_allocated_total++; // RAI-specific
return mem;
}

Expand Down Expand Up @@ -184,7 +212,7 @@ void jl_gc_free_page(jl_gc_pagemeta_t *pg) JL_NOTSAFEPOINT
}
#ifdef _OS_WINDOWS_
VirtualFree(p, decommit_size, MEM_DECOMMIT);
#elif defined(MADV_FREE)
#elif 0
static int supports_madv_free = 1;
if (supports_madv_free) {
if (madvise(p, decommit_size, MADV_FREE) == -1) {
Expand Down
6 changes: 4 additions & 2 deletions src/gc-stacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ static void *malloc_stack(size_t bufsz) JL_NOTSAFEPOINT
munmap(stk, bufsz);
return MAP_FAILED;
}
# endif

#ifdef MADV_NOHUGEPAGE
madvise(stk, bufsz, MADV_NOHUGEPAGE);
#endif
#endif
jl_atomic_fetch_add_relaxed(&num_stack_mappings, 1);
return stk;
}
Expand Down
8 changes: 8 additions & 0 deletions src/gc-stock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3397,6 +3397,9 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
return recollect;
}

extern int jl_heartbeat_pause(void);
extern int jl_heartbeat_resume(void);

JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
{
JL_PROBE_GC_BEGIN(collection);
Expand Down Expand Up @@ -3439,6 +3442,7 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
// existence of the thread in the jl_n_threads count.
//
// TODO: concurrently queue objects
jl_heartbeat_pause();
jl_fence();
gc_n_threads = jl_atomic_load_acquire(&jl_n_threads);
gc_all_tls_states = jl_atomic_load_relaxed(&jl_all_tls_states);
Expand Down Expand Up @@ -3470,6 +3474,7 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)

gc_n_threads = 0;
gc_all_tls_states = NULL;
jl_heartbeat_resume();
jl_safepoint_end_gc();
jl_gc_state_set(ptls, old_state, JL_GC_STATE_WAITING);
JL_PROBE_GC_END();
Expand Down Expand Up @@ -3906,6 +3911,9 @@ void *jl_gc_perm_alloc_nolock(size_t sz, int zero, unsigned align, unsigned offs
errno = last_errno;
if (__unlikely(pool == MAP_FAILED))
return NULL;
#ifdef MADV_NOHUGEPAGE
madvise(pool, GC_PERM_POOL_SIZE, MADV_NOHUGEPAGE);
#endif
#endif
gc_perm_pool = (uintptr_t)pool;
gc_perm_end = gc_perm_pool + GC_PERM_POOL_SIZE;
Expand Down
3 changes: 3 additions & 0 deletions src/gc-stock.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ extern uv_sem_t gc_sweep_assists_needed;
extern _Atomic(int) gc_n_threads_marking;
extern _Atomic(int) gc_n_threads_sweeping_pools;
extern _Atomic(int) n_threads_running;
extern _Atomic(int) gc_n_threads_sweeping_stacks;
extern _Atomic(int) gc_ptls_sweep_idx;
extern _Atomic(int) gc_stack_free_idx;
extern uv_barrier_t thread_init_done;
void gc_mark_queue_all_roots(jl_ptls_t ptls, jl_gc_markqueue_t *mq);
void gc_mark_finlist_(jl_gc_markqueue_t *mq, jl_value_t *fl_parent, jl_value_t **fl_begin, jl_value_t **fl_end) JL_NOTSAFEPOINT;
Expand Down
9 changes: 9 additions & 0 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3890,6 +3890,15 @@ JL_DLLEXPORT void jl_compile_method_sig(jl_method_t *m, jl_value_t *types, jl_sv
jl_compile_method_instance(mi, NULL, world);
}

JL_DLLEXPORT int jl_is_compilable(jl_tupletype_t *types)
{
size_t world = jl_atomic_load_acquire(&jl_world_counter);
size_t min_valid = 0;
size_t max_valid = ~(size_t)0;
jl_method_instance_t *mi = jl_get_compile_hint_specialization(types, world, &min_valid, &max_valid, 1);
return mi == NULL ? 0 : 1;
}

JL_DLLEXPORT int jl_compile_hint(jl_tupletype_t *types)
{
size_t world = jl_atomic_load_acquire(&jl_world_counter);
Expand Down
16 changes: 16 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ extern jl_mutex_t newly_inferred_mutex;
extern jl_mutex_t global_roots_lock;
extern jl_mutex_t profile_show_peek_cond_lock;

extern void jl_init_heartbeat(void);

static void restore_fp_env(void)
{
if (jl_set_zero_subnormals(0) || jl_set_default_nans(0)) {
Expand Down Expand Up @@ -612,6 +614,11 @@ static NOINLINE void _finish_jl_init_(jl_image_buf_t sysimage, jl_ptls_t ptls, j
jl_start_gc_threads();
uv_barrier_wait(&thread_init_done);

if (jl_base_module != NULL) {
// requires code in Base
jl_init_heartbeat();
}

jl_gc_enable(1);

if ((sysimage.kind != JL_IMAGE_KIND_NONE) &&
Expand Down Expand Up @@ -750,6 +757,15 @@ JL_DLLEXPORT void jl_init_(jl_image_buf_t sysimage)
if (jl_options.handle_signals == JL_OPTIONS_HANDLE_SIGNALS_ON)
jl_install_default_signal_handlers();

#if (defined(_OS_LINUX_) && defined(_CPU_X86_64_)) || (defined(_OS_DARWIN_) && defined(_CPU_AARCH64_))
if (jl_options.safe_crash_log_file != NULL) {
jl_sig_fd = open(jl_options.safe_crash_log_file, O_WRONLY | O_CREAT | O_APPEND, 0600);
if (jl_sig_fd == -1) {
jl_error("fatal error: could not open safe crash log file for writing");
}
}
#endif

jl_gc_init();

arraylist_new(&jl_linkage_blobs, 0);
Expand Down
1 change: 1 addition & 0 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
XX(jl_istopmod) \
XX(jl_is_binding_deprecated) \
XX(jl_is_char_signed) \
XX(jl_is_compilable) \
XX(jl_is_const) \
XX(jl_is_assertsbuild) \
XX(jl_is_debugbuild) \
Expand Down
Loading