You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by de...@apache.org on 2016/11/16 22:41:26 UTC

[5/5] incubator-systemml git commit: [SYSTEMML-446] Added GPU sel+ (relu), bias_add (both CP and GPU).

[SYSTEMML-446] Added GPU sel+ (relu), bias_add (both CP and GPU).

- Also removed redirecting of sparse GPU convolution instructions to CP.
- Also supported custom kernel when input to ReLU are greater than 2GB.
- Updating logic of number of threads for custom kernels.
- Safe conversion of long to int and safe multiplication of int by SizeOf.DOUBLE and SizeOf.INT.
- Synchronization bufferpool calls, taking care of inconsistent states (by removing isAllocated variable and always setting jcuda pointers through setter methods)
- Added Apache license to the generated ptx.

Closes #247.


Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/f2344ff6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/f2344ff6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/f2344ff6

Branch: refs/heads/master
Commit: f2344ff6fa0a39f5c426fc87c40b45cfc70dcd59
Parents: 70de5e4
Author: Niketan Pansare <np...@us.ibm.com>
Authored: Wed Nov 16 14:37:52 2016 -0800
Committer: Deron Eriksson <de...@us.ibm.com>
Committed: Wed Nov 16 14:37:52 2016 -0800

----------------------------------------------------------------------
 src/main/cpp/kernels/SystemML.cu                |  10 +
 src/main/cpp/kernels/SystemML.ptx               | 618 ++++++++++---------
 .../org/apache/sysml/hops/ConvolutionOp.java    |  23 +
 src/main/java/org/apache/sysml/hops/Hop.java    |  11 +-
 .../java/org/apache/sysml/hops/UnaryOp.java     |   5 +-
 .../apache/sysml/lops/ConvolutionTransform.java |  33 +-
 .../sysml/parser/BuiltinFunctionExpression.java |  19 +-
 .../org/apache/sysml/parser/DMLTranslator.java  |   9 +
 .../org/apache/sysml/parser/Expression.java     |   2 +-
 .../context/ExecutionContext.java               |   4 +-
 .../instructions/CPInstructionParser.java       |   1 +
 .../instructions/GPUInstructionParser.java      |  12 +-
 .../cp/ConvolutionCPInstruction.java            |  57 +-
 .../gpu/BuiltinUnaryGPUInstruction.java         |  94 +++
 .../gpu/ConvolutionGPUInstruction.java          |  53 +-
 .../instructions/gpu/GPUInstruction.java        |   2 +-
 .../gpu/MatrixBuiltinGPUInstruction.java        |  55 ++
 .../gpu/context/ExecutionConfig.java            |  58 +-
 .../instructions/gpu/context/GPUObject.java     |   9 +-
 .../instructions/gpu/context/JCudaObject.java   | 219 ++++---
 .../runtime/matrix/data/LibMatrixCUDA.java      | 140 ++++-
 .../sysml/runtime/matrix/data/LibMatrixDNN.java |  56 ++
 .../unary/matrix/FullSelectPosTest.java         |  12 +-
 src/test/scripts/functions/tensor/Conv2DTest.R  |  13 +
 .../scripts/functions/tensor/Conv2DTest.dml     |   4 +-
 25 files changed, 1057 insertions(+), 462 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/cpp/kernels/SystemML.cu
----------------------------------------------------------------------
diff --git a/src/main/cpp/kernels/SystemML.cu b/src/main/cpp/kernels/SystemML.cu
index 23a7217..0c78045 100644
--- a/src/main/cpp/kernels/SystemML.cu
+++ b/src/main/cpp/kernels/SystemML.cu
@@ -104,6 +104,16 @@ __global__ void dense_matrix_copy(double* A,  double* ret, int rlen, int clen) {
 	}
 }
 
+extern "C"
+__global__ void relu(double* A,  double* ret, int rlen, int clen) {
+	int ix = blockIdx.x * blockDim.x + threadIdx.x;
+	int iy = blockIdx.y * blockDim.y + threadIdx.y;
+	if(ix < rlen && iy < clen) {
+		int index = ix * clen + iy;
+		ret[index] = max(0.0, A[index]);
+	}
+}
+
 // Compares the value and set
 extern "C"
 __global__ void compareAndSet(double* A,  double* ret, int rlen, int clen, double compareVal, double tol, double ifEqualsVal, double ifLessThanVal, double ifGreaterThanVal) {

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/cpp/kernels/SystemML.ptx
----------------------------------------------------------------------
diff --git a/src/main/cpp/kernels/SystemML.ptx b/src/main/cpp/kernels/SystemML.ptx
index 5a1e05c..b21e18c 100644
--- a/src/main/cpp/kernels/SystemML.ptx
+++ b/src/main/cpp/kernels/SystemML.ptx
@@ -1,8 +1,24 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // Generated by NVIDIA NVVM Compiler
 //
-// Compiler Build ID: CL-19856038
-// Cuda compilation tools, release 7.5, V7.5.17
+// Compiler Build ID: CL-19805474
+// Cuda compilation tools, release 7.5, V7.5.16
 // Based on LLVM 3.4svn
 //
 
@@ -432,6 +448,54 @@ BB4_2:
 	ret;
 }
 
+	// .globl	relu
+.visible .entry relu(
+	.param .u64 relu_param_0,
+	.param .u64 relu_param_1,
+	.param .u32 relu_param_2,
+	.param .u32 relu_param_3
+)
+{
+	.reg .pred 	%p<4>;
+	.reg .b32 	%r<12>;
+	.reg .f64 	%fd<4>;
+	.reg .b64 	%rd<8>;
+
+
+	ld.param.u64 	%rd1, [relu_param_0];
+	ld.param.u64 	%rd2, [relu_param_1];
+	ld.param.u32 	%r4, [relu_param_2];
+	ld.param.u32 	%r3, [relu_param_3];
+	mov.u32 	%r5, %ctaid.x;
+	mov.u32 	%r6, %ntid.x;
+	mov.u32 	%r7, %tid.x;
+	mad.lo.s32 	%r1, %r6, %r5, %r7;
+	mov.u32 	%r8, %ntid.y;
+	mov.u32 	%r9, %ctaid.y;
+	mov.u32 	%r10, %tid.y;
+	mad.lo.s32 	%r2, %r8, %r9, %r10;
+	setp.lt.s32	%p1, %r1, %r4;
+	setp.lt.s32	%p2, %r2, %r3;
+	and.pred  	%p3, %p1, %p2;
+	@!%p3 bra 	BB5_2;
+	bra.uni 	BB5_1;
+
+BB5_1:
+	cvta.to.global.u64 	%rd3, %rd1;
+	mad.lo.s32 	%r11, %r1, %r3, %r2;
+	mul.wide.s32 	%rd4, %r11, 8;
+	add.s64 	%rd5, %rd3, %rd4;
+	ld.global.f64 	%fd1, [%rd5];
+	mov.f64 	%fd2, 0d0000000000000000;
+	max.f64 	%fd3, %fd2, %fd1;
+	cvta.to.global.u64 	%rd6, %rd2;
+	add.s64 	%rd7, %rd6, %rd4;
+	st.global.f64 	[%rd7], %fd3;
+
+BB5_2:
+	ret;
+}
+
 	// .globl	compareAndSet
 .visible .entry compareAndSet(
 	.param .u64 compareAndSet_param_0,
@@ -472,10 +536,10 @@ BB4_2:
 	setp.lt.s32	%p1, %r7, %r2;
 	setp.lt.s32	%p2, %r11, %r3;
 	and.pred  	%p3, %p1, %p2;
-	@!%p3 bra 	BB5_6;
-	bra.uni 	BB5_1;
+	@!%p3 bra 	BB6_6;
+	bra.uni 	BB6_1;
 
-BB5_1:
+BB6_1:
 	cvta.to.global.u64 	%rd4, %rd2;
 	mul.wide.s32 	%rd5, %r1, 8;
 	add.s64 	%rd6, %rd4, %rd5;
@@ -485,26 +549,26 @@ BB5_1:
 	setp.lt.f64	%p4, %fd8, %fd3;
 	cvta.to.global.u64 	%rd7, %rd3;
 	add.s64 	%rd1, %rd7, %rd5;
-	@%p4 bra 	BB5_5;
-	bra.uni 	BB5_2;
+	@%p4 bra 	BB6_5;
+	bra.uni 	BB6_2;
 
-BB5_5:
+BB6_5:
 	st.global.f64 	[%rd1], %fd4;
-	bra.uni 	BB5_6;
+	bra.uni 	BB6_6;
 
-BB5_2:
+BB6_2:
 	setp.lt.f64	%p5, %fd1, %fd2;
-	@%p5 bra 	BB5_4;
-	bra.uni 	BB5_3;
+	@%p5 bra 	BB6_4;
+	bra.uni 	BB6_3;
 
-BB5_4:
+BB6_4:
 	st.global.f64 	[%rd1], %fd5;
-	bra.uni 	BB5_6;
+	bra.uni 	BB6_6;
 
-BB5_3:
+BB6_3:
 	st.global.f64 	[%rd1], %fd6;
 
-BB5_6:
+BB6_6:
 	ret;
 }
 
@@ -545,42 +609,42 @@ BB5_6:
 	setp.lt.s32	%p2, %r1, %r14;
 	setp.lt.s32	%p3, %r2, %r10;
 	and.pred  	%p4, %p2, %p3;
-	@!%p4 bra 	BB6_53;
-	bra.uni 	BB6_1;
+	@!%p4 bra 	BB7_53;
+	bra.uni 	BB7_1;
 
-BB6_1:
+BB7_1:
 	mad.lo.s32 	%r3, %r1, %r10, %r2;
 	setp.eq.s32	%p5, %r11, 1;
 	mov.u32 	%r50, %r1;
-	@%p5 bra 	BB6_5;
+	@%p5 bra 	BB7_5;
 
 	setp.ne.s32	%p6, %r11, 2;
 	mov.u32 	%r51, %r3;
-	@%p6 bra 	BB6_4;
+	@%p6 bra 	BB7_4;
 
 	mov.u32 	%r51, %r2;
 
-BB6_4:
+BB7_4:
 	mov.u32 	%r45, %r51;
 	mov.u32 	%r4, %r45;
 	mov.u32 	%r50, %r4;
 
-BB6_5:
+BB7_5:
 	mov.u32 	%r5, %r50;
 	setp.eq.s32	%p7, %r12, 1;
 	mov.u32 	%r48, %r1;
-	@%p7 bra 	BB6_9;
+	@%p7 bra 	BB7_9;
 
 	setp.ne.s32	%p8, %r12, 2;
 	mov.u32 	%r49, %r3;
-	@%p8 bra 	BB6_8;
+	@%p8 bra 	BB7_8;
 
 	mov.u32 	%r49, %r2;
 
-BB6_8:
+BB7_8:
 	mov.u32 	%r48, %r49;
 
-BB6_9:
+BB7_9:
 	cvta.to.global.u64 	%rd5, %rd3;
 	cvta.to.global.u64 	%rd6, %rd2;
 	mul.wide.s32 	%rd7, %r5, 8;
@@ -591,47 +655,47 @@ BB6_9:
 	ld.global.f64 	%fd2, [%rd10];
 	mov.f64 	%fd38, 0dC08F380000000000;
 	setp.gt.s32	%p9, %r13, 5;
-	@%p9 bra 	BB6_19;
+	@%p9 bra 	BB7_19;
 
 	setp.gt.s32	%p19, %r13, 2;
-	@%p19 bra 	BB6_15;
+	@%p19 bra 	BB7_15;
 
 	setp.eq.s32	%p23, %r13, 0;
-	@%p23 bra 	BB6_51;
+	@%p23 bra 	BB7_51;
 
 	setp.eq.s32	%p24, %r13, 1;
-	@%p24 bra 	BB6_50;
-	bra.uni 	BB6_13;
+	@%p24 bra 	BB7_50;
+	bra.uni 	BB7_13;
 
-BB6_50:
+BB7_50:
 	sub.f64 	%fd38, %fd1, %fd2;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_19:
+BB7_19:
 	setp.gt.s32	%p10, %r13, 8;
-	@%p10 bra 	BB6_24;
+	@%p10 bra 	BB7_24;
 
 	setp.eq.s32	%p16, %r13, 6;
-	@%p16 bra 	BB6_34;
+	@%p16 bra 	BB7_34;
 
 	setp.eq.s32	%p17, %r13, 7;
-	@%p17 bra 	BB6_33;
-	bra.uni 	BB6_22;
+	@%p17 bra 	BB7_33;
+	bra.uni 	BB7_22;
 
-BB6_33:
+BB7_33:
 	setp.gt.f64	%p29, %fd1, %fd2;
 	selp.f64	%fd38, 0d3FF0000000000000, 0d0000000000000000, %p29;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_15:
+BB7_15:
 	setp.eq.s32	%p20, %r13, 3;
-	@%p20 bra 	BB6_49;
+	@%p20 bra 	BB7_49;
 
 	setp.eq.s32	%p21, %r13, 4;
-	@%p21 bra 	BB6_35;
-	bra.uni 	BB6_17;
+	@%p21 bra 	BB7_35;
+	bra.uni 	BB7_17;
 
-BB6_35:
+BB7_35:
 	{
 	.reg .b32 %temp; 
 	mov.b64 	{%temp, %r8}, %fd1;
@@ -667,10 +731,10 @@ BB6_35:
 	}// Callseq End 1
 	setp.lt.s32	%p33, %r8, 0;
 	and.pred  	%p1, %p33, %p32;
-	@!%p1 bra 	BB6_37;
-	bra.uni 	BB6_36;
+	@!%p1 bra 	BB7_37;
+	bra.uni 	BB7_36;
 
-BB6_36:
+BB7_36:
 	{
 	.reg .b32 %temp; 
 	mov.b64 	{%temp, %r23}, %fd37;
@@ -682,111 +746,111 @@ BB6_36:
 	}
 	mov.b64 	%fd37, {%r25, %r24};
 
-BB6_37:
+BB7_37:
 	mov.f64 	%fd36, %fd37;
 	setp.eq.f64	%p34, %fd1, 0d0000000000000000;
-	@%p34 bra 	BB6_40;
-	bra.uni 	BB6_38;
+	@%p34 bra 	BB7_40;
+	bra.uni 	BB7_38;
 
-BB6_40:
+BB7_40:
 	selp.b32	%r26, %r8, 0, %p32;
 	or.b32  	%r27, %r26, 2146435072;
 	setp.lt.s32	%p38, %r9, 0;
 	selp.b32	%r28, %r27, %r26, %p38;
 	mov.u32 	%r29, 0;
 	mov.b64 	%fd36, {%r29, %r28};
-	bra.uni 	BB6_41;
+	bra.uni 	BB7_41;
 
-BB6_24:
+BB7_24:
 	setp.gt.s32	%p11, %r13, 10;
-	@%p11 bra 	BB6_28;
+	@%p11 bra 	BB7_28;
 
 	setp.eq.s32	%p14, %r13, 9;
-	@%p14 bra 	BB6_32;
-	bra.uni 	BB6_26;
+	@%p14 bra 	BB7_32;
+	bra.uni 	BB7_26;
 
-BB6_32:
+BB7_32:
 	setp.eq.f64	%p27, %fd1, %fd2;
 	selp.f64	%fd38, 0d3FF0000000000000, 0d0000000000000000, %p27;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_28:
+BB7_28:
 	setp.eq.s32	%p12, %r13, 11;
-	@%p12 bra 	BB6_31;
-	bra.uni 	BB6_29;
+	@%p12 bra 	BB7_31;
+	bra.uni 	BB7_29;
 
-BB6_31:
+BB7_31:
 	min.f64 	%fd38, %fd1, %fd2;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_51:
+BB7_51:
 	add.f64 	%fd38, %fd1, %fd2;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_13:
+BB7_13:
 	setp.eq.s32	%p25, %r13, 2;
-	@%p25 bra 	BB6_14;
-	bra.uni 	BB6_52;
+	@%p25 bra 	BB7_14;
+	bra.uni 	BB7_52;
 
-BB6_14:
+BB7_14:
 	mul.f64 	%fd38, %fd1, %fd2;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_34:
+BB7_34:
 	setp.le.f64	%p30, %fd1, %fd2;
 	selp.f64	%fd38, 0d3FF0000000000000, 0d0000000000000000, %p30;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_22:
+BB7_22:
 	setp.eq.s32	%p18, %r13, 8;
-	@%p18 bra 	BB6_23;
-	bra.uni 	BB6_52;
+	@%p18 bra 	BB7_23;
+	bra.uni 	BB7_52;
 
-BB6_23:
+BB7_23:
 	setp.ge.f64	%p28, %fd1, %fd2;
 	selp.f64	%fd38, 0d3FF0000000000000, 0d0000000000000000, %p28;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_49:
+BB7_49:
 	div.rn.f64 	%fd38, %fd1, %fd2;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_17:
+BB7_17:
 	setp.eq.s32	%p22, %r13, 5;
-	@%p22 bra 	BB6_18;
-	bra.uni 	BB6_52;
+	@%p22 bra 	BB7_18;
+	bra.uni 	BB7_52;
 
-BB6_18:
+BB7_18:
 	setp.lt.f64	%p31, %fd1, %fd2;
 	selp.f64	%fd38, 0d3FF0000000000000, 0d0000000000000000, %p31;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_26:
+BB7_26:
 	setp.eq.s32	%p15, %r13, 10;
-	@%p15 bra 	BB6_27;
-	bra.uni 	BB6_52;
+	@%p15 bra 	BB7_27;
+	bra.uni 	BB7_52;
 
-BB6_27:
+BB7_27:
 	setp.neu.f64	%p26, %fd1, %fd2;
 	selp.f64	%fd38, 0d3FF0000000000000, 0d0000000000000000, %p26;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_29:
+BB7_29:
 	setp.ne.s32	%p13, %r13, 12;
-	@%p13 bra 	BB6_52;
+	@%p13 bra 	BB7_52;
 
 	max.f64 	%fd38, %fd1, %fd2;
-	bra.uni 	BB6_52;
+	bra.uni 	BB7_52;
 
-BB6_38:
+BB7_38:
 	setp.gt.s32	%p35, %r8, -1;
-	@%p35 bra 	BB6_41;
+	@%p35 bra 	BB7_41;
 
 	cvt.rzi.f64.f64	%fd30, %fd2;
 	setp.neu.f64	%p36, %fd30, %fd2;
 	selp.f64	%fd36, 0dFFF8000000000000, %fd36, %p36;
 
-BB6_41:
+BB7_41:
 	mov.f64 	%fd17, %fd36;
 	add.f64 	%fd18, %fd1, %fd2;
 	{
@@ -796,23 +860,23 @@ BB6_41:
 	and.b32  	%r31, %r30, 2146435072;
 	setp.ne.s32	%p39, %r31, 2146435072;
 	mov.f64 	%fd35, %fd17;
-	@%p39 bra 	BB6_48;
+	@%p39 bra 	BB7_48;
 
 	setp.gtu.f64	%p40, %fd11, 0d7FF0000000000000;
 	mov.f64 	%fd35, %fd18;
-	@%p40 bra 	BB6_48;
+	@%p40 bra 	BB7_48;
 
 	abs.f64 	%fd19, %fd2;
 	setp.gtu.f64	%p41, %fd19, 0d7FF0000000000000;
 	mov.f64 	%fd34, %fd18;
 	mov.f64 	%fd35, %fd34;
-	@%p41 bra 	BB6_48;
+	@%p41 bra 	BB7_48;
 
 	setp.eq.f64	%p42, %fd19, 0d7FF0000000000000;
-	@%p42 bra 	BB6_47;
-	bra.uni 	BB6_45;
+	@%p42 bra 	BB7_47;
+	bra.uni 	BB7_45;
 
-BB6_47:
+BB7_47:
 	setp.gt.f64	%p44, %fd11, 0d3FF0000000000000;
 	selp.b32	%r38, 2146435072, 0, %p44;
 	xor.b32  	%r39, %r38, 2146435072;
@@ -822,12 +886,12 @@ BB6_47:
 	selp.b32	%r41, 1072693248, %r40, %p46;
 	mov.u32 	%r42, 0;
 	mov.b64 	%fd35, {%r42, %r41};
-	bra.uni 	BB6_48;
+	bra.uni 	BB7_48;
 
-BB6_45:
+BB7_45:
 	setp.neu.f64	%p43, %fd11, 0d7FF0000000000000;
 	mov.f64 	%fd35, %fd17;
-	@%p43 bra 	BB6_48;
+	@%p43 bra 	BB7_48;
 
 	shr.s32 	%r32, %r9, 31;
 	and.b32  	%r33, %r32, -2146435072;
@@ -837,19 +901,19 @@ BB6_45:
 	mov.u32 	%r37, 0;
 	mov.b64 	%fd35, {%r37, %r36};
 
-BB6_48:
+BB7_48:
 	setp.eq.f64	%p47, %fd2, 0d0000000000000000;
 	setp.eq.f64	%p48, %fd1, 0d3FF0000000000000;
 	or.pred  	%p49, %p48, %p47;
 	selp.f64	%fd38, 0d3FF0000000000000, %fd35, %p49;
 
-BB6_52:
+BB7_52:
 	cvta.to.global.u64 	%rd12, %rd4;
 	mul.wide.s32 	%rd13, %r3, 8;
 	add.s64 	%rd14, %rd12, %rd13;
 	st.global.f64 	[%rd14], %fd38;
 
-BB6_53:
+BB7_53:
 	ret;
 }
 
@@ -888,7 +952,7 @@ BB6_53:
 	mad.lo.s32 	%r1, %r14, %r15, %r17;
 	mul.lo.s32 	%r18, %r9, %r8;
 	setp.ge.s32	%p3, %r1, %r18;
-	@%p3 bra 	BB7_88;
+	@%p3 bra 	BB8_88;
 
 	cvta.to.global.u64 	%rd6, %rd5;
 	cvta.to.global.u64 	%rd7, %rd4;
@@ -897,178 +961,178 @@ BB6_53:
 	ld.global.f64 	%fd1, [%rd9];
 	add.s64 	%rd1, %rd6, %rd8;
 	setp.eq.s32	%p4, %r7, 0;
-	@%p4 bra 	BB7_45;
+	@%p4 bra 	BB8_45;
 
 	setp.eq.s32	%p5, %r6, 0;
-	@%p5 bra 	BB7_43;
+	@%p5 bra 	BB8_43;
 
 	mov.f64 	%fd66, 0dC08F380000000000;
 	setp.gt.s32	%p6, %r6, 6;
-	@%p6 bra 	BB7_13;
+	@%p6 bra 	BB8_13;
 
 	setp.gt.s32	%p14, %r6, 3;
-	@%p14 bra 	BB7_9;
+	@%p14 bra 	BB8_9;
 
 	setp.eq.s32	%p18, %r6, 1;
-	@%p18 bra 	BB7_42;
+	@%p18 bra 	BB8_42;
 
 	setp.eq.s32	%p19, %r6, 2;
-	@%p19 bra 	BB7_41;
-	bra.uni 	BB7_7;
+	@%p19 bra 	BB8_41;
+	bra.uni 	BB8_7;
 
-BB7_41:
+BB8_41:
 	mul.f64 	%fd66, %fd1, %fd54;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_45:
+BB8_45:
 	setp.eq.s32	%p45, %r6, 0;
-	@%p45 bra 	BB7_86;
+	@%p45 bra 	BB8_86;
 
 	mov.f64 	%fd74, 0dC08F380000000000;
 	setp.gt.s32	%p46, %r6, 6;
-	@%p46 bra 	BB7_56;
+	@%p46 bra 	BB8_56;
 
 	setp.gt.s32	%p54, %r6, 3;
-	@%p54 bra 	BB7_52;
+	@%p54 bra 	BB8_52;
 
 	setp.eq.s32	%p58, %r6, 1;
-	@%p58 bra 	BB7_85;
+	@%p58 bra 	BB8_85;
 
 	setp.eq.s32	%p59, %r6, 2;
-	@%p59 bra 	BB7_84;
-	bra.uni 	BB7_50;
+	@%p59 bra 	BB8_84;
+	bra.uni 	BB8_50;
 
-BB7_84:
+BB8_84:
 	mul.f64 	%fd74, %fd1, %fd54;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_43:
+BB8_43:
 	add.f64 	%fd66, %fd1, %fd54;
 
-BB7_44:
+BB8_44:
 	st.global.f64 	[%rd1], %fd66;
-	bra.uni 	BB7_88;
+	bra.uni 	BB8_88;
 
-BB7_13:
+BB8_13:
 	setp.gt.s32	%p7, %r6, 9;
-	@%p7 bra 	BB7_18;
+	@%p7 bra 	BB8_18;
 
 	setp.eq.s32	%p11, %r6, 7;
-	@%p11 bra 	BB7_25;
+	@%p11 bra 	BB8_25;
 
 	setp.eq.s32	%p12, %r6, 8;
-	@%p12 bra 	BB7_24;
-	bra.uni 	BB7_16;
+	@%p12 bra 	BB8_24;
+	bra.uni 	BB8_16;
 
-BB7_24:
+BB8_24:
 	setp.le.f64	%p23, %fd1, %fd54;
 	selp.f64	%fd66, 0d3FF0000000000000, 0d0000000000000000, %p23;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_86:
+BB8_86:
 	add.f64 	%fd74, %fd1, %fd54;
 
-BB7_87:
+BB8_87:
 	st.global.f64 	[%rd1], %fd74;
 
-BB7_88:
+BB8_88:
 	ret;
 
-BB7_56:
+BB8_56:
 	setp.gt.s32	%p47, %r6, 9;
-	@%p47 bra 	BB7_61;
+	@%p47 bra 	BB8_61;
 
 	setp.eq.s32	%p51, %r6, 7;
-	@%p51 bra 	BB7_68;
+	@%p51 bra 	BB8_68;
 
 	setp.eq.s32	%p52, %r6, 8;
-	@%p52 bra 	BB7_67;
-	bra.uni 	BB7_59;
+	@%p52 bra 	BB8_67;
+	bra.uni 	BB8_59;
 
-BB7_67:
+BB8_67:
 	setp.ge.f64	%p63, %fd1, %fd54;
 	selp.f64	%fd74, 0d3FF0000000000000, 0d0000000000000000, %p63;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_9:
+BB8_9:
 	setp.eq.s32	%p15, %r6, 4;
-	@%p15 bra 	BB7_27;
+	@%p15 bra 	BB8_27;
 
 	setp.eq.s32	%p16, %r6, 5;
-	@%p16 bra 	BB7_26;
-	bra.uni 	BB7_11;
+	@%p16 bra 	BB8_26;
+	bra.uni 	BB8_11;
 
-BB7_26:
+BB8_26:
 	setp.gt.f64	%p26, %fd1, %fd54;
 	selp.f64	%fd66, 0d3FF0000000000000, 0d0000000000000000, %p26;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_18:
+BB8_18:
 	setp.eq.s32	%p8, %r6, 10;
-	@%p8 bra 	BB7_23;
+	@%p8 bra 	BB8_23;
 
 	setp.eq.s32	%p9, %r6, 11;
-	@%p9 bra 	BB7_22;
-	bra.uni 	BB7_20;
+	@%p9 bra 	BB8_22;
+	bra.uni 	BB8_20;
 
-BB7_22:
+BB8_22:
 	min.f64 	%fd66, %fd54, %fd1;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_52:
+BB8_52:
 	setp.eq.s32	%p55, %r6, 4;
-	@%p55 bra 	BB7_70;
+	@%p55 bra 	BB8_70;
 
 	setp.eq.s32	%p56, %r6, 5;
-	@%p56 bra 	BB7_69;
-	bra.uni 	BB7_54;
+	@%p56 bra 	BB8_69;
+	bra.uni 	BB8_54;
 
-BB7_69:
+BB8_69:
 	setp.lt.f64	%p66, %fd1, %fd54;
 	selp.f64	%fd74, 0d3FF0000000000000, 0d0000000000000000, %p66;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_61:
+BB8_61:
 	setp.eq.s32	%p48, %r6, 10;
-	@%p48 bra 	BB7_66;
+	@%p48 bra 	BB8_66;
 
 	setp.eq.s32	%p49, %r6, 11;
-	@%p49 bra 	BB7_65;
-	bra.uni 	BB7_63;
+	@%p49 bra 	BB8_65;
+	bra.uni 	BB8_63;
 
-BB7_65:
+BB8_65:
 	min.f64 	%fd74, %fd1, %fd54;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_42:
+BB8_42:
 	sub.f64 	%fd66, %fd54, %fd1;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_7:
+BB8_7:
 	setp.eq.s32	%p20, %r6, 3;
-	@%p20 bra 	BB7_8;
-	bra.uni 	BB7_44;
+	@%p20 bra 	BB8_8;
+	bra.uni 	BB8_44;
 
-BB7_8:
+BB8_8:
 	div.rn.f64 	%fd66, %fd54, %fd1;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_25:
+BB8_25:
 	setp.lt.f64	%p24, %fd1, %fd54;
 	selp.f64	%fd66, 0d3FF0000000000000, 0d0000000000000000, %p24;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_16:
+BB8_16:
 	setp.eq.s32	%p13, %r6, 9;
-	@%p13 bra 	BB7_17;
-	bra.uni 	BB7_44;
+	@%p13 bra 	BB8_17;
+	bra.uni 	BB8_44;
 
-BB7_17:
+BB8_17:
 	setp.eq.f64	%p22, %fd1, %fd54;
 	selp.f64	%fd66, 0d3FF0000000000000, 0d0000000000000000, %p22;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_27:
+BB8_27:
 	{
 	.reg .b32 %temp; 
 	mov.b64 	{%temp, %r2}, %fd54;
@@ -1104,10 +1168,10 @@ BB7_27:
 	}// Callseq End 2
 	setp.lt.s32	%p28, %r2, 0;
 	and.pred  	%p1, %p28, %p27;
-	@!%p1 bra 	BB7_29;
-	bra.uni 	BB7_28;
+	@!%p1 bra 	BB8_29;
+	bra.uni 	BB8_28;
 
-BB7_28:
+BB8_28:
 	{
 	.reg .b32 %temp; 
 	mov.b64 	{%temp, %r21}, %fd65;
@@ -1119,72 +1183,72 @@ BB7_28:
 	}
 	mov.b64 	%fd65, {%r23, %r22};
 
-BB7_29:
+BB8_29:
 	mov.f64 	%fd64, %fd65;
 	setp.eq.f64	%p29, %fd54, 0d0000000000000000;
-	@%p29 bra 	BB7_32;
-	bra.uni 	BB7_30;
+	@%p29 bra 	BB8_32;
+	bra.uni 	BB8_30;
 
-BB7_32:
+BB8_32:
 	selp.b32	%r24, %r2, 0, %p27;
 	or.b32  	%r25, %r24, 2146435072;
 	setp.lt.s32	%p33, %r3, 0;
 	selp.b32	%r26, %r25, %r24, %p33;
 	mov.u32 	%r27, 0;
 	mov.b64 	%fd64, {%r27, %r26};
-	bra.uni 	BB7_33;
+	bra.uni 	BB8_33;
 
-BB7_11:
+BB8_11:
 	setp.eq.s32	%p17, %r6, 6;
-	@%p17 bra 	BB7_12;
-	bra.uni 	BB7_44;
+	@%p17 bra 	BB8_12;
+	bra.uni 	BB8_44;
 
-BB7_12:
+BB8_12:
 	setp.ge.f64	%p25, %fd1, %fd54;
 	selp.f64	%fd66, 0d3FF0000000000000, 0d0000000000000000, %p25;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_23:
+BB8_23:
 	setp.neu.f64	%p21, %fd1, %fd54;
 	selp.f64	%fd66, 0d3FF0000000000000, 0d0000000000000000, %p21;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_20:
+BB8_20:
 	setp.ne.s32	%p10, %r6, 12;
-	@%p10 bra 	BB7_44;
+	@%p10 bra 	BB8_44;
 
 	max.f64 	%fd66, %fd54, %fd1;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_85:
+BB8_85:
 	sub.f64 	%fd74, %fd1, %fd54;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_50:
+BB8_50:
 	setp.eq.s32	%p60, %r6, 3;
-	@%p60 bra 	BB7_51;
-	bra.uni 	BB7_87;
+	@%p60 bra 	BB8_51;
+	bra.uni 	BB8_87;
 
-BB7_51:
+BB8_51:
 	div.rn.f64 	%fd74, %fd1, %fd54;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_68:
+BB8_68:
 	setp.gt.f64	%p64, %fd1, %fd54;
 	selp.f64	%fd74, 0d3FF0000000000000, 0d0000000000000000, %p64;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_59:
+BB8_59:
 	setp.eq.s32	%p53, %r6, 9;
-	@%p53 bra 	BB7_60;
-	bra.uni 	BB7_87;
+	@%p53 bra 	BB8_60;
+	bra.uni 	BB8_87;
 
-BB7_60:
+BB8_60:
 	setp.eq.f64	%p62, %fd1, %fd54;
 	selp.f64	%fd74, 0d3FF0000000000000, 0d0000000000000000, %p62;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_70:
+BB8_70:
 	{
 	.reg .b32 %temp; 
 	mov.b64 	{%temp, %r4}, %fd1;
@@ -1220,10 +1284,10 @@ BB7_70:
 	}// Callseq End 3
 	setp.lt.s32	%p68, %r4, 0;
 	and.pred  	%p2, %p68, %p67;
-	@!%p2 bra 	BB7_72;
-	bra.uni 	BB7_71;
+	@!%p2 bra 	BB8_72;
+	bra.uni 	BB8_71;
 
-BB7_71:
+BB8_71:
 	{
 	.reg .b32 %temp; 
 	mov.b64 	{%temp, %r43}, %fd73;
@@ -1235,52 +1299,52 @@ BB7_71:
 	}
 	mov.b64 	%fd73, {%r45, %r44};
 
-BB7_72:
+BB8_72:
 	mov.f64 	%fd72, %fd73;
 	setp.eq.f64	%p69, %fd1, 0d0000000000000000;
-	@%p69 bra 	BB7_75;
-	bra.uni 	BB7_73;
+	@%p69 bra 	BB8_75;
+	bra.uni 	BB8_73;
 
-BB7_75:
+BB8_75:
 	selp.b32	%r46, %r4, 0, %p67;
 	or.b32  	%r47, %r46, 2146435072;
 	setp.lt.s32	%p73, %r5, 0;
 	selp.b32	%r48, %r47, %r46, %p73;
 	mov.u32 	%r49, 0;
 	mov.b64 	%fd72, {%r49, %r48};
-	bra.uni 	BB7_76;
+	bra.uni 	BB8_76;
 
-BB7_54:
+BB8_54:
 	setp.eq.s32	%p57, %r6, 6;
-	@%p57 bra 	BB7_55;
-	bra.uni 	BB7_87;
+	@%p57 bra 	BB8_55;
+	bra.uni 	BB8_87;
 
-BB7_55:
+BB8_55:
 	setp.le.f64	%p65, %fd1, %fd54;
 	selp.f64	%fd74, 0d3FF0000000000000, 0d0000000000000000, %p65;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_66:
+BB8_66:
 	setp.neu.f64	%p61, %fd1, %fd54;
 	selp.f64	%fd74, 0d3FF0000000000000, 0d0000000000000000, %p61;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_63:
+BB8_63:
 	setp.ne.s32	%p50, %r6, 12;
-	@%p50 bra 	BB7_87;
+	@%p50 bra 	BB8_87;
 
 	max.f64 	%fd74, %fd1, %fd54;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 
-BB7_30:
+BB8_30:
 	setp.gt.s32	%p30, %r2, -1;
-	@%p30 bra 	BB7_33;
+	@%p30 bra 	BB8_33;
 
 	cvt.rzi.f64.f64	%fd56, %fd1;
 	setp.neu.f64	%p31, %fd56, %fd1;
 	selp.f64	%fd64, 0dFFF8000000000000, %fd64, %p31;
 
-BB7_33:
+BB8_33:
 	mov.f64 	%fd16, %fd64;
 	add.f64 	%fd17, %fd1, %fd54;
 	{
@@ -1290,23 +1354,23 @@ BB7_33:
 	and.b32  	%r29, %r28, 2146435072;
 	setp.ne.s32	%p34, %r29, 2146435072;
 	mov.f64 	%fd63, %fd16;
-	@%p34 bra 	BB7_40;
+	@%p34 bra 	BB8_40;
 
 	setp.gtu.f64	%p35, %fd10, 0d7FF0000000000000;
 	mov.f64 	%fd63, %fd17;
-	@%p35 bra 	BB7_40;
+	@%p35 bra 	BB8_40;
 
 	abs.f64 	%fd18, %fd1;
 	setp.gtu.f64	%p36, %fd18, 0d7FF0000000000000;
 	mov.f64 	%fd62, %fd17;
 	mov.f64 	%fd63, %fd62;
-	@%p36 bra 	BB7_40;
+	@%p36 bra 	BB8_40;
 
 	setp.eq.f64	%p37, %fd18, 0d7FF0000000000000;
-	@%p37 bra 	BB7_39;
-	bra.uni 	BB7_37;
+	@%p37 bra 	BB8_39;
+	bra.uni 	BB8_37;
 
-BB7_39:
+BB8_39:
 	setp.gt.f64	%p39, %fd10, 0d3FF0000000000000;
 	selp.b32	%r36, 2146435072, 0, %p39;
 	xor.b32  	%r37, %r36, 2146435072;
@@ -1316,17 +1380,17 @@ BB7_39:
 	selp.b32	%r39, 1072693248, %r38, %p41;
 	mov.u32 	%r40, 0;
 	mov.b64 	%fd63, {%r40, %r39};
-	bra.uni 	BB7_40;
+	bra.uni 	BB8_40;
 
-BB7_73:
+BB8_73:
 	setp.gt.s32	%p70, %r4, -1;
-	@%p70 bra 	BB7_76;
+	@%p70 bra 	BB8_76;
 
 	cvt.rzi.f64.f64	%fd58, %fd54;
 	setp.neu.f64	%p71, %fd58, %fd54;
 	selp.f64	%fd72, 0dFFF8000000000000, %fd72, %p71;
 
-BB7_76:
+BB8_76:
 	mov.f64 	%fd42, %fd72;
 	add.f64 	%fd43, %fd1, %fd54;
 	{
@@ -1336,23 +1400,23 @@ BB7_76:
 	and.b32  	%r51, %r50, 2146435072;
 	setp.ne.s32	%p74, %r51, 2146435072;
 	mov.f64 	%fd71, %fd42;
-	@%p74 bra 	BB7_83;
+	@%p74 bra 	BB8_83;
 
 	setp.gtu.f64	%p75, %fd36, 0d7FF0000000000000;
 	mov.f64 	%fd71, %fd43;
-	@%p75 bra 	BB7_83;
+	@%p75 bra 	BB8_83;
 
 	abs.f64 	%fd44, %fd54;
 	setp.gtu.f64	%p76, %fd44, 0d7FF0000000000000;
 	mov.f64 	%fd70, %fd43;
 	mov.f64 	%fd71, %fd70;
-	@%p76 bra 	BB7_83;
+	@%p76 bra 	BB8_83;
 
 	setp.eq.f64	%p77, %fd44, 0d7FF0000000000000;
-	@%p77 bra 	BB7_82;
-	bra.uni 	BB7_80;
+	@%p77 bra 	BB8_82;
+	bra.uni 	BB8_80;
 
-BB7_82:
+BB8_82:
 	setp.gt.f64	%p79, %fd36, 0d3FF0000000000000;
 	selp.b32	%r58, 2146435072, 0, %p79;
 	xor.b32  	%r59, %r58, 2146435072;
@@ -1362,12 +1426,12 @@ BB7_82:
 	selp.b32	%r61, 1072693248, %r60, %p81;
 	mov.u32 	%r62, 0;
 	mov.b64 	%fd71, {%r62, %r61};
-	bra.uni 	BB7_83;
+	bra.uni 	BB8_83;
 
-BB7_37:
+BB8_37:
 	setp.neu.f64	%p38, %fd10, 0d7FF0000000000000;
 	mov.f64 	%fd63, %fd16;
-	@%p38 bra 	BB7_40;
+	@%p38 bra 	BB8_40;
 
 	shr.s32 	%r30, %r3, 31;
 	and.b32  	%r31, %r30, -2146435072;
@@ -1377,17 +1441,17 @@ BB7_37:
 	mov.u32 	%r35, 0;
 	mov.b64 	%fd63, {%r35, %r34};
 
-BB7_40:
+BB8_40:
 	setp.eq.f64	%p42, %fd1, 0d0000000000000000;
 	setp.eq.f64	%p43, %fd54, 0d3FF0000000000000;
 	or.pred  	%p44, %p43, %p42;
 	selp.f64	%fd66, 0d3FF0000000000000, %fd63, %p44;
-	bra.uni 	BB7_44;
+	bra.uni 	BB8_44;
 
-BB7_80:
+BB8_80:
 	setp.neu.f64	%p78, %fd36, 0d7FF0000000000000;
 	mov.f64 	%fd71, %fd42;
-	@%p78 bra 	BB7_83;
+	@%p78 bra 	BB8_83;
 
 	shr.s32 	%r52, %r5, 31;
 	and.b32  	%r53, %r52, -2146435072;
@@ -1397,12 +1461,12 @@ BB7_80:
 	mov.u32 	%r57, 0;
 	mov.b64 	%fd71, {%r57, %r56};
 
-BB7_83:
+BB8_83:
 	setp.eq.f64	%p82, %fd54, 0d0000000000000000;
 	setp.eq.f64	%p83, %fd1, 0d3FF0000000000000;
 	or.pred  	%p84, %p83, %p82;
 	selp.f64	%fd74, 0d3FF0000000000000, %fd71, %p84;
-	bra.uni 	BB7_87;
+	bra.uni 	BB8_87;
 }
 
 	// .globl	fill
@@ -1426,14 +1490,14 @@ BB7_83:
 	mov.u32 	%r5, %tid.x;
 	mad.lo.s32 	%r1, %r4, %r3, %r5;
 	setp.ge.s32	%p1, %r1, %r2;
-	@%p1 bra 	BB8_2;
+	@%p1 bra 	BB9_2;
 
 	cvta.to.global.u64 	%rd2, %rd1;
 	mul.wide.s32 	%rd3, %r1, 8;
 	add.s64 	%rd4, %rd2, %rd3;
 	st.global.f64 	[%rd4], %fd1;
 
-BB8_2:
+BB9_2:
 	ret;
 }
 
@@ -1460,7 +1524,7 @@ BB8_2:
 	}
 	shr.u32 	%r47, %r46, 20;
 	setp.ne.s32	%p1, %r47, 0;
-	@%p1 bra 	BB9_2;
+	@%p1 bra 	BB10_2;
 
 	mul.f64 	%fd14, %fd12, 0d4350000000000000;
 	{
@@ -1474,13 +1538,13 @@ BB8_2:
 	shr.u32 	%r16, %r46, 20;
 	add.s32 	%r47, %r16, -54;
 
-BB9_2:
+BB10_2:
 	add.s32 	%r48, %r47, -1023;
 	and.b32  	%r17, %r46, -2146435073;
 	or.b32  	%r18, %r17, 1072693248;
 	mov.b64 	%fd134, {%r45, %r18};
 	setp.lt.u32	%p2, %r18, 1073127583;
-	@%p2 bra 	BB9_4;
+	@%p2 bra 	BB10_4;
 
 	{
 	.reg .b32 %temp; 
@@ -1494,7 +1558,7 @@ BB9_2:
 	mov.b64 	%fd134, {%r19, %r21};
 	add.s32 	%r48, %r47, -1022;
 
-BB9_4:
+BB10_4:
 	add.f64 	%fd16, %fd134, 0d3FF0000000000000;
 	// inline asm
 	rcp.approx.ftz.f64 %fd15,%fd16;
@@ -1660,13 +1724,13 @@ BB9_4:
 	mov.b32 	 %f2, %r35;
 	abs.f32 	%f1, %f2;
 	setp.lt.f32	%p4, %f1, 0f4086232B;
-	@%p4 bra 	BB9_7;
+	@%p4 bra 	BB10_7;
 
 	setp.lt.f64	%p5, %fd4, 0d0000000000000000;
 	add.f64 	%fd130, %fd4, 0d7FF0000000000000;
 	selp.f64	%fd135, 0d0000000000000000, %fd130, %p5;
 	setp.geu.f32	%p6, %f1, 0f40874800;
-	@%p6 bra 	BB9_7;
+	@%p6 bra 	BB10_7;
 
 	shr.u32 	%r36, %r13, 31;
 	add.s32 	%r37, %r13, %r36;
@@ -1681,14 +1745,14 @@ BB9_4:
 	mov.b64 	%fd132, {%r44, %r43};
 	mul.f64 	%fd135, %fd131, %fd132;
 
-BB9_7:
+BB10_7:
 	abs.f64 	%fd133, %fd135;
 	setp.eq.f64	%p7, %fd133, 0d7FF0000000000000;
-	@%p7 bra 	BB9_9;
+	@%p7 bra 	BB10_9;
 
 	fma.rn.f64 	%fd135, %fd135, %fd5, %fd135;
 
-BB9_9:
+BB10_9:
 	st.param.f64	[func_retval0+0], %fd135;
 	ret;
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/hops/ConvolutionOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/ConvolutionOp.java b/src/main/java/org/apache/sysml/hops/ConvolutionOp.java
index dae2f82..8446b11 100644
--- a/src/main/java/org/apache/sysml/hops/ConvolutionOp.java
+++ b/src/main/java/org/apache/sysml/hops/ConvolutionOp.java
@@ -31,6 +31,7 @@ import org.apache.sysml.lops.LopProperties.ExecType;
 import org.apache.sysml.parser.Expression.DataType;
 import org.apache.sysml.parser.Expression.ValueType;
 import org.apache.sysml.runtime.DMLRuntimeException;
+import org.apache.sysml.runtime.matrix.MatrixCharacteristics;
 import org.apache.sysml.runtime.matrix.data.LibMatrixDNN.ConvolutionParameters;
 
 public class ConvolutionOp extends Hop  implements MultiThreadedHop
@@ -98,6 +99,7 @@ public class ConvolutionOp extends Hop  implements MultiThreadedHop
 			case DIRECT_CONV2D:
 			case DIRECT_CONV2D_BACKWARD_DATA:
 			case DIRECT_CONV2D_BACKWARD_FILTER:
+			case BIAS_ADD:
 			{	
 				//TODO: Fix me. Currently forcing the instruction to GPU if gpu flag is set
 				if(DMLScript.USE_ACCELERATOR) {
@@ -182,6 +184,9 @@ public class ConvolutionOp extends Hop  implements MultiThreadedHop
 				|| op == ConvOp.DIRECT_CONV2D_BACKWARD_DATA) {
 			expectedNumInputs = 14;
 		}
+		else if(op == ConvOp.BIAS_ADD) {
+			expectedNumInputs = 2;
+		}
 		
 		if(inputs.size() != expectedNumInputs) {
 			throw new HopsException("Incorrect number of inputs for " + op.name());
@@ -229,6 +234,17 @@ public class ConvolutionOp extends Hop  implements MultiThreadedHop
 	{
 		// [numRows, numCols, NNZ] 
 		long[] ret = null;
+		
+		if(op == ConvOp.BIAS_ADD) {
+			MatrixCharacteristics[] mc = memo.getAllInputStats(getInput());
+			if( mc[0].rowsKnown() && mc[0].colsKnown() ) {
+				ret = new long[3];
+				ret[0] = mc[0].getRows();
+				ret[1] = mc[0].getCols();
+				ret[2] = -1;
+				return ret;
+			}
+		}
 	
 		ConvolutionParameters params;
 		try {
@@ -397,6 +413,13 @@ public class ConvolutionOp extends Hop  implements MultiThreadedHop
 	@Override
 	public void refreshSizeInformation()
 	{
+		if(op == ConvOp.BIAS_ADD) {
+			Hop input1 = getInput().get(0);
+			setDim1(input1.getDim1());
+			setDim2(input1.getDim2());
+			return;
+		}
+		
 		ConvolutionParameters params;
 		try {
 			params = parseInput();

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/hops/Hop.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/Hop.java b/src/main/java/org/apache/sysml/hops/Hop.java
index 2b9467e..6ad21e7 100644
--- a/src/main/java/org/apache/sysml/hops/Hop.java
+++ b/src/main/java/org/apache/sysml/hops/Hop.java
@@ -797,6 +797,13 @@ public abstract class Hop
 		
 		return et;
 	}
+	
+	protected ExecType findGPUExecTypeByMemEstimate(ExecType et) {
+		if(DMLScript.USE_ACCELERATOR && (DMLScript.FORCE_ACCELERATOR || getMemEstimate() < OptimizerUtils.GPU_MEMORY_BUDGET)) {
+			return ExecType.GPU;
+		}
+		return et;
+	}
 
 	public ArrayList<Hop> getParent() {
 		return _parent;
@@ -1084,7 +1091,8 @@ public abstract class Hop
 	
 	public enum ConvOp {
 		MAX_POOLING, MAX_POOLING_BACKWARD,
-		DIRECT_CONV2D, DIRECT_CONV2D_BACKWARD_FILTER, DIRECT_CONV2D_BACKWARD_DATA
+		DIRECT_CONV2D, DIRECT_CONV2D_BACKWARD_FILTER, DIRECT_CONV2D_BACKWARD_DATA,
+		BIAS_ADD
 	};
 	
 	public enum DataGenMethod {
@@ -1158,6 +1166,7 @@ public abstract class Hop
 		HopsConv2Lops.put(ConvOp.MAX_POOLING, org.apache.sysml.lops.ConvolutionTransform.OperationTypes.MAX_POOLING);
 		HopsConv2Lops.put(ConvOp.MAX_POOLING_BACKWARD, org.apache.sysml.lops.ConvolutionTransform.OperationTypes.MAX_POOLING_BACKWARD);
 		HopsConv2Lops.put(ConvOp.DIRECT_CONV2D, org.apache.sysml.lops.ConvolutionTransform.OperationTypes.DIRECT_CONV2D);
+		HopsConv2Lops.put(ConvOp.BIAS_ADD, org.apache.sysml.lops.ConvolutionTransform.OperationTypes.BIAS_ADD);
 		HopsConv2Lops.put(ConvOp.DIRECT_CONV2D_BACKWARD_FILTER, org.apache.sysml.lops.ConvolutionTransform.OperationTypes.DIRECT_CONV2D_BACKWARD_FILTER);
 		HopsConv2Lops.put(ConvOp.DIRECT_CONV2D_BACKWARD_DATA, org.apache.sysml.lops.ConvolutionTransform.OperationTypes.DIRECT_CONV2D_BACKWARD_DATA);
 	}

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/hops/UnaryOp.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/UnaryOp.java b/src/main/java/org/apache/sysml/hops/UnaryOp.java
index 992ab9d..0ab4bad 100644
--- a/src/main/java/org/apache/sysml/hops/UnaryOp.java
+++ b/src/main/java/org/apache/sysml/hops/UnaryOp.java
@@ -164,7 +164,10 @@ public class UnaryOp extends Hop implements MultiThreadedHop
 				}
 				else //default unary 
 				{
-					int k = isCumulativeUnaryOperation() ? OptimizerUtils.getConstrainedNumThreads( _maxNumThreads ) : 1;					
+					int k = isCumulativeUnaryOperation() ? OptimizerUtils.getConstrainedNumThreads( _maxNumThreads ) : 1;
+					if(_op == OpOp1.SELP) {
+						et = findGPUExecTypeByMemEstimate(et);
+					}
 					Unary unary1 = new Unary(input.constructLops(), HopsOpOp1LopsU.get(_op), 
 							                 getDataType(), getValueType(), et, k);
 					setOutputDimensions(unary1);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/lops/ConvolutionTransform.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/lops/ConvolutionTransform.java b/src/main/java/org/apache/sysml/lops/ConvolutionTransform.java
index e512982..2f3be2c 100644
--- a/src/main/java/org/apache/sysml/lops/ConvolutionTransform.java
+++ b/src/main/java/org/apache/sysml/lops/ConvolutionTransform.java
@@ -31,7 +31,8 @@ public class ConvolutionTransform extends Lop
 	
 	public enum OperationTypes {
 		MAX_POOLING, MAX_POOLING_BACKWARD,
-		DIRECT_CONV2D, DIRECT_CONV2D_BACKWARD_FILTER, DIRECT_CONV2D_BACKWARD_DATA
+		DIRECT_CONV2D, DIRECT_CONV2D_BACKWARD_FILTER, DIRECT_CONV2D_BACKWARD_DATA,
+		BIAS_ADD
 	};
 	
 	private OperationTypes operation = null;
@@ -109,6 +110,9 @@ public class ConvolutionTransform extends Lop
 		
 		case DIRECT_CONV2D:
 			return "conv2d";
+		
+		case BIAS_ADD:
+			return "bias_add";
 			
 		case DIRECT_CONV2D_BACKWARD_FILTER:
 			return "conv2d_backward_filter";
@@ -122,6 +126,33 @@ public class ConvolutionTransform extends Lop
 		}
 	}
 	
+	public String getInstructions(String input, String bias, String output) throws LopsException {
+		if(operation == OperationTypes.BIAS_ADD) {
+			StringBuilder sb = new StringBuilder();
+			sb.append( getExecType() );
+			
+			sb.append( OPERAND_DELIMITOR );
+			sb.append( getOpcode() );
+			sb.append( OPERAND_DELIMITOR );
+			sb.append( getInputs().get(0).prepInputOperand(input));
+			sb.append( OPERAND_DELIMITOR );
+			sb.append( getInputs().get(0).prepInputOperand(bias));
+			//output
+			sb.append( OPERAND_DELIMITOR );
+			sb.append( this.prepOutputOperand(output));
+			
+			//append degree of parallelism
+			if( getExecType()==ExecType.CP ) {
+				sb.append( OPERAND_DELIMITOR );
+				sb.append( numThreads );
+			}
+			return sb.toString();
+		}
+		else {
+			throw new LopsException("The operation is not supported with two operands:" + operation.name());
+		}
+	}
+	
 	//CP instructions
 	// stride1, stride2, padding1, padding2  
 	// input_shape1, input_shape2, input_shape3, input_shape4, 

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
index ef69a7a..6cd53fd 100644
--- a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
+++ b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
@@ -1102,7 +1102,20 @@ public class BuiltinFunctionExpression extends DataIdentifier
 			output.setDimensions(id.getDim1(), id2.getDim2());
 			output.setBlockDimensions(id.getRowsInBlock(), id.getColumnsInBlock()); 
 			break;
-			
+		
+		case BIAS_ADD:
+		{
+			Identifier input_id = getFirstExpr().getOutput();
+			Expression input = _args[0];
+			Expression bias = _args[1];
+			output.setDataType(DataType.MATRIX);
+			output.setValueType(ValueType.DOUBLE);
+			output.setDimensions(input_id.getDim1(), input_id.getDim2());
+			output.setBlockDimensions(input.getOutput().getRowsInBlock(), input.getOutput().getColumnsInBlock());
+			checkMatrixParam(input);
+			checkMatrixParam(bias);
+			break;
+		}
 		case CONV2D:
 		case CONV2D_BACKWARD_FILTER:
 		case CONV2D_BACKWARD_DATA:
@@ -1600,6 +1613,8 @@ public class BuiltinFunctionExpression extends DataIdentifier
 			bifop = Expression.BuiltinFunctionOp.EIGEN;
 		else if (functionName.equals("conv2d"))
 			 bifop = Expression.BuiltinFunctionOp.CONV2D;
+		else if (functionName.equals("bias_add"))
+			 bifop = Expression.BuiltinFunctionOp.BIAS_ADD;
 		else if (functionName.equals("conv2d_backward_filter"))
 			 bifop = Expression.BuiltinFunctionOp.CONV2D_BACKWARD_FILTER;
 		else if (functionName.equals("conv2d_backward_data"))
@@ -1658,4 +1673,4 @@ public class BuiltinFunctionExpression extends DataIdentifier
 				throw new LanguageException("No cast for value type "+vt);
 		}
 	}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/parser/DMLTranslator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/DMLTranslator.java b/src/main/java/org/apache/sysml/parser/DMLTranslator.java
index 6a3050e..e7e37c8 100644
--- a/src/main/java/org/apache/sysml/parser/DMLTranslator.java
+++ b/src/main/java/org/apache/sysml/parser/DMLTranslator.java
@@ -2810,6 +2810,15 @@ public class DMLTranslator
 			setBlockSizeAndRefreshSizeInfo(image, currBuiltinOp);
 			break;
 		}
+		case BIAS_ADD:
+		{
+			ArrayList<Hop> inHops1 = new ArrayList<Hop>();
+			inHops1.add(expr);
+			inHops1.add(expr2);
+			currBuiltinOp = new ConvolutionOp(target.getName(), target.getDataType(), target.getValueType(), Hop.ConvOp.BIAS_ADD, inHops1);
+			setBlockSizeAndRefreshSizeInfo(expr, currBuiltinOp);
+			break;
+		}
 		case AVG_POOL:
 		case MAX_POOL:
 		{

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/parser/Expression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/Expression.java b/src/main/java/org/apache/sysml/parser/Expression.java
index da30e64..f5c1052 100644
--- a/src/main/java/org/apache/sysml/parser/Expression.java
+++ b/src/main/java/org/apache/sysml/parser/Expression.java
@@ -91,7 +91,7 @@ public abstract class Expression
 		CUMSUM,
 		DIAG,
 		EIGEN,
-		CONV2D, CONV2D_BACKWARD_FILTER, CONV2D_BACKWARD_DATA, 
+		CONV2D, CONV2D_BACKWARD_FILTER, CONV2D_BACKWARD_DATA, BIAS_ADD,
 		MAX_POOL, AVG_POOL, MAX_POOL_BACKWARD,
 		EXP,
 		FLOOR,

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/controlprogram/context/ExecutionContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/controlprogram/context/ExecutionContext.java b/src/main/java/org/apache/sysml/runtime/controlprogram/context/ExecutionContext.java
index cef0432..9b0b52a 100644
--- a/src/main/java/org/apache/sysml/runtime/controlprogram/context/ExecutionContext.java
+++ b/src/main/java/org/apache/sysml/runtime/controlprogram/context/ExecutionContext.java
@@ -298,7 +298,7 @@ public class ExecutionContext
 			mo.setGPUObject(GPUContext.createGPUObject(mo));
 		}
 		boolean acquired = false;
-		if( !mo.getGPUObject().isAllocated ) {
+		if( !mo.getGPUObject().isAllocated() ) {
 			mo.acquireRead();
 			acquired = true;
 		}
@@ -397,7 +397,7 @@ public class ExecutionContext
 	
 	public void releaseMatrixOutputForGPUInstruction(String varName) throws DMLRuntimeException {
 		MatrixObject mo = getMatrixObject(varName);
-		if(mo.getGPUObject() == null || !mo.getGPUObject().isAllocated) {
+		if(mo.getGPUObject() == null || !mo.getGPUObject().isAllocated()) {
 			throw new DMLRuntimeException("No output is allocated on GPU");
 		}
 		mo.getGPUObject().releaseOutput();

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java b/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java
index 909525f..344cde4 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/CPInstructionParser.java
@@ -223,6 +223,7 @@ public class CPInstructionParser extends InstructionParser
 		String2CPInstructionType.put( "conv2d"      , CPINSTRUCTION_TYPE.Convolution);
 		String2CPInstructionType.put( "conv2d_backward_filter"      , CPINSTRUCTION_TYPE.Convolution);
 		String2CPInstructionType.put( "conv2d_backward_data"      , CPINSTRUCTION_TYPE.Convolution);
+		String2CPInstructionType.put( "bias_add"      , CPINSTRUCTION_TYPE.Convolution);
 		
 		// Quaternary instruction opcodes
 		String2CPInstructionType.put( "wsloss"  , CPINSTRUCTION_TYPE.Quaternary);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/instructions/GPUInstructionParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/GPUInstructionParser.java b/src/main/java/org/apache/sysml/runtime/instructions/GPUInstructionParser.java
index 96b82de..9c8be5d 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/GPUInstructionParser.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/GPUInstructionParser.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import org.apache.sysml.runtime.DMLRuntimeException;
 import org.apache.sysml.runtime.instructions.gpu.AggregateBinaryGPUInstruction;
 import org.apache.sysml.runtime.instructions.gpu.ArithmeticBinaryGPUInstruction;
+import org.apache.sysml.runtime.instructions.gpu.BuiltinUnaryGPUInstruction;
 import org.apache.sysml.runtime.instructions.gpu.ConvolutionGPUInstruction;
 import org.apache.sysml.runtime.instructions.gpu.GPUInstruction;
 import org.apache.sysml.runtime.instructions.gpu.GPUInstruction.GPUINSTRUCTION_TYPE;
@@ -39,6 +40,7 @@ public class GPUInstructionParser  extends InstructionParser
 		String2GPUInstructionType.put( "conv2d_backward_data",   GPUINSTRUCTION_TYPE.Convolution);
 		String2GPUInstructionType.put( "maxpooling",             GPUINSTRUCTION_TYPE.Convolution);
 		String2GPUInstructionType.put( "maxpooling_backward",    GPUINSTRUCTION_TYPE.Convolution);
+		String2GPUInstructionType.put( "bias_add",    			 GPUINSTRUCTION_TYPE.Convolution);
 		String2GPUInstructionType.put( "ba+*",                   GPUINSTRUCTION_TYPE.AggregateBinary);
 		String2GPUInstructionType.put( "tsmm",                   GPUINSTRUCTION_TYPE.MMTSJ);
 		String2GPUInstructionType.put( "r'",                   	 GPUINSTRUCTION_TYPE.Reorg);
@@ -57,6 +59,9 @@ public class GPUInstructionParser  extends InstructionParser
 		String2GPUInstructionType.put( "-nz"  , GPUINSTRUCTION_TYPE.ArithmeticBinary); //special - case
 		String2GPUInstructionType.put( "+*"  , GPUINSTRUCTION_TYPE.ArithmeticBinary); 
 		String2GPUInstructionType.put( "-*"  , GPUINSTRUCTION_TYPE.ArithmeticBinary); 
+		
+		
+		String2GPUInstructionType.put( "sel+"  , GPUINSTRUCTION_TYPE.BuiltinUnary);
 	}
 	
 	public static GPUInstruction parseSingleInstruction (String str ) 
@@ -85,7 +90,10 @@ public class GPUInstructionParser  extends InstructionParser
 		switch(gputype) {
 			case AggregateBinary:
 				return AggregateBinaryGPUInstruction.parseInstruction(str);
-				
+			
+			case BuiltinUnary:
+				return BuiltinUnaryGPUInstruction.parseInstruction(str);
+			
 			case Convolution:
 				return ConvolutionGPUInstruction.parseInstruction(str);
 				
@@ -102,4 +110,4 @@ public class GPUInstructionParser  extends InstructionParser
 				throw new DMLRuntimeException("Invalid GPU Instruction Type: " + gputype );
 		}
 	}	
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/instructions/cp/ConvolutionCPInstruction.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/cp/ConvolutionCPInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/cp/ConvolutionCPInstruction.java
index 91c74f0..5997760 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/cp/ConvolutionCPInstruction.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/cp/ConvolutionCPInstruction.java
@@ -44,6 +44,18 @@ public class ConvolutionCPInstruction extends UnaryCPInstruction {
 	private ArrayList<CPOperand> _padding = new ArrayList<CPOperand>();
 	private boolean _reuseNonZeroedOutput = false;
 	private int _numThreads = -1;
+	
+	public ConvolutionCPInstruction(CPOperand in, CPOperand in2, CPOperand out, String opcode, String istr, int numThreads) throws DMLRuntimeException {
+		super(new ReorgOperator(SwapIndex.getSwapIndexFnObject()), in, out,
+				opcode, istr);
+		if(!opcode.equals("bias_add")) {
+			throw new DMLRuntimeException("Incorrect usage. Expected the opcode to be bias_add, but found " + opcode);
+		}
+		_in2 = in2;
+		_cptype = CPINSTRUCTION_TYPE.Convolution;
+		_numThreads = numThreads;
+	}
+	
 	public ConvolutionCPInstruction(CPOperand in, CPOperand out, String opcode,
 			String istr, ArrayList<CPOperand> stride,
 			ArrayList<CPOperand> padding, ArrayList<CPOperand> input_shape,
@@ -143,6 +155,15 @@ public class ConvolutionCPInstruction extends UnaryCPInstruction {
 			return new ConvolutionCPInstruction(in, in2, out, opcode, str, stride,
 					padding, input_shape, filter_shape, k);
 		} 
+		else if (opcode.equalsIgnoreCase("bias_add")) {
+			InstructionUtils.checkNumFields(parts, 4);
+			in.split(parts[1]);
+			CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
+			in2.split(parts[2]);
+			out.split(parts[3]);
+			int k = Integer.parseInt(parts[4]);
+			return new ConvolutionCPInstruction(in, in2, out, opcode, str, k);
+		}
 		else {
 			throw new DMLRuntimeException("Unknown opcode while parsing a ConvolutionCPInstruction: " + str);
 		}
@@ -155,9 +176,43 @@ public class ConvolutionCPInstruction extends UnaryCPInstruction {
 				.getLongValue();
 	}
 	
+	public void processBiasInstruction(ExecutionContext ec) throws DMLRuntimeException {
+		MatrixBlock outputBlock = null;
+		MatrixBlock input = ec.getMatrixInput(input1.getName());
+		MatrixBlock bias = ec.getMatrixInput(_in2.getName());
+		
+		if(bias.getNumColumns() != 1) {
+			throw new DMLRuntimeException("Expected the number of columns of bias matrix to be 1, but found " + bias.getNumColumns());
+		}
+		
+		if(input.isEmptyBlock() && bias.isEmptyBlock()) {
+			outputBlock = new MatrixBlock(input.getNumRows(), input.getNumColumns(), true, 0);
+		}
+		else if(bias.isEmptyBlock()) {
+			outputBlock = new MatrixBlock(input.getNumRows(), input.getNumColumns(), input.isInSparseFormat());
+			outputBlock.copy(input);
+		}
+		else {
+			// As we always fill the output first with bias
+			outputBlock = getDenseOutputBlock(ec, input.getNumRows(), input.getNumColumns(), true);
+			LibMatrixDNN.bias_add(input, bias, outputBlock, _numThreads);
+		}
+		
+		// release inputs/outputs
+		ec.releaseMatrixInput(input1.getName());
+		ec.releaseMatrixInput(_in2.getName());
+		ec.setMatrixOutput(getOutputVariableName(), outputBlock);
+	}
+	
+	
 	@Override
 	public void processInstruction(ExecutionContext ec)
 			throws DMLRuntimeException {
+		if (instOpcode.equalsIgnoreCase("bias_add")) {
+			processBiasInstruction(ec);
+			return;
+		}
+		
 		// acquire inputs
 		MatrixBlock outputBlock = null;
 		MatrixBlock matBlock = ec.getMatrixInput(input1.getName());
@@ -186,7 +241,7 @@ public class ConvolutionCPInstruction extends UnaryCPInstruction {
 			else {
 				// Is eligible for REUSE_NONZEROED_OUTPUT but cannot guarantee that previous output has been rmvar-ed
 				// without somewhat expensive HashMap checks
-				outputBlock = getDenseOutputBlock(ec, N, C*P*Q, true);
+				outputBlock = getDenseOutputBlock(ec, N, C*P*Q, false);
 				params.setReuseNonZeroedOutput(_reuseNonZeroedOutput);
 				LibMatrixDNN.maxpooling(matBlock, outputBlock, params);
 			}

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/instructions/gpu/BuiltinUnaryGPUInstruction.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/gpu/BuiltinUnaryGPUInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/gpu/BuiltinUnaryGPUInstruction.java
new file mode 100644
index 0000000..491bf96
--- /dev/null
+++ b/src/main/java/org/apache/sysml/runtime/instructions/gpu/BuiltinUnaryGPUInstruction.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.sysml.runtime.instructions.gpu;
+
+import org.apache.sysml.parser.Expression.DataType;
+import org.apache.sysml.parser.Expression.ValueType;
+import org.apache.sysml.runtime.DMLRuntimeException;
+import org.apache.sysml.runtime.functionobjects.Builtin;
+import org.apache.sysml.runtime.functionobjects.ValueFunction;
+import org.apache.sysml.runtime.instructions.InstructionUtils;
+import org.apache.sysml.runtime.instructions.cp.CPOperand;
+import org.apache.sysml.runtime.matrix.operators.Operator;
+import org.apache.sysml.runtime.matrix.operators.UnaryOperator;
+
+public abstract class BuiltinUnaryGPUInstruction  extends GPUInstruction {
+
+
+	int _arity;
+	CPOperand _input;
+    CPOperand _output;
+	
+	public BuiltinUnaryGPUInstruction(Operator op, CPOperand in, CPOperand out, int _arity, String opcode, String istr )
+	{
+		super(op, opcode, istr);
+		_gputype = GPUINSTRUCTION_TYPE.BuiltinUnary;
+		_arity = _arity;
+		_input = in;
+        _output = out;
+	}
+
+	public int getArity() {
+		return _arity;
+	}
+	
+	public static BuiltinUnaryGPUInstruction parseInstruction ( String str ) 
+		throws DMLRuntimeException 
+	{
+		CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
+		CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
+		
+		String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
+		String opcode = null;
+		ValueFunction func = null;
+		
+		//print or stop or cumulative aggregates
+		if( parts.length==4 ) 
+		{
+			opcode = parts[0];
+			in.split(parts[1]);
+			out.split(parts[2]);
+			func = Builtin.getBuiltinFnObject(opcode);
+			
+			throw new DMLRuntimeException("The instruction is not supported on GPU:" + str);
+//			if( Arrays.asList(new String[]{"ucumk+","ucum*","ucummin","ucummax"}).contains(opcode) )
+//				return new MatrixBuiltinCPInstruction(new UnaryOperator(func,Integer.parseInt(parts[3])), in, out, opcode, str); 
+//			else
+//				return new ScalarBuiltinCPInstruction(new SimpleOperator(func), in, out, opcode, str);
+		}
+		else //2+1, general case
+		{
+			InstructionUtils.checkNumFields(str, 2);
+			opcode = parts[0];
+			in.split(parts[1]);
+			out.split(parts[2]);
+			func = Builtin.getBuiltinFnObject(opcode);
+			
+			if(in.getDataType() == DataType.SCALAR)
+				throw new DMLRuntimeException("The instruction is not supported on GPU:" + str);
+//				return new ScalarBuiltinCPInstruction(new SimpleOperator(func), in, out, opcode, str);
+			else if(in.getDataType() == DataType.MATRIX)
+				return new MatrixBuiltinGPUInstruction(new UnaryOperator(func), in, out, opcode, str);
+		}
+		
+		return null;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/instructions/gpu/ConvolutionGPUInstruction.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/gpu/ConvolutionGPUInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/gpu/ConvolutionGPUInstruction.java
index 2ac3c9a..1a5f3de 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/gpu/ConvolutionGPUInstruction.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/gpu/ConvolutionGPUInstruction.java
@@ -23,12 +23,9 @@ import java.util.ArrayList;
 import org.apache.sysml.runtime.DMLRuntimeException;
 import org.apache.sysml.runtime.controlprogram.caching.MatrixObject;
 import org.apache.sysml.runtime.controlprogram.context.ExecutionContext;
-import org.apache.sysml.runtime.controlprogram.parfor.stat.InfrastructureAnalyzer;
 import org.apache.sysml.runtime.functionobjects.SwapIndex;
-import org.apache.sysml.runtime.instructions.Instruction;
 import org.apache.sysml.runtime.instructions.InstructionUtils;
 import org.apache.sysml.runtime.instructions.cp.CPOperand;
-import org.apache.sysml.runtime.instructions.cp.ConvolutionCPInstruction;
 import org.apache.sysml.runtime.matrix.data.LibMatrixCUDA;
 import org.apache.sysml.runtime.matrix.operators.ReorgOperator;
 import org.apache.sysml.runtime.util.ConvolutionUtils;
@@ -44,6 +41,17 @@ public class ConvolutionGPUInstruction extends GPUInstruction
 	private ArrayList<CPOperand> _stride = new ArrayList<CPOperand>();
 	private ArrayList<CPOperand> _padding = new ArrayList<CPOperand>();
 	
+	public ConvolutionGPUInstruction(CPOperand in1, CPOperand in2, CPOperand out, String opcode, String istr) throws DMLRuntimeException {
+		super(new ReorgOperator(SwapIndex.getSwapIndexFnObject()), opcode, istr);
+		if(!opcode.equals("bias_add")) {
+			throw new DMLRuntimeException("Incorrect usage. Expected the opcode to be bias_add, but found " + opcode);
+		}
+		_input1 = in1;
+		_input2 = in2;
+		_gputype = GPUINSTRUCTION_TYPE.Convolution;
+		_output = out;
+	}
+	
 	public ConvolutionGPUInstruction(CPOperand in1, CPOperand in2, CPOperand out, String opcode,
 			String istr, ArrayList<CPOperand> stride,
 			ArrayList<CPOperand> padding, ArrayList<CPOperand> input_shape,
@@ -121,32 +129,39 @@ public class ConvolutionGPUInstruction extends GPUInstruction
 			return new ConvolutionGPUInstruction(in1, null, out, opcode, str, stride,
 					padding, input_shape, filter_shape);
 		}
+		else if( opcode.equalsIgnoreCase("bias_add") ) {
+			InstructionUtils.checkNumFields(parts, 3);
+			CPOperand in1 = new CPOperand(parts[1]);
+			CPOperand in2 = new CPOperand(parts[2]);
+			CPOperand out = new CPOperand(parts[3]);
+			return new ConvolutionGPUInstruction(in1, in2, out, opcode, str);
+		}
 		else {
 			throw new DMLRuntimeException("Unknown opcode while parsing a ConvolutionGPUInstruction: " + str);	
 		}
 	}
 	
-	private boolean isSparse(ExecutionContext ec, String var) throws DMLRuntimeException {
-		MatrixObject mo = ec.getMatrixObject(var);
-		return LibMatrixCUDA.isInSparseFormat(mo);
+	public void processBiasInstruction(ExecutionContext ec) throws DMLRuntimeException {
+		Statistics.incrementNoOfExecutedGPUInst();
+		MatrixObject input = ec.getMatrixInputForGPUInstruction(_input1.getName());
+		MatrixObject bias = ec.getMatrixInputForGPUInstruction(_input2.getName());
+		
+		MatrixObject out = ec.getDenseMatrixOutputForGPUInstruction(_output.getName());
+		ec.setMetaData(_output.getName(), input.getNumRows(), input.getNumColumns());
+		LibMatrixCUDA.bias_add(input, bias, out);
+		// release inputs/outputs
+		ec.releaseMatrixInputForGPUInstruction(_input1.getName());
+		ec.releaseMatrixInputForGPUInstruction(_input2.getName());
+		ec.releaseMatrixOutputForGPUInstruction(_output.getName());
 	}
 	
 	@Override
 	public void processInstruction(ExecutionContext ec) 
 			throws DMLRuntimeException 
 	{
-		// TODO: Fix Me. Currently calling CP if data is sparse
-		if (instOpcode.equalsIgnoreCase("maxpooling")) {
-			if(	isSparse(ec, _input1.getName())) {
-				ConvolutionCPInstruction.parseInstruction(this.toString() + Instruction.OPERAND_DELIM + InfrastructureAnalyzer.getLocalParallelism()).processInstruction(ec);
-				return;
-			}
-		}
-		else {
-			if(	isSparse(ec, _input1.getName()) || isSparse(ec, _input2.getName())) {
-				ConvolutionCPInstruction.parseInstruction(this.toString() + Instruction.OPERAND_DELIM + InfrastructureAnalyzer.getLocalParallelism()).processInstruction(ec);
-				return;
-			}
+		if (instOpcode.equalsIgnoreCase("bias_add")) {
+			processBiasInstruction(ec);
+			return;
 		}
 		
 		Statistics.incrementNoOfExecutedGPUInst();
@@ -266,4 +281,4 @@ public class ConvolutionGPUInstruction extends GPUInstruction
 				aL.get(index).getValueType(), aL.get(index).isLiteral())
 				.getLongValue();
 	}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/instructions/gpu/GPUInstruction.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/gpu/GPUInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/gpu/GPUInstruction.java
index b2f2eb2..27a12fd 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/gpu/GPUInstruction.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/gpu/GPUInstruction.java
@@ -28,7 +28,7 @@ import org.apache.sysml.runtime.matrix.operators.Operator;
 
 public abstract class GPUInstruction extends Instruction 
 {
-	public enum GPUINSTRUCTION_TYPE { AggregateBinary, Convolution, MMTSJ, Reorg, ArithmeticBinary }; 
+	public enum GPUINSTRUCTION_TYPE { AggregateBinary, Convolution, MMTSJ, Reorg, ArithmeticBinary, BuiltinUnary }; 
 	
 	protected GPUINSTRUCTION_TYPE _gputype;
 	protected Operator _optr;

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/instructions/gpu/MatrixBuiltinGPUInstruction.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/gpu/MatrixBuiltinGPUInstruction.java b/src/main/java/org/apache/sysml/runtime/instructions/gpu/MatrixBuiltinGPUInstruction.java
new file mode 100644
index 0000000..527ea55
--- /dev/null
+++ b/src/main/java/org/apache/sysml/runtime/instructions/gpu/MatrixBuiltinGPUInstruction.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysml.runtime.instructions.gpu;
+
+import org.apache.sysml.runtime.DMLRuntimeException;
+import org.apache.sysml.runtime.controlprogram.caching.MatrixObject;
+import org.apache.sysml.runtime.controlprogram.context.ExecutionContext;
+import org.apache.sysml.runtime.instructions.gpu.BuiltinUnaryGPUInstruction;
+import org.apache.sysml.runtime.instructions.cp.CPOperand;
+import org.apache.sysml.runtime.matrix.data.LibMatrixCUDA;
+import org.apache.sysml.runtime.matrix.operators.Operator;
+import org.apache.sysml.utils.Statistics;
+
+public class MatrixBuiltinGPUInstruction extends BuiltinUnaryGPUInstruction {
+	
+	public MatrixBuiltinGPUInstruction(Operator op, CPOperand in, CPOperand out, String opcode, String instr){
+		super(op, in, out, 1, opcode, instr);
+		_gputype = GPUINSTRUCTION_TYPE.BuiltinUnary;
+	}
+
+	@Override
+	public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
+		Statistics.incrementNoOfExecutedGPUInst();
+		
+		String opcode = getOpcode();
+		//get input
+        MatrixObject mat = ec.getMatrixInputForGPUInstruction(_input.getName());
+		if(opcode.equals("sel+")) {
+			ec.setMetaData(_output.getName(), mat.getNumRows(), mat.getNumColumns());
+			LibMatrixCUDA.relu(ec, mat, _output.getName());
+			ec.releaseMatrixInputForGPUInstruction(_input.getName());
+			ec.releaseMatrixOutputForGPUInstruction(_output.getName());
+		}
+		else {
+			throw new DMLRuntimeException("Unsupported GPU operator:" + opcode);
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/ExecutionConfig.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/ExecutionConfig.java b/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/ExecutionConfig.java
index 596d837..e33e1b0 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/ExecutionConfig.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/ExecutionConfig.java
@@ -19,8 +19,12 @@
 
 package org.apache.sysml.runtime.instructions.gpu.context;
 
+import java.util.HashMap;
+
 import org.apache.sysml.runtime.DMLRuntimeException;
 
+import jcuda.driver.CUdevice;
+import jcuda.driver.CUdevice_attribute;
 import jcuda.driver.CUstream;
 
 /**
@@ -36,8 +40,7 @@ public class ExecutionConfig {
 	public int sharedMemBytes = 0;
 	public CUstream stream = null;
 	
-//	private static HashMap<Integer, Integer> maxBlockDimXForDevice = new HashMap<Integer, Integer>();
-//	private static HashMap<Integer, Integer> maxBlockDimYForDevice = new HashMap<Integer, Integer>();
+	private static HashMap<Integer, Integer> maxBlockDimForDevice = new HashMap<Integer, Integer>();
 	
 	/**
 	 * Use this for simple vector operations and use following in the kernel 
@@ -53,7 +56,7 @@ public class ExecutionConfig {
 	 */
 	public static ExecutionConfig getConfigForSimpleVectorOperations(int numCells) throws DMLRuntimeException {
 		int deviceNumber = 0;
-		int blockDimX = getMaxBlockDimX(deviceNumber);
+		int blockDimX = getMaxBlockDim(deviceNumber);
 		int gridDimX = (int)Math.ceil((double)numCells / blockDimX);
 		return new ExecutionConfig(gridDimX, blockDimX);
 	}
@@ -73,9 +76,10 @@ public class ExecutionConfig {
 	 */
 	public static ExecutionConfig getConfigForSimpleMatrixOperations(int rlen, int clen) throws DMLRuntimeException {
 		int deviceNumber = 0;
-		int blockDimX = (int) Math.min(getMaxBlockDimX(deviceNumber), rlen);
+		int maxBlockDim = getMaxBlockDim(deviceNumber);
+		int blockDimX = (int) Math.min(maxBlockDim, rlen);
 		int gridDimX = (int)Math.ceil((double)rlen / blockDimX);
-		int blockDimY = (int)Math.min(getMaxBlockDimY(deviceNumber), clen);
+		int blockDimY = (int)Math.min(Math.ceil(((double)maxBlockDim)/blockDimX), clen);
 		int gridDimY = (int)Math.ceil((double)clen / blockDimY);
 		return new ExecutionConfig(gridDimX, gridDimY, blockDimX, blockDimY);
 	}
@@ -99,39 +103,19 @@ public class ExecutionConfig {
      * @return The maximum block dimension, in x-direction
 	 * @throws DMLRuntimeException 
      */
-    private static int getMaxBlockDimX(int deviceNumber) throws DMLRuntimeException {
-    	return 32;
+    private static int getMaxBlockDim(int deviceNumber) throws DMLRuntimeException {
+//    	return 32;
     	// TODO: Use JCudaDriver.cuOccupancyMaxPotentialBlockSize to chose the block size that maximizes occupancy
-//    	Integer ret = maxBlockDimXForDevice.get(deviceNumber);
-//    	if(ret == null) {
-//    		CUdevice device = new CUdevice();
-//            JCudaKernels.checkResult(cuDeviceGet(device, deviceNumber));
-//            int maxBlockDimX[] =  {0};
-//            cuDeviceGetAttribute(maxBlockDimX, CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X, device);
-//            maxBlockDimXForDevice.put(deviceNumber, maxBlockDimX[0]);
-//            return maxBlockDimX[0];
-//    	}
-//        return ret;
+    	Integer ret = maxBlockDimForDevice.get(deviceNumber);
+    	if(ret == null) {
+    		CUdevice device = new CUdevice();
+            JCudaKernels.checkResult(jcuda.driver.JCudaDriver.cuDeviceGet(device, deviceNumber));
+            int maxBlockDimX[] =  {0};
+            jcuda.driver.JCudaDriver.cuDeviceGetAttribute(maxBlockDimX, CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X, device);
+            maxBlockDimForDevice.put(deviceNumber, maxBlockDimX[0]);
+            return maxBlockDimX[0];
+    	}
+        return ret;
     }
     
-    /**
-     * Get the CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y of the given device
-     * 
-     * @return The maximum block dimension, in y-direction
-	 * @throws DMLRuntimeException 
-     */
-    private static int getMaxBlockDimY(int deviceNumber) throws DMLRuntimeException {
-    	return 32;
-    	// TODO: Use JCudaDriver.cuOccupancyMaxPotentialBlockSize to chose the block size that maximizes occupancy
-//    	Integer ret = maxBlockDimYForDevice.get(deviceNumber);
-//    	if(ret == null) {
-//    		CUdevice device = new CUdevice();
-//            JCudaKernels.checkResult(cuDeviceGet(device, deviceNumber));
-//            int maxBlockDimY[] =  {0};
-//            cuDeviceGetAttribute(maxBlockDimY, CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y, device);
-//            maxBlockDimYForDevice.put(deviceNumber, maxBlockDimY[0]);
-//            return maxBlockDimY[0];
-//    	}
-//        return ret;
     }
-}

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/f2344ff6/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/GPUObject.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/GPUObject.java b/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/GPUObject.java
index 850e116..91bd3ea 100644
--- a/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/GPUObject.java
+++ b/src/main/java/org/apache/sysml/runtime/instructions/gpu/context/GPUObject.java
@@ -41,7 +41,6 @@ public abstract class GPUObject
 	AtomicLong timestamp = new AtomicLong(0);
 	
 	protected boolean isInSparseFormat = false;
-	public boolean isAllocated = false;
 	protected MatrixObject mat = null;
 	
 	protected GPUObject(MatrixObject mat2)  {
@@ -52,9 +51,7 @@ public abstract class GPUObject
 		return isInSparseFormat;
 	}
 	
-	public boolean isAllocated() {
-		return isAllocated;
-	}
+	public abstract boolean isAllocated();
 	
 	public abstract void acquireDeviceRead() throws DMLRuntimeException;
 	/**
@@ -86,7 +83,7 @@ public abstract class GPUObject
 	 * @param numElemToAllocate number of elements in dense matrix, -1 for unknown or sparse matrix
 	 * @throws DMLRuntimeException if DMLRuntimeException occurs
 	 */
-	abstract void allocateMemoryOnDevice(int numElemToAllocate) throws DMLRuntimeException;
+	abstract void allocateMemoryOnDevice(long numElemToAllocate) throws DMLRuntimeException;
 	abstract void deallocateMemoryOnDevice() throws DMLRuntimeException;
 	abstract long getSizeOnDevice() throws DMLRuntimeException;
 	
@@ -207,4 +204,4 @@ public abstract class GPUObject
 //			}
 //		}
 //	}
-}
\ No newline at end of file
+}