This commit is contained in:
abdul124 2024-08-02 17:46:49 +08:00
parent 2237137f1a
commit 8f6e3a5bd8
35 changed files with 153 additions and 11 deletions

View File

@ -17,12 +17,6 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "cslice"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f8cb7306107e4b10e64994de6d3274bd08996a7c1322a27b86482392f96be0a"
[[package]]
name = "libm"
version = "0.2.8"
@ -33,7 +27,6 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
name = "linalg"
version = "0.1.0"
dependencies = [
"cslice",
"nalgebra",
]

View File

@ -8,6 +8,12 @@ crate-type = ["staticlib"]
[dependencies]
nalgebra = {version = "0.32.6", default-features = false, features = ["libm", "alloc"]}
cslice = "0.3.0"
#cslice = "0.3.0"
#[dependencies.nalgebra]
#git = "https://git.m-labs.hk/M-labs/nalgebra.git"
#rev = "dd00f9b"
#default-features = false
#features = ["libm", "alloc"]
[workspace]

View File

@ -0,0 +1,11 @@
# cross-shell.nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = [
pkgs.binutils
pkgs.gcc
pkgs.rustc.override { targets = ["i686-unknown-linux-gnu"]; }
pkgs.cargo.override { targets = ["i686-unknown-linux-gnu"]; }
];
}

View File

@ -0,0 +1,49 @@
{ pkgs ? import <nixpkgs> {} }:
let
fenix = import (fetchTarball "https://github.com/nix-community/fenix/archive/main.tar.gz") {
system = "x86_64-linux";
};
targets = ["i686-unknown-linux-gnu" "x86_64-unknown-linux-gnu"];
fenixToolchain = fenix.stable.toolchain.overrideAttrs (old: {
inherit targets;
});
in
pkgs.rustPlatform.buildRustPackage {
name = "my-crate";
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = with fenixToolchain; [
rust
] ++ (builtins.concatLists (
map (target: [
(rust.override { inherit targets; })
]) targets
));
buildAndTestSubdir = ".";
buildPhase = ''
${builtins.concatStringsSep "\n" (map (target:
''
cargo build --release --target ${target} --locked
''
) targets)}
'';
installPhase = ''
mkdir -p $out/lib
${builtins.concatStringsSep "\n" (map (target:
''
cp target/${target}/release/libmy_crate.a $out/lib/libmy_crate-${target}.a
''
) targets)}
'';
}

View File

@ -0,0 +1,21 @@
{
"llvm-target": "i686-unknown-none",
"data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128",
"arch": "x86",
"target-endian": "little",
"target-pointer-width": "32",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"pre-link-args": {
"ld.lld": [
"--script=linker.ld",
"--Map=target/linker.map"
]
},
"features": "-mmx,-sse,+soft-float"
}

View File

@ -0,0 +1,58 @@
ENTRY(_start_bootloader)
SECTIONS {
. = 0x4000;
. = ALIGN(0x1000);
__smp_trampoline_start = .;
.smp_trampoline :
{
*(.smp_trampoline)
}
. = ALIGN(0x1000);
__smp_trampoline_end = .;
. = 1M;
__bootloader_start = .;
.boot : ALIGN(2)
{
/* ensure that the multiboot header is at the beginning */
KEEP(*(.multiboot_header))
}
.bootloader : ALIGN(16)
{
*(.init_bootloader)
*(.text .text.*)
*(.rodata .rodata.*)
*(.data .data.*)
*(.bss .bss.*)
*(.got .got.*)
}
. = ALIGN(0x1000);
__bootloader_end = .;
. = 2M;
__kernel_start = .;
.kernel :
{
KEEP(*(.kernel))
}
. = ALIGN(0x1000);
__kernel_end = .;
. = ALIGN(0x1000);
__page_table_start = .;
_p4 = .;
. += 0x1000;
_p3 = .;
. += 0x1000;
_p2_tables_start = .;
. += 0x4000; /* One p2 table equals 1Gb memory mapped */
_p2_tables_end = .;
_p1_tables_start = .;
. += 0x1000; /* First p1 table to map 0-2Mb with 4Kb pages*/
_p1_tss_tables_start = .;
. += 0x1000 * 128; /* 1Mb per core for interrupt stacks (max 256 cores) */
_p1_tables_end = .;
__page_table_end = .;
__minimum_mem_requirement = .;
}

View File

@ -4,8 +4,9 @@
// * Both `nalgebra::Matrix` and `NDArray` require their content to be stored in row-major order
// * `NDArray` data pointer can be directly read and converted to `nalgebra::Matrix` (row and column number must be known)
// * `nalgebra::Matrix::as_slice` returns the content of matrix in column-major order and initial data needs to be transposed before storing it in `NDArray` data pointer
extern crate core;
use core::slice;
use std::slice;
use nalgebra::DMatrix;
fn report_error(
@ -19,7 +20,7 @@ fn report_error(
panic!(
"Exception {} from {} in {}:{}:{}, message: {}",
error_name, fn_name, file_name, line_num, col_num, err_msg
);
)
}
pub struct InputMatrix {
@ -247,7 +248,10 @@ pub unsafe extern "C" fn np_linalg_matrix_power(
let out_slice = unsafe { slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]) };
let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) };
let abs_pow = power.abs();
let mut abs_pow = power;
if abs_pow < 0.0 {
abs_pow = abs_pow * -1.0;
}
let matrix1 = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1);
let mut result = matrix1.pow(abs_pow as u32);