void heston_kernel_ml(const params_ml params, hls::stream<calc_t> &gaussian_rn1,
		hls::stream<calc_t> &gaussian_rn2, hls::stream<calc_t> &prices) {
	#pragma HLS interface ap_none port=params
	#pragma HLS resource core=AXI4LiteS metadata="-bus_bundle params" \
			variable=params
	#pragma HLS interface ap_fifo port=gaussian_rn1
	#pragma HLS resource core=AXI4Stream variable=gaussian_rn1
	#pragma HLS interface ap_fifo port=gaussian_rn2
	#pragma HLS resource core=AXI4Stream variable=gaussian_rn2
	#pragma HLS interface ap_fifo port=prices
	#pragma HLS resource core=AXI4Stream variable=prices
	#pragma HLS resource core=AXI4LiteS metadata="-bus_bundle params" \
			variable=return

	// write block size to stream
	prices.write(BLOCK_SIZE);

	state_t state_coarse[BLOCK_SIZE];
	#pragma HLS data_pack variable=state_coarse
	state_t state_fine[BLOCK_SIZE];
	#pragma HLS data_pack variable=state_fine
	w_both_t w_both[BLOCK_SIZE];
	#pragma HLS data_pack variable=w_both

	ap_uint<6> upper_j = params.ml_constant + (params.do_multilevel ? 1 : 0);

	for (uint32_t path = 0; path < params.path_cnt; path += BLOCK_SIZE) {
		for (uint32_t step = 0; step != params.step_cnt_coarse; ++step) {
			for (ap_uint<6> j = 0; j != upper_j; ++j) {
				for (ap_uint<10> block_i = 0; block_i != BLOCK_SIZE;
						++block_i) {
					#pragma HLS PIPELINE II=1

					bool is_fine = j != params.ml_constant;

					//
					// initialize
					//
					state_t l_state_coarse, l_state_fine;
					w_both_t l_w_both;
					if (step == 0 && j == 0) {
						l_state_coarse = get_init_state(params);
						l_state_fine = get_init_state(params);
						l_w_both = get_w_zero();
					} else {
						l_state_coarse = state_coarse[block_i];
						l_state_fine = state_fine[block_i];
						l_w_both = w_both[block_i];
					}

					//
					// calculate next step
					//
					state_t n_state_coarse, n_state_fine;
					w_both_t n_w_both;

					if (is_fine) {
						// step fine
						float w_stock = gaussian_rn1.read();
						float w_vola = gaussian_rn2.read();
						n_state_fine = get_next_step(params, l_state_fine,
								w_stock, w_vola, true);
						n_state_coarse = l_state_coarse;
						// accumulate random numbers
						n_w_both.w_stock = l_w_both.w_stock + w_stock;
						n_w_both.w_vola = l_w_both.w_vola + w_vola;
					} else {
						// step coarse
						n_state_coarse = get_next_step(params, l_state_coarse,
								l_w_both.w_stock, l_w_both.w_vola, false);
						n_state_fine = l_state_fine;
						n_w_both = get_w_zero();
					}

					state_coarse[block_i] = n_state_coarse;
					state_fine[block_i] = n_state_fine;
					w_both[block_i] = n_w_both;

					//
					// write out
					//
					if ((step + 1 == params.step_cnt_coarse) &&
							(j + 1 >= params.ml_constant)) {
						if (is_fine) {
							prices.write(get_log_price(n_state_fine));
						} else {
							prices.write(get_log_price(n_state_coarse));
						}
					}
				}
			}
		}
	}
}
예제 #2
0
파일: language.c 프로젝트: h-sun/miss
/**
 * Exceute the static initializer if required. Note that the ret address used
 * here is set such that the current instruction will be re-started when the
 * initialization completes.
 * @return An indication of how the VM should proceed
 */
int dispatch_static_initializer (ClassRecord *aRec, byte *retAddr)
{
  int state = get_init_state(aRec);
  ClassRecord *init = aRec;
  ClassRecord *super = get_class_record(init->parentClass);
  MethodRecord *method;
  // Are we needed?
  if (state & C_INITIALIZED) return EXEC_CONTINUE;
  // We need to initialize all of the super classes first. So we find the
  // highest one that has not been initialized and deal with that. This code
  // will then be called again and we will init the next highest and so on
  // until all of the classes in the chain are done.
  for(;;)
  {
    // find first super class that has not been initialized
    while (init != super && (get_init_state(super) & C_INITIALIZED) == 0)
    {
      init = super;
      super = get_class_record(init->parentClass);
    }
    // Do we have an initilizer if so we have found our class
    if (has_clinit (init)) break;
    // no initializer so mark as now initialized
    set_init_state (init, C_INITIALIZED);
    // If we are at the start of the list we are done
    if (init == aRec) return EXEC_CONTINUE;
    // Otherwise go do it all again
    init = aRec;
  }
  state = get_init_state(init);
  // are we already initializing ?
  if (state & C_INITIALIZING)
  {
    // Is it this thread that is doing the init?
    if (get_sync(init)->threadId == currentThread->threadId)
      return EXEC_CONTINUE;
    // No so we must retry the current instruction
    curPc = retAddr;
    sleep_thread(1);
    schedule_request(REQUEST_SWITCH_THREAD);
    return EXEC_RETRY;
  }
  #if DEBUG_METHODS
  printf ("dispatch_static_initializer: has clinit: %d, %d\n",
          (int) aRec, (int) retAddr);
  #endif
  // Static initializer is always the first method
  method = get_method_table(init);
  if ((byte *)method == get_binary_base() || method->signatureId != _6clinit_7_4_5V)
  {
    throw_new_exception (JAVA_LANG_NOSUCHMETHODERROR);
    return EXEC_EXCEPTION;
  }

  // Can we run it?
  if (!dispatch_special (method, retAddr))
    return EXEC_RETRY;
  // Mark for next time
  set_init_state(init, C_INITIALIZING);
  // and claim the monitor
  current_stackframe()->monitor = (Object *)init;
  enter_monitor (currentThread, (Object *)init);
  return EXEC_RUN;
}