-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from boydjohnson/feature/more-primitives
Feature/more primitives
- Loading branch information
Showing
10 changed files
with
347 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use { | ||
super::PrimitiveConfig, | ||
crate::{ | ||
memory::descriptor::MemoryDescriptor, | ||
primitive::{descriptor::PrimitiveDescriptor, Forward, PropType}, | ||
}, | ||
onednnl_sys::{ | ||
dnnl_alg_kind_t, dnnl_eltwise_forward_primitive_desc_create, dnnl_primitive_attr_t, | ||
dnnl_status_t, | ||
}, | ||
}; | ||
|
||
pub struct ForwardEltwiseConfig<'a> { | ||
pub alg_kind: dnnl_alg_kind_t::Type, | ||
pub src_desc: &'a MemoryDescriptor, | ||
pub dst_desc: &'a MemoryDescriptor, | ||
pub alpha: f32, | ||
pub beta: f32, | ||
pub attr: dnnl_primitive_attr_t, | ||
} | ||
|
||
impl<'a, P: PropType<Forward>> PrimitiveConfig<'a, Forward, P> for ForwardEltwiseConfig<'a> { | ||
fn create_primitive_desc( | ||
&self, | ||
engine: std::sync::Arc<crate::engine::Engine>, | ||
) -> Result<crate::primitive::descriptor::PrimitiveDescriptor, crate::error::DnnlError> { | ||
let mut handle = std::ptr::null_mut(); | ||
let status = unsafe { | ||
dnnl_eltwise_forward_primitive_desc_create( | ||
&mut handle, | ||
engine.handle, | ||
P::KIND, | ||
self.alg_kind, | ||
self.src_desc.handle, | ||
self.dst_desc.handle, | ||
self.alpha, | ||
self.beta, | ||
self.attr, | ||
) | ||
}; | ||
|
||
if status == dnnl_status_t::dnnl_success { | ||
Ok(PrimitiveDescriptor { handle }) | ||
} else { | ||
Err(status.into()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use { | ||
super::PrimitiveConfig, | ||
crate::{ | ||
memory::descriptor::MemoryDescriptor, | ||
primitive::{descriptor::PrimitiveDescriptor, Forward, PropType}, | ||
}, | ||
onednnl_sys::{ | ||
dnnl_inner_product_forward_primitive_desc_create, dnnl_primitive_attr_t, dnnl_status_t, | ||
}, | ||
}; | ||
|
||
pub struct ForwardInnerProductConfig<'a> { | ||
pub src_desc: &'a MemoryDescriptor, | ||
pub weights_desc: &'a MemoryDescriptor, | ||
pub bias_desc: &'a MemoryDescriptor, | ||
pub dst_desc: &'a MemoryDescriptor, | ||
pub attr: dnnl_primitive_attr_t, | ||
} | ||
|
||
impl<'a, P: PropType<Forward>> PrimitiveConfig<'a, Forward, P> for ForwardInnerProductConfig<'a> { | ||
fn create_primitive_desc( | ||
&self, | ||
engine: std::sync::Arc<crate::engine::Engine>, | ||
) -> Result<crate::primitive::descriptor::PrimitiveDescriptor, crate::error::DnnlError> { | ||
let mut handle = std::ptr::null_mut(); | ||
let status = unsafe { | ||
dnnl_inner_product_forward_primitive_desc_create( | ||
&mut handle, | ||
engine.handle, | ||
P::KIND, | ||
self.src_desc.handle, | ||
self.weights_desc.handle, | ||
self.bias_desc.handle, | ||
self.dst_desc.handle, | ||
self.attr, | ||
) | ||
}; | ||
if status == dnnl_status_t::dnnl_success { | ||
Ok(PrimitiveDescriptor { handle }) | ||
} else { | ||
Err(status.into()) | ||
} | ||
} | ||
} |
Oops, something went wrong.