Skip to content
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

Updated code to work with new OpenCL stuff added to linear_algebra #1

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
640 changes: 479 additions & 161 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: rust

os:
- osx
268 changes: 251 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[package]
name = "neural_network"
version = "0.0.0"
version = "0.1.2"
authors = ["usbalbin <[email protected]>"]

[dependencies]
linear_algebra = { git = "https://github.com/usbalbin/linear_algebra.git" }
rand = "0.4.1"
linear_algebra = { git = "https://github.com/usbalbin/linear_algebra.git", branch = "OpenCL-accelerated" }
rand = "0.4.1"
ocl = "0.16.0"
lazy_static = "1.0.0"
65 changes: 65 additions & 0 deletions src/extra_kernels.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@


#if defined(IS_FLOAT) || defined(IS_FLOAT)

{T} {T}_sig_helper({T} x) {
return ({T})(1) / (({T})(1) + exp(-x));
}

kernel void {T}_sigmoid(global {T}* C, global {T}* B) {
C[i] = {T}_sig_helper(B[i]);
}

kernel void {T}_sigmoid_in_place(global {T}* C) {
C[i] = {T}_sig_helper(C[i]);
}

kernel void {T}_sigmoid_prime(global {T}* C, global {T}* B) {
{T} sig = {T}_sig_helper(B[i]);
C[i] = sig * (1.0 - sig);
}

kernel void {T}_sigmoid_prime_in_place(global {T}* C) {
{T} sig = {T}_sig_helper(C[i]);
C[i] = sig * (1.0 - sig);
}








#define lid get_local_id(0)
#define wgid get_group_id(0)
#define gz get_global_size(0)

/// Calculate the sum of all the elements in the vector
kernel void {T}_validate_sample(global const {T}* data, global const {T}* expected_data, global {T}* results, int count, local {T}* temp) {

{T} value = 0.0;
for (int globalIndex = i; globalIndex < count; globalIndex += gz) {
value += fabs(data[globalIndex] - expected_data[globalIndex]) > 0.5 ? 0.0 : 1.0;
}

temp[lid] = value;
barrier(CLK_LOCAL_MEM_FENCE);

for (int offset = lz / 2; offset > 0; offset /= 2) {
if (lid < offset)
temp[lid] += temp[lid + offset];
barrier(CLK_LOCAL_MEM_FENCE);
}

if (lid == 0) {
results[wgid] = temp[0];
}
}

#undef gz
#undef wgid
#undef lid

#endif

Loading