public void Batch_In_GPU() { sample_Idx.CopyIntoCuda(); seg_Idx.CopyIntoCuda(); seg_Margin.CopyIntoCuda(); seg_Len.CopyIntoCuda(); fea_Idx.CopyIntoCuda(); fea_Value.CopyIntoCuda(); }
unsafe public void Negative_Sampling_Transpose(int batchsize) { List <List <int> > mlist = new List <List <int> >(); for (int k = 0; k < batchsize; k++) { mlist.Add(new List <int>()); } for (int i = 0; i < ParameterSetting.NTRIAL; i++) { for (int k = 0; k < batchsize; k++) { mlist[k].Clear(); } for (int k = 0; k < batchsize; k++) { int bs = GPU_negative_index_Array.MemPtr[i * ParameterSetting.BATCH_SIZE + k]; // ].MemPtr[k]; mlist[bs].Add(k); } int ptotal = 0; int pindex = 0; for (int k = 0; k < batchsize; k++) { for (int m = 0; m < mlist[k].Count; m++) { GPU_Inver_negative_value_Array.MemPtr[i * ParameterSetting.BATCH_SIZE + pindex] = mlist[k][m]; // i].MemPtr[pindex] = mlist[k][m]; pindex++; } GPU_Inver_negative_index_Array.MemPtr[i * ParameterSetting.BATCH_SIZE + k] = ptotal + mlist[k].Count; ptotal = GPU_Inver_negative_index_Array.MemPtr[i * ParameterSetting.BATCH_SIZE + k]; } } GPU_Inver_negative_index_Array.CopyIntoCuda(); GPU_Inver_negative_value_Array.CopyIntoCuda(); }
unsafe public void Negative_Sampling(int batchSize) { for (int i = 0; i < ParameterSetting.NTRIAL; i++) { if (LearningParameters.neg_static_sample) { //int randpos = neg_random.Next((int)(0.33f * batchSize)) + (int)(0.1 * batchSize); int k1 = (int)(0.33f * batchSize); int k2 = (int)(0.67f * batchSize); int k3 = (int)(0.53f * batchSize); int k4 = (int)(0.73f * batchSize); if (k1 % batchSize == 0) { k1 = k1 + 1; } if (k2 % batchSize == 0) { k2 = k2 + 1; } if (k3 % batchSize == 0) { k3 = k3 + 1; } if (k4 % batchSize == 0) { k4 = k4 + 1; } for (int k = 0; k < batchSize; k++) { if (i == 0) { GPU_negative_index_Array.MemPtr[i * ParameterSetting.BATCH_SIZE + k] = (k1 + k) % batchSize; } else if (i == 1) { GPU_negative_index_Array.MemPtr[i * ParameterSetting.BATCH_SIZE + k] = (k2 + k) % batchSize; } else if (i == 2) { GPU_negative_index_Array.MemPtr[i * ParameterSetting.BATCH_SIZE + k] = (k3 + k) % batchSize; } else if (i == 3) { GPU_negative_index_Array.MemPtr[i * ParameterSetting.BATCH_SIZE + k] = (k4 + k) % batchSize; } } } else { int randpos = neg_random.Next((int)(0.8 * batchSize)) + (int)(0.1 * batchSize); for (int k = 0; k < batchSize; k++) { int bs = (randpos + k) % batchSize; GPU_negative_index_Array.MemPtr[i * ParameterSetting.BATCH_SIZE + k] = bs; } } } GPU_negative_index_Array.CopyIntoCuda(); }