Skip to content

Pure batching without autodiff #141637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

ZuseZ4
Copy link
Member

@ZuseZ4 ZuseZ4 commented May 27, 2025

r? ghost

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) F-autodiff `#![feature(autodiff)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 27, 2025
@ZuseZ4 ZuseZ4 added F-batching `#![feature(batching)]` and removed F-autodiff `#![feature(autodiff)]` labels May 27, 2025
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` labels May 28, 2025
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
info: removing rustup binaries
info: rustup is uninstalled
##[group]Image checksum input
mingw-check-tidy
# We use the ghcr base image because ghcr doesn't have a rate limit
# and the mingw-check-tidy job doesn't cache docker images in CI.
FROM ghcr.io/rust-lang/ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
  g++ \
---

COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
           --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#12 2.832 Building wheels for collected packages: reuse
#12 2.833   Building wheel for reuse (pyproject.toml): started
#12 3.047   Building wheel for reuse (pyproject.toml): finished with status 'done'
#12 3.048   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132719 sha256=d2a2565e7037ad3883fb9337653f2e25bbb588534fbef3697286cbc26d1bf634
#12 3.048   Stored in directory: /tmp/pip-ephem-wheel-cache-pajjestz/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#12 3.051 Successfully built reuse
#12 3.051 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#12 3.463 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#12 3.464 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#12 4.008 Collecting virtualenv
#12 4.083   Downloading virtualenv-20.31.2-py3-none-any.whl (6.1 MB)
#12 4.199      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.1/6.1 MB 53.4 MB/s eta 0:00:00
#12 4.261 Collecting filelock<4,>=3.12.2
#12 4.276   Downloading filelock-3.18.0-py3-none-any.whl (16 kB)
#12 4.297 Collecting distlib<1,>=0.3.7
#12 4.313   Downloading distlib-0.3.9-py2.py3-none-any.whl (468 kB)
#12 4.320      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 91.2 MB/s eta 0:00:00
#12 4.356 Collecting platformdirs<5,>=3.9.1
#12 4.371   Downloading platformdirs-4.3.8-py3-none-any.whl (18 kB)
#12 4.455 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#12 4.657 Successfully installed distlib-0.3.9 filelock-3.18.0 platformdirs-4.3.8 virtualenv-20.31.2
#12 4.657 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#12 DONE 4.7s

#13 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#13 DONE 0.0s
---
DirectMap4k:      145344 kB
DirectMap2M:     6146048 kB
DirectMap1G:    12582912 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
##[group]Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.05s
##[endgroup]
WARN: currently no CI rustc builds have rustc debug assertions enabled. Please either set `rust.debug-assertions` to `false` if you want to use download CI rustc or set `rust.download-rustc` to `false`.
downloading https://static.rust-lang.org/dist/2025-05-27/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
---
##[endgroup]
[TIMING] core::build_steps::tool::ToolBuild { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu, tool: "tidy", path: "src/tools/tidy", mode: ToolBootstrap, source_type: InTree, extra_features: [], allow_features: "", cargo_args: [], artifact_kind: Binary } -- 34.669
[TIMING] core::build_steps::tool::Tidy { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu } -- 0.000
fmt check
Diff in /checkout/compiler/rustc_builtin_macros/src/autodiff.rs:884:
                 DiffActivity::None | DiffActivity::FakeActivitySize(_) => {
                     panic!("Should not happen");
                 }
-                DiffActivity::Vector | DiffActivity::Scalar | DiffActivity::Buffer => todo!()
+                DiffActivity::Vector | DiffActivity::Scalar | DiffActivity::Buffer => todo!(),
             }
             if let PatKind::Ident(_, ident, _) = arg.pat.kind {
                 idents.push(ident.clone());
Diff in /checkout/compiler/rustc_codegen_llvm/src/type_.rs:158:
     pub(crate) fn is_float_type(&self, ty: &'ll Type) -> bool {
         matches!(
             self.type_kind(ty),
-            TypeKind::Half | TypeKind::Float | TypeKind::Double | TypeKind::X86_FP80
-                | TypeKind::FP128 | TypeKind::PPC_FP128
+            TypeKind::Half
+                | TypeKind::Float
+                | TypeKind::Double
+                | TypeKind::X86_FP80
+                | TypeKind::FP128
+                | TypeKind::PPC_FP128
         )
     }
 
Diff in /checkout/compiler/rustc_codegen_llvm/src/type_.rs:166:
     pub(crate) fn is_vec_or_array_type(&self, ty: &'ll Type) -> bool {
-        matches!(self.type_kind(ty),
-            TypeKind::Array | TypeKind::Vector | TypeKind::ScalableVector)
+        matches!(self.type_kind(ty), TypeKind::Array | TypeKind::Vector | TypeKind::ScalableVector)
     }
 
     pub(crate) fn is_ptr_type(&self, ty: &'ll Type) -> bool {
Diff in /checkout/compiler/rustc_codegen_llvm/src/builder/autodiff.rs:109:
             DiffActivity::Buffer => (enzyme_buffer, false),
             DiffActivity::Scalar => (enzyme_scalar, true),
         };
-        let no_autodiff_only_batching = matches!(diff_activity, DiffActivity::Scalar | DiffActivity::Vector | DiffActivity::Buffer);
+        let no_autodiff_only_batching = matches!(
+            diff_activity,
+            DiffActivity::Scalar | DiffActivity::Vector | DiffActivity::Buffer
+        );
         let outer_arg = outer_args[outer_pos];
         args.push(cx.get_metadata_value(activity));
         if matches!(diff_activity, DiffActivity::Dualv) {
Diff in /checkout/compiler/rustc_codegen_llvm/src/builder/autodiff.rs:253:
 }
 
 fn is_slice(activity_pos: usize, inputs: &[DiffActivity]) -> bool {
-     if activity_pos + 1 >= inputs.len() {
-         // If there is no arg following our ptr, it also can't be a slice,
-         // since that would lead to a ptr, int pair.
-         false
-     } else {
-         let next_activity = inputs[activity_pos + 1];
-         // We analyze the MIR types and add this dummy activity if we visit a slice.
-         matches!(next_activity, DiffActivity::FakeActivitySize(_))
-     }
+    if activity_pos + 1 >= inputs.len() {
+        // If there is no arg following our ptr, it also can't be a slice,
+        // since that would lead to a ptr, int pair.
+        false
+    } else {
+        let next_activity = inputs[activity_pos + 1];
+        // We analyze the MIR types and add this dummy activity if we visit a slice.
+        matches!(next_activity, DiffActivity::FakeActivitySize(_))
+    }
 }
 
 // On LLVM-IR, we can luckily declare __enzyme_ functions without specifying the input
Diff in /checkout/compiler/rustc_codegen_llvm/src/builder/autodiff.rs:340:
                     todo!("Handle sret for reverse mode");
                 }
                 DiffMode::Batch => {
-                    let arr_ty = unsafe {
-                        llvm::LLVMArrayType2(inner_ret_ty, attrs.width as u64)
-                    };
+                    let arr_ty = unsafe { llvm::LLVMArrayType2(inner_ret_ty, attrs.width as u64) };
                     ret_ty = arr_ty;
                 }
                 _ => {
Diff in /checkout/compiler/rustc_monomorphize/src/partitioning/autodiff.rs:60:
                         | DiffActivity::Duplicated => {
                             DiffActivity::FakeActivitySize(Some(elem_size))
                         }
-                        DiffActivity::Buffer => {
-                            DiffActivity::FakeActivitySize(Some(elem_size))
-                        }
+                        DiffActivity::Buffer => DiffActivity::FakeActivitySize(Some(elem_size)),
                         DiffActivity::Const => DiffActivity::Const,
                         _ => bug!("unexpected activity for ptr/ref"),
                     };
Diff in /checkout/tests/codegen/batching/batching1.rs:16:
 //@ pretty-compare-only
 //@ pp-exact:batching.pp
 
-
 // Test that forward mode ad macros are expanded correctly.
 use std::arch::asm;
 use std::autodiff::autodiff;
Diff in /checkout/tests/codegen/batching/batching1.rs:75:
     ::core::hint::black_box((bx_0, bx_1, bx_2));
     ::core::hint::black_box(<[f32; 4usize]>::default())
 }
-
 
 fn main() {}
 
Diff in /checkout/tests/codegen/batching/batching2.rs:13:
 use ::std::prelude::rust_2015::*;
 #[macro_use]
 extern crate std;
-use std::simd::Simd;
 //@ pretty-mode:expanded
 //@ pretty-compare-only
 //@ pp-exact:batching.pp
Diff in /checkout/tests/codegen/batching/batching2.rs:23:
 // Test that forward mode ad macros are expanded correctly.
 use std::arch::asm;
 use std::autodiff::autodiff;
+use std::simd::Simd;
 
 // Generated from:
 //// ```
Diff in /checkout/tests/codegen/batching/batching2.rs:40:
 #[rustc_autodiff(Batch, 4, Buffer, Buffer)]
 #[no_mangle]
 #[inline(never)]
-fn d_square2(x: &[f32]) -> Simd<f32,4> {
+fn d_square2(x: &[f32]) -> Simd<f32, 4> {
     unsafe {
         asm!("NOP", options(nomem));
     };
fmt: checked 6031 files
Build completed unsuccessfully in 0:01:14
  local time: Wed May 28 05:54:51 UTC 2025
  network time: Wed, 28 May 2025 05:54:51 GMT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` F-batching `#![feature(batching)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants