Example #1
0
 /// Elementwise operator /
 AutoDiffBlock operator/(const AutoDiffBlock& rhs) const
 {
     if (jac_.empty() && rhs.jac_.empty()) {
         return constant(val_ / rhs.val_);
     }
     if (jac_.empty()) {
         return val_ / rhs;
     }
     if (rhs.jac_.empty()) {
         return *this / rhs.val_;
     }
     int num_blocks = numBlocks();
     std::vector<M> jac(num_blocks);
     assert(numBlocks() == rhs.numBlocks());
     typedef Eigen::DiagonalMatrix<Scalar, Eigen::Dynamic> D;
     D D1 = val_.matrix().asDiagonal();
     D D2 = rhs.val_.matrix().asDiagonal();
     D D3 = (1.0/(rhs.val_*rhs.val_)).matrix().asDiagonal();
     for (int block = 0; block < num_blocks; ++block) {
         assert(jac_[block].rows() == rhs.jac_[block].rows());
         assert(jac_[block].cols() == rhs.jac_[block].cols());
         jac[block] = D3 * (D2*jac_[block] - D1*rhs.jac_[block]);
     }
     return function(val_ / rhs.val_, jac);
 }
Example #2
0
string AES128CTR(string in, string key, string nonce){
	string cipher=newString(NULL, in.len);
	string keystream;
	string counter=newString(NULL,8);
	int i,j,n;
	n=numBlocks(in,16);

	if (nonce.len!=8){
		nonce=newString(NULL,8);
	}

	j=0;
	for(i=0; i<n; i++){
		keystream=AES128EncodeBlock(stringCat(nonce, counter), key);
		do{
			if(j<in.len){
				cipher.c[j]=keystream.c[j%16] ^ in.c[j];
				j++;
			}
			else break;
		}while(j%16);
		littleEndianIncrement(&counter);
	}
	return cipher;
}
Example #3
0
 /// Sizes (number of columns) of Jacobian blocks.
 std::vector<int> blockPattern() const
 {
     const int nb = numBlocks();
     std::vector<int> bp(nb);
     for (int block = 0; block < nb; ++block) {
         bp[block] = jac_[block].cols();
     }
     return bp;
 }
void sobel1(int *h_result, unsigned int *h_pic, int xsize, int ysize, int thresh)
{

	
	int *d_result;
	unsigned int *d_pic;
	
	 
	int resultSize = xsize * ysize  * 3 * sizeof(int);
	int picSize = xsize * ysize * sizeof(int);

	 
	cudaMalloc( (void**)&d_result, resultSize);
	if( !d_result) {
		exit(-1);
	}
	cudaMalloc( (void**)&d_pic, picSize);
	if( !d_pic) {
		exit(-1);
	}

	 
	cudaMemcpy(d_result, h_result, resultSize, cudaMemcpyHostToDevice);
	cudaMemcpy(d_pic, h_pic, picSize, cudaMemcpyHostToDevice);
	
	 
	
	dim3 threadsPerBlock(BLOCKSIZE, BLOCKSIZE);
	dim3 numBlocks(ceil((float)ysize/(float)threadsPerBlock.x), ceil((float)xsize/(float)threadsPerBlock.y));
	
	 
	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
{	__set_CUDAConfig(numBlocks, threadsPerBlock ); 
          
	d_sobel1 (d_result, d_pic, xsize, ysize, thresh);}
          
	
	 
	cudaEventSynchronize(stop);
	float elapsedTime;
	cudaEventElapsedTime(&elapsedTime, start, stop);
	cudaEventDestroy(start);
	cudaEventDestroy(stop);

	 
	 
	cudaMemcpy(h_result, d_result, resultSize, cudaMemcpyDeviceToHost);
	cudaMemcpy(h_pic, d_pic, picSize, cudaMemcpyDeviceToHost);

	 
	cudaFree(d_result);
	cudaFree(d_pic);
	
}
Example #5
0
        /// Elementwise operator +=
        AutoDiffBlock& operator+=(const AutoDiffBlock& rhs)
        {
            if (jac_.empty()) {
                jac_ = rhs.jac_;
            } else if (!rhs.jac_.empty()) {
                assert (numBlocks()    == rhs.numBlocks());
                assert (value().size() == rhs.value().size());

                const int num_blocks = numBlocks();
                for (int block = 0; block < num_blocks; ++block) {
                    assert(jac_[block].rows() == rhs.jac_[block].rows());
                    assert(jac_[block].cols() == rhs.jac_[block].cols());
                    jac_[block] += rhs.jac_[block];
                }
            }

            val_ += rhs.val_;

            return *this;
        }
Example #6
0
 /// Elementwise operator -
 AutoDiffBlock operator-(const AutoDiffBlock& rhs) const
 {
     if (jac_.empty() && rhs.jac_.empty()) {
         return constant(val_ - rhs.val_);
     }
     if (jac_.empty()) {
         return val_ - rhs;
     }
     if (rhs.jac_.empty()) {
         return *this - rhs.val_;
     }
     std::vector<M> jac = jac_;
     assert(numBlocks() == rhs.numBlocks());
     int num_blocks = numBlocks();
     for (int block = 0; block < num_blocks; ++block) {
         assert(jac[block].rows() == rhs.jac_[block].rows());
         assert(jac[block].cols() == rhs.jac_[block].cols());
         jac[block] -= rhs.jac_[block];
     }
     return function(val_ - rhs.val_, jac);
 }
Example #7
0
string AES128DecodeCBC(string in, string key, string IV){
	if(in.len%16){
		return NULLSTRING;
	}
	string out = NULLSTRING;
	string *blocks = blockString(in, 16);
	int num = numBlocks(in, 16);
	for(int i=num-1; i>=0; i--){
		blocks[i] = AES128DecodeBlock(blocks[i],key);
		if(i==0){
			out = stringCat(stringXOR(blocks[i], IV), out);
		} else{
			out = stringCat(stringXOR(blocks[i-1], blocks[i]),out);
		}
	}
	return out;
}
Example #8
0
string AES128EncodeCBC(string in, string key, string IV){
	string out = NULLSTRING;
	if(!validatePKCS7Padding(in)){
		in = PKCS7PadString(in, 16);
	}
	string *blocks = blockString(in, 16);
	int num = numBlocks(in, 16);
	for(int i=0; i<num; i++){
		if(i==0){
			blocks[0] = stringXOR(blocks[0], IV);
		}else{
			blocks[i] = stringXOR(blocks[i], newString(&out.c[(i-1)*16],16));
		}
		out = stringCat(out, AES128EncodeBlock(blocks[i], key));
	}
	return out;
}
	void DynamicMarchingTetrahedra::update(GLContext * gl) {

		GLContext::Program * prog = gl->getProgram(m_sceneShader.c_str());
		prog->use();

		Vec3i numBlocks(64);
		Vec3i threadBlockSize(4);
		Vec3i gridSize = (numBlocks + threadBlockSize - 1) / threadBlockSize;

		gl->setUniform(prog->getUniformLoc("cubeInfo"), m_cubeInfo);
		gl->setUniform(prog->getUniformLoc("isPrefixSumPass"), true);

		gl->setUniform(prog->getUniformLoc("numCubes"), numBlocks);

		gl->setUniform(prog->getUniformLoc("sync1"), m_disp1);
		gl->setUniform(prog->getUniformLoc("sync2"), m_disp2);
		gl->setUniform(prog->getUniformLoc("sync3"), m_disp3);
		gl->setUniform(prog->getUniformLoc("sync4"), m_disp4);
		gl->setUniform(prog->getUniformLoc("maxTetrahedras"), 6);

		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_buffers[DMT_Buffer_Types::INDEX_BUFFER]);
		glDispatchCompute(gridSize.x, gridSize.y, gridSize.z);

		glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);

		GPUPrefixScan::scan(gl, m_buffers[DMT_Buffer_Types::INDEX_BUFFER], m_buffers[DMT_Buffer_Types::BLOCK_BUFFER], 100*100*100);

		prog->use();
		gl->setUniform(prog->getUniformLoc("isPrefixSumPass"), false);

		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_buffers[DMT_Buffer_Types::MESH_BUFFER]);
		
		glDispatchCompute(gridSize.x, gridSize.y, gridSize.z);

		glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);

		m_numTriangles = GPUPrefixScan::getSum(gl, m_buffers[DMT_Buffer_Types::BLOCK_BUFFER]);
	}
void
SideSetsAroundSubdomain::modify()
{
  // Reference the the libMesh::MeshBase
  MeshBase & mesh = _mesh_ptr->getMesh();

  // Extract the 'first' block ID
  SubdomainID block_id = *blockIDs().begin();

  // Extract the SubdomainID
  if (numBlocks() > 1)
     mooseWarning("SideSetsAroundSubdomain only acts on a single subdomain, but multiple were provided: only the " << block_id << "' subdomain is being used.");

  // Create the boundary IDs from the list of names provided (the true flag creates ids from unknown names)
  std::vector<BoundaryID> boundary_ids = _mesh_ptr->getBoundaryIDs(_boundary_names, true);

  // construct the FE object so we can compute normals of faces
  setup();
  Point face_normal;
  bool add_to_bdy = true;

  // Get a reference to our BoundaryInfo object for later use
  BoundaryInfo & boundary_info = mesh.get_boundary_info();

  // Loop over the elements
  MeshBase::const_element_iterator   el  = mesh.active_elements_begin();
  const MeshBase::const_element_iterator end_el = mesh.active_elements_end();
  for (; el != end_el ; ++el)
  {
    const Elem* elem = *el;
    SubdomainID curr_subdomain = elem->subdomain_id();

    // We only need to loop over elements in the source subdomain
    if (curr_subdomain != block_id)
      continue;

    for (unsigned int side = 0; side < elem->n_sides(); ++side)
    {
      const Elem * neighbor = elem->neighbor(side);
      if (neighbor == NULL ||                   // element on boundary OR
          neighbor->subdomain_id() != block_id) // neighboring element is on a different subdomain
        {
          if (_using_normal)
          {
            _fe_face->reinit(elem, side);
            face_normal = _fe_face->get_normals()[0];
            add_to_bdy = (_normal*face_normal >= 1.0 - _normal_tol);
          }


          // Add the boundaries, if appropriate
          if (add_to_bdy)
            for (const auto & boundary_id : boundary_ids)
              boundary_info.add_side(elem, side, boundary_id);
        }
    }
  }

  finalize();

  // Assign the supplied names to the newly created side sets
  for (unsigned int i = 0; i < boundary_ids.size(); ++i)
    boundary_info.sideset_name(boundary_ids[i]) = _boundary_names[i];
}
 // Number of sets.
 int numSets() const { return _comm->getSize() / numBlocks(); }