aboutsummaryrefslogtreecommitdiff
path: root/src/cuda-sim/instructions.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuda-sim/instructions.cc')
-rw-r--r--src/cuda-sim/instructions.cc431
1 files changed, 3 insertions, 428 deletions
diff --git a/src/cuda-sim/instructions.cc b/src/cuda-sim/instructions.cc
index 52d89f2..2677c40 100644
--- a/src/cuda-sim/instructions.cc
+++ b/src/cuda-sim/instructions.cc
@@ -25,7 +25,7 @@
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "half.hpp"
+#include "half.h"
#include "instructions.h"
#include "ptx_ir.h"
#include "opcodes.h"
@@ -48,7 +48,7 @@
using half_float::half;
unsigned ptx_instruction::g_num_ptx_inst_uid=0;
-bool g_debug_instruction = 1;
+bool g_debug_instruction = 0;
const char *g_opcode_string[NUM_OPCODES] = {
@@ -129,15 +129,6 @@ unsigned thread_group_offset(int thread,unsigned wmma_type,unsigned wmma_layout
}
}
break;
- case VP_MMA:
- case VP_MMA4:
- case VP_MMA8:
- case VP_MMA16:
- if(wmma_layout==ROW)
- offset=load_c_float_row[thread_group]+16*in_tg_index;
- else
- offset=load_c_float_col[thread_group]+in_tg_index;
- break;
default:
abort();
@@ -1706,11 +1697,6 @@ void mapping(int thread,int wmma_type,int wmma_layout,int type,int index,int str
}
assg_offset=index;
}
- else if(wmma_type==VP_MMA || wmma_type==VP_MMA4 || wmma_type==VP_MMA8 || wmma_type==VP_MMA16){
- row=c_row_offset[thread/4]+thread%4;
- col=c_col_offset[thread/4]+index;
- assg_offset=index;
- }
if(wmma_type==LOAD_A||wmma_type==LOAD_B){
if(wmma_layout==ROW){
@@ -1724,152 +1710,6 @@ void mapping(int thread,int wmma_type,int wmma_layout,int type,int index,int str
}
}
-void vp_mma_impl( const ptx_instruction *pI, core_t *core, warp_inst_t inst )
-{
- int i,j,k,thrd;
- int row,col,offset;
- ptx_reg_t matrix_a[16][16];
- ptx_reg_t matrix_b[16][16];
- ptx_reg_t matrix_c[16][16];
- ptx_reg_t matrix_d[16][16];
- ptx_reg_t src_data;
- ptx_thread_info *thread;
- int stride;
- unsigned wmma_type = pI->get_wmma_type();
- unsigned a_layout = pI->get_wmma_layout(0);
- unsigned b_layout = pI->get_wmma_layout(1);
- unsigned type = pI->get_type();
- int tid = inst.warp_id_func() * core->get_warp_size();
- const operand_info &dst = pI->operand_lookup(0);
-
- unsigned thread_group_index;
-
- for (thrd=0; thrd < core->get_warp_size(); thrd++){
- thread = core->get_thread_info()[tid+thrd];
- if(g_debug_instruction)
- printf("THREAD=%d\n:",thrd);
- for(i=1;i<=3;i++){
- const operand_info &src_a= pI->operand_lookup(i);
- unsigned nelem = src_a.get_vect_nelem();
- ptx_reg_t v[8];
- thread->get_vector_operand_values( src_a, v, nelem );
- if(g_debug_instruction){
- printf("Thread%d_Iteration=%d:",thrd,i);
- for(k=0;k<nelem;k++){
- printf("%x ",v[k].u64);
- }
- printf("\n");
- }
- int hex_val;
- switch(i) {
- case 1 ://operand 1
- for(k=0;k<8;k++){
- mapping(thrd,wmma_type,a_layout,S32_TYPE,k,16,row,col,offset);
- if(g_debug_instruction)
- printf("A:thread=%d,row=%d,col=%d,offset=%d\n",thrd,row,col,offset);
- matrix_a[row][col]=v[offset];
- }
- break;
- case 2 ://operand 2
- for(k=0;k<8;k++){
- mapping(thrd,wmma_type,b_layout,S32_TYPE,k,16,row,col,offset);
- if(g_debug_instruction)
- printf("B:thread=%d,row=%d,col=%d,offset=%d\n",thrd,row,col,offset);
- if(nelem==1){
- matrix_b[row][col].s32=((v[0].u32&(0xf<<4*k))>>4*k);
- }
- if(nelem==2){
- matrix_b[row][col].s32=((v[k/4].u32&(0xff<<8*(k%4)))>>8*(k%4));
- }
- if(nelem==4){
- matrix_b[row][col].s32=((v[k/2].u32&(0xffff<<16*(k%2)))>>16*(k%2));
- }
- }
- break;
- case 3 ://operand 3
- for(k=0;k<8;k++){
- mapping(thrd,wmma_type,ROW,S32_TYPE,k,16,row,col,offset);
- if(g_debug_instruction)
- printf("C:thread=%d,row=%d,col=%d,offset=%d\n",thrd,row,col,offset);
- matrix_c[row][col]=v[offset];
- }
- break;
- default :
- printf("Invalid Operand Index\n" );
- }
- }
- if(g_debug_instruction)
- printf("\n");
- }
- if(g_debug_instruction){
- printf("MATRIX_A\n");
- for (i=0;i<16;i++){
- for(j=0;j<16;j++){
- printf("%d ",matrix_a[i][j].s32);
- }
- printf("\n");
- }
- }
- printf("MATRIX_B\n");
- for (i=0;i<16;i++){
- for(j=0;j<16;j++){
- printf("%d ",matrix_b[i][j].s32);
- }
- printf("\n");
- }
- printf("MATRIX_C\n");
- for (i=0;i<16;i++){
- for(j=0;j<16;j++){
- printf("%d ",matrix_c[i][j].s32);
- }
- printf("\n");
- }
- for (i=0;i<16;i++){
- for(j=0;j<16;j++){
- matrix_d[i][j].f16=0;
- }
- }
-
- for (i=0;i<16;i++){
- for(j=0;j<16;j++){
- for(k=0;k<16;k++){
- matrix_d[i][j].s32=matrix_d[i][j].s32+matrix_a[i][k].s32*matrix_b[k][j].s32;
- }
- matrix_d[i][j].s32+=matrix_c[i][j].s32;
- }
- }
- if(g_debug_instruction){
- printf("MATRIX_D\n");
- for (i=0;i<16;i++){
- for(j=0;j<16;j++){
- printf("%d ",matrix_d[i][j].s32);
- }
- printf("\n");
- }
- }
- for (thrd=0; thrd < core->get_warp_size(); thrd++){
- int row_t[8];
- int col_t[8];
- for(k=0;k<8;k++){
- mapping(thrd,wmma_type,ROW,type,k,16,row_t[k],col_t[k],offset);
- if(g_debug_instruction)
- printf("vp_mma:row:%d,col%d\n",row_t[k],col_t[k]);
- }
- thread = core->get_thread_info()[tid+thrd];
-
-
- thread->set_wmma_vector_operand_values(dst,matrix_d[row_t[0]][col_t[0]],matrix_d[row_t[1]][col_t[1]],matrix_d[row_t[2]][col_t[2]],matrix_d[row_t[3]][col_t[3]],matrix_d[row_t[4]][col_t[4]],matrix_d[row_t[5]][col_t[5]],matrix_d[row_t[6]][col_t[6]],matrix_d[row_t[7]][col_t[7]]);
-
- if(g_debug_instruction)
- {
- printf("thread%d:",thrd);
- for(k=0;k<8;k++){
- printf("%d ",matrix_d[row_t[k]][col_t[k]].s32);
- }
- printf("\n");
- }
- }
-}
void mma_impl( const ptx_instruction *pI, core_t *core, warp_inst_t inst )
{
int i,j,k,thrd;
@@ -2387,18 +2227,10 @@ ptx_reg_t f2x( ptx_reg_t x, unsigned from_width, unsigned to_width, int to_sign,
} else {
switch ( to_width ) {
case 16:
- mytemp=half(x.f32);
- myfloat=mytemp;
- y.f16 =mytemp;
- #if 0
- printf("f2x: %f\n",myfloat);
- #endif
+ y.f16 =half_float::half_cast<half,std::numeric_limits<float>::round_style>(x.f32);//mytemp;
break;
case 32:
y.f32=float(x.f16);
- #if 0
- printf("f2xnew:%x:my%f:%f\n",x.f16,y.f32,half_float::detail::half2float<float>(x.u16));
- #endif
break; // handled by f2f
case 64:
y.f64 = x.f32;
@@ -3119,78 +2951,6 @@ void ldu_impl( const ptx_instruction *pI, ptx_thread_info *thread )
ld_exec(pI,thread);
}
-void vp_st_impl( const ptx_instruction *pI, core_t *core, warp_inst_t & inst)
-{
- size_t size;
- unsigned smid;
- int t;
- int thrd,odd,inx,k;
- ptx_thread_info *thread;
-
- const operand_info &src = pI->operand_lookup(1);
- const operand_info &src1 = pI->operand_lookup(0);
- const operand_info &src2 = pI->operand_lookup(2);
- int tid = inst.warp_id_func()*core->get_warp_size();
- unsigned type = pI->get_type();
- unsigned wmma_type = pI->get_wmma_type();
- unsigned wmma_layout = pI->get_wmma_layout(0);
- int stride;
- _memory_op_t insn_memory_op = pI->has_memory_read() ? memory_load : memory_store;
- for (thrd=0; thrd < core->get_warp_size(); thrd++) {
- thread = core->get_thread_info()[tid+thrd];
- odd=thrd%2;
- inx=thrd/2;
- ptx_reg_t addr_reg = thread->get_operand_value(src1, src, type, thread, 1);
- ptx_reg_t src2_data = thread->get_operand_value(src2, src, type, thread, 1);
- const operand_info &src_a= pI->operand_lookup(1);
- unsigned nelem = src_a.get_vect_nelem();
- ptx_reg_t* v= new ptx_reg_t[8];
- thread->get_vector_operand_values( src_a, v, nelem );
- stride=src2_data.u32;
-
- memory_space_t space = pI->get_space();
- new_addr_type mem_txn_addr[MAX_ACCESSES_PER_INSN_PER_THREAD];
- int num_mem_txn=0;
-
- memory_space *mem = NULL;
- addr_t addr = addr_reg.u32;
-
- smid = thread->get_hw_sid();
- if( whichspace(addr) == shared_space ) {
- addr= generic_to_shared(smid,addr);
- space = shared_space;
- }
- decode_space(space,thread,src1,mem,addr);
-
- type_info_key::type_decode(type,size,t);
- if(g_debug_instruction)
- printf("vp_st: thrd=%d,addr=%x, fp(size=%d), stride=%d\n",thrd,addr_reg.u32,size,src2_data.u32);
- addr_t new_addr = addr+thread_group_offset(thrd,VP_MMA,wmma_layout,type,stride)*size/8;
-
- if(g_debug_instruction){
- printf("vp_st:thread%d=%d,%d,%d,%d,%d,%d,%d,%d\n",thrd,v[0].s32,v[1].s32,v[2].s32,v[3].s32,v[4].s32,v[5].s32,v[6].s32,v[7].s32);
- }
-
- for(k=0;k<8;k++){
- if(wmma_layout==ROW){
- mem->write(new_addr+4*k,size/8,&v[k].s64,thread,pI);
- mem_txn_addr[num_mem_txn++]=new_addr+4*k;
- }
- else if(wmma_layout==COL){
- mem->write(new_addr+k*4*stride,size/8,&v[k].s64,thread,pI);
- mem_txn_addr[num_mem_txn++]=new_addr+4*k*stride;
- }
- }
-
- delete [] v;
- inst.space = space;
- inst.set_addr(thrd, (new_addr_type *)mem_txn_addr , num_mem_txn);
- inst.data_size = 4; // 4 byte transaction
- assert( inst.memory_op == insn_memory_op );
-// thread->m_last_effective_address = addr;
-// thread->m_last_memory_space = space;
- }
-}
void mma_st_impl( const ptx_instruction *pI, core_t *core, warp_inst_t &inst )
{
size_t size;
@@ -3296,191 +3056,6 @@ void mma_st_impl( const ptx_instruction *pI, core_t *core, warp_inst_t &inst )
//thread->m_last_memory_space = space;
}
}
-void vp_ld_impl(const ptx_instruction *pI, core_t *core, warp_inst_t &inst)
-{
- size_t size;
- int t,i;
- unsigned smid;
- const operand_info &dst = pI->dst();
- const operand_info &src1 = pI->src1();
- const operand_info &src2 = pI->src2();
- unsigned type = pI->get_type();
- unsigned wmma_type = pI->get_wmma_type();
- unsigned wmma_layout = pI->get_wmma_layout(0);
- int tid = inst.warp_id_func()*core->get_warp_size();
- int thrd,stride;
- ptx_thread_info *thread;
- _memory_op_t insn_memory_op = pI->has_memory_read() ? memory_load : memory_store;
- for (thrd=0; thrd < core->get_warp_size(); thrd++){
- thread = core->get_thread_info()[tid+thrd];
- ptx_reg_t src1_data = thread->get_operand_value(src1, dst, U32_TYPE, thread, 1);
- ptx_reg_t src2_data = thread->get_operand_value(src2, dst, U32_TYPE, thread, 1);
- stride=src2_data.u32;
- memory_space_t space = pI->get_space();
-
- new_addr_type mem_txn_addr[MAX_ACCESSES_PER_INSN_PER_THREAD];
- int num_mem_txn=0;
-
- memory_space *mem = NULL;
- addr_t addr = src1_data.u32;
-
- smid = thread->get_hw_sid();
- if( whichspace(addr) == shared_space ) {
- addr= generic_to_shared(smid,addr);
- space = shared_space;
- }
-
- decode_space(space,thread,src1,mem,addr);
- type_info_key::type_decode(type,size,t);
-
- ptx_reg_t data[8];
- addr_t new_addr;
-
- //note we are using distribution of VP_MMA for every type of load!
- if(wmma_type==LOAD_A||wmma_type==LOAD_C){
- new_addr = addr+thread_group_offset(thrd,VP_MMA,wmma_layout,type,stride)*size/8;
- }
- else if(wmma_type==LOAD_B4){
- new_addr = addr+thread_group_offset(thrd,VP_MMA,wmma_layout,type,stride)/2;
- }
- else if (wmma_type==LOAD_B8){
- new_addr = addr+thread_group_offset(thrd,VP_MMA,wmma_layout,type,stride);
- }
- else if (wmma_type==LOAD_B16){
- new_addr = addr+thread_group_offset(thrd,VP_MMA,wmma_layout,type,stride)*2;
- }
-
- if(g_debug_instruction)
- printf("vp_ld: thrx=%d,addr=%x, base_addr=%x, size=%d, stride=%d\n",thrd,new_addr,addr,size,src2_data.u32);
-
- if(wmma_type==LOAD_A||wmma_type==LOAD_C){
- printf("lda/c:");
- for(i=0;i<8;i++){
- if(wmma_layout==ROW){
- //mem->read(new_addr+4*i,size/8,&data[i].s64);
- mem->read(new_addr+4*i,size/8,&data[i].s64);
- printf("%x ", new_addr+4*i);
- mem_txn_addr[num_mem_txn++]=new_addr+4*i;
- }
- else if(wmma_layout==COL){
- //mem->read(new_addr+4*stride*i,size/8,&data[i].s64);
- printf("%x ", new_addr+4*stride*i);
- mem->read(new_addr+4*stride*i,size/8,&data[i].s64);
- mem_txn_addr[num_mem_txn++]=new_addr+4*stride*i;
- }
- }
-
- }
-
- else if(wmma_type==LOAD_B4){
- printf("ldb4:");
- if(wmma_layout==ROW){
- mem->read(new_addr,size/8,&data[0].s64);
- printf("%x ",new_addr);
- mem_txn_addr[num_mem_txn++]=new_addr;
- }
- else if(wmma_layout==COL){
- }
- }
- else if(wmma_type==LOAD_B8){
- printf("ldb8:");
- if(wmma_layout==ROW){
- mem->read(new_addr,size/8,&data[0].s64);
- mem->read(new_addr+4,size/8,&data[1].s64);
- printf("%x ",new_addr,new_addr+4);
-
- mem_txn_addr[num_mem_txn++]=new_addr;
- mem_txn_addr[num_mem_txn++]=new_addr+4;
- }
- else if(wmma_layout==COL){
-
- }
- }
- else if(wmma_type==LOAD_B16){
- printf("ldb16:");
- if(wmma_layout==ROW){
- mem->read(new_addr,size/8,&data[0].s64);
- mem->read(new_addr+4,size/8,&data[1].s64);
- mem->read(new_addr+8,size/8,&data[2].s64);
- mem->read(new_addr+12,size/8,&data[3].s64);
- printf("%x ",new_addr,new_addr+4,new_addr+8,new_addr+12);
- mem_txn_addr[num_mem_txn++]=new_addr;
- mem_txn_addr[num_mem_txn++]=new_addr+4;
- mem_txn_addr[num_mem_txn++]=new_addr+8;
- mem_txn_addr[num_mem_txn++]=new_addr+12;
- }
- else if(wmma_layout==COL){
- }
- }
- else{
- printf("wrong vp_load type\n");;
- abort();
- }
- printf("\n");
-
- //generate timing memory request
- inst.space = space;
- inst.set_addr(thrd, (new_addr_type *)mem_txn_addr , num_mem_txn);
- inst.data_size = 4; // 4 byte transaction
- assert( inst.memory_op == insn_memory_op );
- printf("\nVPLOAD_THREAD%d:",thrd);
- for(int lll=0;lll<num_mem_txn;lll++)
- {
- printf("%x ",mem_txn_addr[lll]);
- }
- printf("\n");
-
- int num_reg;
- if(g_debug_instruction){
- printf("\nvp_ld:thread%d= ",thrd);
- if((wmma_type==LOAD_A)||(wmma_type==LOAD_C)){
- num_reg=8;
- }
- else if(wmma_type==LOAD_B4){
- num_reg=1;
- }
- else if(wmma_type==LOAD_B8){
- num_reg=2;
- }
- else if(wmma_type==LOAD_B16){
- num_reg=4;
- }
- for(i=0;i<num_reg;i++){
- printf("%x ",data[i].s32);
- }
- printf("\n");
- }
-
- if((wmma_type==LOAD_A)||(wmma_type==LOAD_C)){
- thread->set_wmma_vector_operand_values(dst,data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7]);
- }
- else if(wmma_type==LOAD_B4){
- thread->set_vector_operand_values(dst,data[0],data[0],data[0],data[0]);
- }
- else if(wmma_type==LOAD_B8){
- thread->set_vector_operand_values(dst,data[0],data[1],data[1],data[1]);
- }
- else if (wmma_type==LOAD_B16){
- thread->set_vector_operand_values(dst,data[0],data[1],data[2],data[3]);
- }
- else
- abort();
-
-
-
- if(g_debug_instruction){
- for(int i=0;i<num_reg;i++)
- printf("vp_ld:data[%i].s64=%x\n",i,data[i].u64);
- }
-
-
- //thread->m_last_effective_address = addr;
- //thread->m_last_memory_space = space;
- }
-
-
-
-}
void mma_ld_impl( const ptx_instruction *pI, core_t *core, warp_inst_t &inst )
{