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
8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ edition = "2018"
readme = "README.md"
repository = "https://github.com/ulysseB/telamon/"

[[bin]]
name = "expandconfig"

[[bin]]
name = "parse_event_log"

[[bench]]
name = "descent"
harness = false
Expand Down Expand Up @@ -72,7 +66,6 @@ structopt = "0.2"
bincode = "1.0"
std-semaphore = "0.1.0"
tempfile = "3.0.1"
toml = "0.4"
flate2 = "1.0.2"
dot = "0.1"
csv = "1"
Expand Down Expand Up @@ -106,4 +99,5 @@ members = [
"telamon-utils",
"telamon-gen/cc_tests",
"telamon-capi",
"telamon-explorer",
]
5 changes: 1 addition & 4 deletions backend/cuda/src/characterize/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{Context, Gpu, Kernel, PerfCounterSet};
use itertools::Itertools;
use log::*;
use num::Zero;

use telamon::codegen;
use telamon::device::{ArgMapExt, Device, ScalarArgument};
use telamon::explorer;
use telamon::helper::tensor::DimSize;
use telamon::helper::{AutoOperand, Builder, Reduce};
use telamon::ir::{self, Signature};
Expand Down Expand Up @@ -498,9 +498,6 @@ pub fn run(
result_prefix: &[u64],
result: &mut Table<u64>,
) {
if let Some(choice) = explorer::choice::default_list(space).next() {
panic!("The benchmark is not completely scheduled: {:?}", choice);
}
let dev_fun = codegen::Function::build(space);
let kernel = Kernel::compile(&dev_fun, context.gpu(), context.executor(), 1);
for &(arg, range) in args_range {
Expand Down
6 changes: 3 additions & 3 deletions backend/cuda/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use log::{debug, info};
use std::f64;
use std::sync::{atomic, mpsc, Arc};
use telamon::device::{self, AsyncCallback, Device, EvalMode, ScalarArgument};
use telamon::{codegen, explorer, ir};
use telamon::{codegen, ir, search_space::Candidate};
use utils::*;

/// Max number of candidates waiting to be evaluated.
Expand Down Expand Up @@ -225,7 +225,7 @@ impl<'a> device::Context for Context<'a> {
}
}

type AsyncPayload<'a, 'b> = (explorer::Candidate<'a>, Thunk<'b>, AsyncCallback<'a, 'b>);
type AsyncPayload<'a, 'b> = (Candidate<'a>, Thunk<'b>, AsyncCallback<'a, 'b>);

pub struct AsyncEvaluator<'a, 'b>
where
Expand All @@ -244,7 +244,7 @@ where
{
fn add_kernel(
&mut self,
candidate: explorer::Candidate<'a>,
candidate: Candidate<'a>,
callback: device::AsyncCallback<'a, 'c>,
) {
let thunk = {
Expand Down
11 changes: 3 additions & 8 deletions backend/x86/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use telamon::codegen::ParamVal;

use telamon::codegen;
use telamon::device::{self, AsyncCallback, Device, EvalMode, ScalarArgument};
use telamon::explorer;
use telamon::ir;
use telamon::search_space::Candidate;

use crossbeam;
use itertools::Itertools;
Expand Down Expand Up @@ -221,12 +221,7 @@ fn function_evaluate(fun_str: &str, args: &[ThunkArg]) -> Result<f64, ()> {
Ok(time)
}

type AsyncPayload<'a, 'b> = (
explorer::Candidate<'a>,
String,
Vec<ThunkArg>,
AsyncCallback<'a, 'b>,
);
type AsyncPayload<'a, 'b> = (Candidate<'a>, String, Vec<ThunkArg>, AsyncCallback<'a, 'b>);

pub struct AsyncEvaluator<'a, 'b>
where
Expand All @@ -243,7 +238,7 @@ where
{
fn add_kernel(
&mut self,
candidate: explorer::Candidate<'a>,
candidate: Candidate<'a>,
callback: device::AsyncCallback<'a, 'c>,
) {
let (fun_str, code_args);
Expand Down
1 change: 1 addition & 0 deletions kernels/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde = { version = "1.0", features = ["derive"] }
cuda-sys = { optional = true, version = "0.1.0" }

telamon = { path = "../" }
telamon-explorer = { path = "../telamon-explorer" }
telamon-cuda = { path = "../backend/cuda", optional=true }
telamon-x86 = { path = "../backend/x86" }
utils = { package = "telamon-utils", path = "../telamon-utils" }
Expand Down
2 changes: 1 addition & 1 deletion kernels/benches/cuda_search.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Benchmarks the exploration on CUDA gpus.
use cuda_sys::cublas::*;
use cuda_sys::cuda::*;
use telamon::explorer::config::Config;
use telamon_cuda as cuda;
use telamon_explorer::config::Config;
use telamon_kernels::statistics::estimate_mean;
use telamon_kernels::{linalg, Kernel};

Expand Down
8 changes: 4 additions & 4 deletions kernels/benches/cuda_variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use log::*;
use std::sync::Mutex;
use std::time::Duration;
use telamon::device::Context;
use telamon::explorer::local_selection;
use telamon::{device, explorer, helper};
use telamon::{device, helper, search_space::Candidate};
use telamon_cuda as cuda;
use telamon_explorer::{config, local_selection};
use telamon_kernels::{linalg, Kernel};
use utils::*;

Expand Down Expand Up @@ -49,7 +49,7 @@ where
let candidates = kernel.build_body(&signature, &context);
let candidates = std::iter::repeat(())
.flat_map(|()| {
let order = explorer::config::NewNodeOrder::WeightedRandom;
let order = config::NewNodeOrder::WeightedRandom;
let candidate_idx = order.pick_candidate(&candidates, CUT);
let candidate = candidates[unwrap!(candidate_idx)].clone();
local_selection::descend(&Default::default(), order, &context, candidate, CUT)
Expand Down Expand Up @@ -114,7 +114,7 @@ fn analyse_runtimes(mut runtimes: Vec<f64>, name: &str, bound: &str) -> (f64, f6

/// Runs a series of evaluation, sleeping the given duration betwen each evaluation.
fn run_evaluations(
candidates: &[explorer::Candidate],
candidates: &[Candidate],
context: &Context,
num_samples: usize,
sleep: Option<Duration>,
Expand Down
9 changes: 6 additions & 3 deletions kernels/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ use rpds::list::List;
use serde::{de::DeserializeOwned, Serialize};
use std::io::{Read, Write};
use std::sync::{atomic, Mutex};
use telamon::explorer::{self, choice::ActionEx, local_selection, Candidate};
use telamon::helper::SignatureBuilder;
use telamon::model::Bound;
use telamon::{codegen, device, ir};
use telamon::{
codegen, device, ir,
search_space::{ActionEx, Candidate},
};
use telamon_explorer::{self as explorer, local_selection};
use utils::*;

/// Ignore candidates with a too big bound in tests.
Expand Down Expand Up @@ -354,7 +357,7 @@ fn descend_check_bounds<'a>(

/// A sample of the accuracy of bounds.
pub struct BoundSample {
actions: Vec<explorer::choice::ActionEx>,
actions: Vec<ActionEx>,
bound: Bound,
runtime: f64,
}
Expand Down
6 changes: 3 additions & 3 deletions kernels/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ pub use crate::kernel::{analyze_bounds, Kernel};
use telamon::device::{self, ArgMap, Context};
use telamon::helper::tensor::DimSize;
use telamon::helper::{self, SignatureBuilder};
use telamon::{explorer, model, search_space};
use telamon::{model, search_space};

/// Creates a candidate from the search space and registers the tile sizes in it.
fn build_candidate<'a>(
space: search_space::SearchSpace<'a>,
ctx: &device::Context,
) -> explorer::Candidate<'a> {
) -> search_space::Candidate<'a> {
let bound = model::bound(&space, ctx);
explorer::Candidate::new(space, bound)
search_space::Candidate::new(space, bound)
}

/// Creates a `DimSize`. If the instantiate flag is true, it uses a constant size,
Expand Down
2 changes: 1 addition & 1 deletion kernels/src/linalg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use ::ndarray::{Array1, Array2, Array3, ArrayD};
use itertools::Itertools;
use rand;
use serde::{Deserialize, Serialize};
use telamon::explorer::Candidate;
use telamon::helper::tensor::*;
use telamon::helper::{self, Builder, SignatureBuilder};
use telamon::ir::DimMapScope::Global as GlobalScope;
use telamon::search_space::Candidate;
use telamon::search_space::*;
use telamon::{device, ir};
use utils::*;
Expand Down
5 changes: 5 additions & 0 deletions src/codegen/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub struct Function<'a> {
impl<'a> Function<'a> {
/// Creates a device `Function` from an IR instance.
pub fn build(space: &'a SearchSpace<'a>) -> Function<'a> {
assert!(
space.is_implementation(),
"impossible to generate code from partial implementations",
);

let mut dims = dimension::group_merged_dimensions(space);
let (induction_vars, init_induction_levels) =
dimension::register_induction_vars(&mut dims, space);
Expand Down
2 changes: 1 addition & 1 deletion src/device/context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Describes the context for which a function must be optimized.
use crate::codegen::{self, Function};
use crate::device::{ArrayArgument, Device, ScalarArgument};
use crate::explorer::Candidate;
use crate::ir;
use crate::search_space::Candidate;
use boxfnonce::SendBoxFnOnce;
use num;
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/device/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::marker::PhantomData;
use std::sync::Arc;

use crate::codegen;
use crate::explorer::Candidate;
use crate::ir;
use crate::search_space::Candidate;

use super::{
ArgMap, ArrayArgument, AsyncCallback, AsyncEvaluator, Context, Device, EvalMode,
Expand Down
6 changes: 3 additions & 3 deletions src/ir/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ impl fmt::Debug for DimId {
}
}

impl Into<usize> for DimId {
fn into(self) -> usize {
self.0 as usize
impl From<DimId> for usize {
fn from(id: DimId) -> Self {
id.0 as usize
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl<'a, L> Function<'a, L> {
}

/// Returns the list of layouts to lower.
pub(crate) fn layouts_to_lower(&self) -> &[ir::MemId] {
pub fn layouts_to_lower(&self) -> &[ir::MemId] {
&self.layouts_to_lower
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ pub mod codegen;
#[macro_use]
pub mod helper;
pub mod device;
pub mod explorer;
pub mod ir;
pub mod model;
pub mod offline_analysis;
pub mod search_space;
46 changes: 38 additions & 8 deletions src/explorer/candidate.rs → src/search_space/candidate.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
//! Exploration of the search space.
use crate::device::Context;
use crate::explorer::choice::ActionEx;
use crate::model::{bound, Bound};
use crate::search_space::SearchSpace;

use log::{debug, info, trace};
use rpds::List;
use std;
use std::cmp::{Ordering, PartialOrd};
use std::{self, fmt};

use itertools::Itertools;
use log::{debug, info, trace};
use rpds::List;
use serde::{Deserialize, Serialize};
use utils::unwrap;

use crate::device::Context;
use crate::ir;
use crate::model::{bound, Bound};
use crate::search_space::{choices::Action, SearchSpace};

/// Either a regular action or a manually applied action.
#[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ActionEx {
Action(Action),
LowerLayout {
mem: ir::MemId,
st_dims: Vec<ir::DimId>,
ld_dims: Vec<ir::DimId>,
},
}

impl fmt::Debug for ActionEx {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
// Actions are already explicitely self-describing enough
ActionEx::Action(action) => write!(f, "{:?}", action),
ActionEx::LowerLayout {
mem,
st_dims,
ld_dims,
} => write!(
f,
"LowerLayout {{ mem: {:?}, st_dims: {:?}, ld_dims: {:?} }}",
mem, st_dims, ld_dims
),
}
}
}

/// A node of the search tree.
#[derive(Clone)]
pub struct Candidate<'a> {
Expand Down
7 changes: 7 additions & 0 deletions src/search_space/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ use crate::device::Context;
use crate::ir;
use log::debug;

mod candidate;
mod dim_map;
mod operand;
use utils::generated_file;
generated_file!(choices);

pub use self::candidate::{ActionEx, Candidate};
pub use self::choices::{
Action, Bool, Choice, DimKind, Domain, DomainStore, InstFlag, MemSpace, NumSet,
Order, ThreadMapping,
Expand Down Expand Up @@ -111,6 +113,11 @@ impl<'a> SearchSpace<'a> {

Ok(())
}

/// Returns whether the candidate is a fully specified implementation.
pub fn is_implementation(&self) -> bool {
self.ir_instance.layouts_to_lower().is_empty() && self.domain.is_constrained()
}
}

/// Update the domain after a lowering.
Expand Down
2 changes: 1 addition & 1 deletion telamon-capi/src/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std;
use std::ffi::CStr;

use libc::c_char;
use telamon::explorer::{self, Config};
use telamon_explorer::{self, Config};

use super::error::TelamonStatus;
use super::search_space::SearchSpace;
Expand Down
2 changes: 1 addition & 1 deletion telamon-capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub mod search_space;

use libc::{c_char, c_int, c_uint, size_t, uint32_t};
use telamon::device;
use telamon::explorer::config::Config;
use telamon::helper::TilingPattern;
use telamon_explorer::config::Config;
pub use telamon_kernels::{linalg, Kernel};
use telamon_x86 as x86;

Expand Down
Loading