Пример #1
0
    Array<T>* setUnique(const Array<T> &in,
                        const bool is_sorted)
    {
        if ((std::is_same<T, double>::value || std::is_same<T, cdouble>::value) &&
            !isDoubleSupported(getActiveDeviceId())) {
            OPENCL_NOT_SUPPORTED();
        }
        Array<T> *out = copyArray<T>(in);

        compute::command_queue queue(getQueue()());

        compute::buffer out_data((*out->get())());

        compute::buffer_iterator<T> begin(out_data, 0);
        compute::buffer_iterator<T> end(out_data, out->dims()[0]);

        if (!is_sorted) {
            compute::sort(begin, end, queue);
        }

        end = compute::unique(begin, end, queue);

        out->resetDims(dim4(std::distance(begin, end), 1, 1, 1));

        return out;
    }
Пример #2
0
static void read_pipe
(
    HANDLE   in,  /* the pipe to read from */
    string * out,
    int      forwarding_mode
)
{
    DWORD bytesInBuffer = 0;
    DWORD bytesAvailable = 0;

    do
    {
        /* check if we have any data to read */
        if ( !PeekNamedPipe( in, ioBuffer, IO_BUFFER_SIZE, &bytesInBuffer,
            &bytesAvailable, NULL ) )
            bytesAvailable = 0;

        /* read in the available data */
        if ( bytesAvailable > 0 )
        {
            /* we only read in the available bytes, to avoid blocking */
            if ( ReadFile( in, ioBuffer, bytesAvailable <= IO_BUFFER_SIZE ?
                bytesAvailable : IO_BUFFER_SIZE, &bytesInBuffer, NULL ) )
            {
                if ( bytesInBuffer > 0 )
                {
                    /* Clean up some illegal chars. */
                    int i;
                    for ( i = 0; i < bytesInBuffer; ++i )
                    {
                        if ( ( (unsigned char)ioBuffer[ i ] < 1 ) )
                            ioBuffer[ i ] = '?';
                    }
                    /* Null, terminate. */
                    ioBuffer[ bytesInBuffer ] = '\0';
                    /* Append to the output. */
                    string_append( out, ioBuffer );
                    /* Copy it to our output if appropriate */
                    if ( forwarding_mode == FORWARD_PIPE_STDOUT )
                        out_data( ioBuffer );
                    else if ( forwarding_mode == FORWARD_PIPE_STDERR )
                        err_data( ioBuffer );
                    /* Subtract what we read in. */
                    bytesAvailable -= bytesInBuffer;
                }
                else
                {
                    /* Likely read a error, bail out. */
                    bytesAvailable = 0;
                }
            }
            else
            {
                /* Definitely read a error, bail out. */
                bytesAvailable = 0;
            }
        }
    }
    while ( bytesAvailable > 0 );
}
Пример #3
0
static int read_descriptor( int i, int s )
{
    int ret;
    char buffer[ BUFSIZ ];

    while ( 0 < ( ret = fread( buffer, sizeof( char ), BUFSIZ - 1,
        cmdtab[ i ].stream[ s ] ) ) )
    {
        buffer[ ret ] = 0;

        /* Copy it to our output if appropriate */
        if ( ! ( cmdtab[ i ].flags & EXEC_CMD_QUIET ) )
        {
            if ( s == OUT && ( globs.pipe_action != 2 ) )
                out_data( buffer );
            else if ( s == ERR && ( globs.pipe_action & 2 ) )
                err_data( buffer );
        }

        if ( !cmdtab[ i ].buffer[ s ] )
        {
            /* Never been allocated. */
            if ( globs.max_buf && ret > globs.max_buf )
            {
                ret = globs.max_buf;
                buffer[ ret ] = 0;
            }
            cmdtab[ i ].buf_size[ s ] = ret + 1;
            cmdtab[ i ].buffer[ s ] = (char*)BJAM_MALLOC_ATOMIC( ret + 1 );
            memcpy( cmdtab[ i ].buffer[ s ], buffer, ret + 1 );
        }
        else
        {
            /* Previously allocated. */
            if ( cmdtab[ i ].buf_size[ s ] < globs.max_buf || !globs.max_buf )
            {
                char * tmp = cmdtab[ i ].buffer[ s ];
                int const old_len = cmdtab[ i ].buf_size[ s ] - 1;
                int const new_len = old_len + ret + 1;
                cmdtab[ i ].buf_size[ s ] = new_len;
                cmdtab[ i ].buffer[ s ] = (char*)BJAM_MALLOC_ATOMIC( new_len );
                memcpy( cmdtab[ i ].buffer[ s ], tmp, old_len );
                memcpy( cmdtab[ i ].buffer[ s ] + old_len, buffer, ret + 1 );
                BJAM_FREE( tmp );
            }
        }
    }

    /* If buffer full, ensure last buffer char is newline so that jam log
     * contains the command status at beginning of it own line instead of
     * appended to end of the previous output.
     */
    if ( globs.max_buf && globs.max_buf <= cmdtab[ i ].buf_size[ s ] )
        cmdtab[ i ].buffer[ s ][ cmdtab[ i ].buf_size[ s ] - 2 ] = '\n';

    return feof( cmdtab[ i ].stream[ s ] );
}
Пример #4
0
void Data::first_scan() {
    infile.open(is.c_str());
    string line;

    // stage 1 : get item numbers and each support number
    while(getline(infile , line)) {
        istringstream instring(line);
        int x;
        while(instring >> x) {
            if(item_count.count(x) == 0) item_count[x] = 1;
            else ++item_count[x];
        }
        if(x > item_num) item_num = x;
        ++set_num;
    }
    double d_freq = double(freq*set_num)/double(100);
    if(double(int(d_freq)) < (d_freq)) freq = int(d_freq)+1;
    else freq = int(d_freq);

    // stage 2 : sort the items b its support number
    map<int , int>::iterator it = item_count.begin();
    for(; it != item_count.end() ; ++it) {
        item_list.push_back(make_pair(it->second , it->first));
    }
    sort(item_list.begin() , item_list.end() , greater<pair<int , int> >() );
    for(int i = 0 ; i < item_list.size() ; ++i) {
        if(item_list[i].first < freq) {
            item_list.erase(item_list.begin()+i , item_list.end());
            break;
        }
    }

    // stage 3 : generate ord to item table and item to ord table
    item_to_ord.clear();
    item_to_ord.resize(item_num+1 , -1);
    ord_to_item.clear();
    valid_item_num = item_list.size();
    ord_to_item.resize(valid_item_num);
    ord_to_item.resize(item_list.size());
    for(int i = 0 ; i < item_list.size() ; ++i) {
        item_to_ord[item_list[i].second] = i;
        ord_to_item[i] = item_list[i].second;
    }

    // stage 4 : generating detached database (initialize but not input data)
    for(int i = valid_item_num ; i <= valid_item_num ; ++i) {
        char c[5];
        sprintf(c , "%d" , i);
        string outdata = sub+"_d"+c+".dat";
        ofstream out_data(outdata.c_str());
        out_data.close();
    }
    ofstream outfile(os.c_str());
    outfile.close();
    infile.close();
}
Пример #5
0
 void outputData(){
     const char *path= (structIsaBTree)? "/Users/connor/Desktop/C++:Python/GillespieAlgorithm/outputBT.txt" : "/Users/connor/Desktop/C++:Python/GillespieAlgorithm/outputC.txt";
     std::ofstream out_data(path);
     for (int x = 0; x<data.size();x++){
         for ( int y = 0; y<data[0].size();y++){
             out_data<<data[x][y]<< ' ';
         }
         out_data<< '\n';
     }
 }
Пример #6
0
void out_leb128(OutputBuffer* buf, uint32_t value, const char* desc) {
  uint8_t data[5]; /* max 5 bytes */
  int i = 0;
  do {
    assert(i < 5);
    data[i] = value & 0x7f;
    value >>= 7;
    if (value)
      data[i] |= 0x80;
    ++i;
  } while (value);
  buf->size = out_data(buf, buf->size, data, i, desc);
}
Пример #7
0
void Data::store_data(int head , vector<int> v) {

    // store data into the "head"'s database
    char c[5];
    sprintf(c , "%d" , head);
    string outdata = sub+"_d"+c+".dat";
    ofstream out_data(outdata.c_str() , ios::out | ios::app);
    out_data << -1 << ' ';
    for(int i = 0 ; i < v.size() ; ++i) {
        out_data << v[i] << ' ';
    }
    out_data << endl;
    out_data.close();
}
Пример #8
0
  void out_of_place(BE *backend,
		    const_Vector<InT, Block0>& in,
		    Vector<OutT, Block1>& out)
  {
    {
      dda::Data<Block0, dda::in> in_data(in.block());
      dda::Data<Block1, dda::out> out_data(out.block());

      backend->out_of_place(in_data.ptr(),  in_data.stride(0),
			    out_data.ptr(), out_data.stride(0),
			    select_fft_size<InT, OutT>(in_data.size(0), out_data.size(0)));
    }

    // Scale the data if not already done by the backend.
    if (!backend->supports_scale() && !almost_equal(scale_, scalar_type(1.)))
      out *= scale_;
  }
Пример #9
0
void out_action
(
    char const * const action,
    char const * const target,
    char const * const command,
    char const * const out_d,
    char const * const err_d,
    int const exit_reason
)
{
    /* Print out the action + target line, if the action is quiet the action
     * should be null.
     */
    if ( action )
        out_printf( "%s %s\n", action, target );

    /* Print out the command executed if given -d+2. */
    if ( DEBUG_EXEC )
    {
        out_puts( command );
        out_putc( '\n' );
    }

    /* If the process expired, make user aware with an explicit message, but do
     * this only for non-quiet actions.
     */
    if ( exit_reason == EXIT_TIMEOUT && action )
        out_printf( "%ld second time limit exceeded\n", globs.timeout );

    /* Print out the command output, if requested, or if the program failed, but
     * only output for non-quiet actions.
     */
    if ( action || exit_reason != EXIT_OK )
    {
        if ( out_d &&
           ( ( globs.pipe_action & 1 /* STDOUT_FILENO */ ) ||
             ( globs.pipe_action == 0 ) ) )
            out_data( out_d );
        if ( err_d && ( globs.pipe_action & 2 /* STDERR_FILENO */ ) )
            err_data( err_d );
    }

    out_flush();
    err_flush();
}
Пример #10
0
    template<> std::vector<int32_t> qt_gui_settings::get_value<std::vector<int32_t>>(const QString& _name, const std::vector<int32_t>& _default_value) const
    {
        std::vector<char> data;
        if (!get_value_simple_data(_name, data))
            return _default_value;

        if (data.size() == 0)
            return _default_value;

        if ((data.size() % sizeof(int32_t)) != 0)
        {
            assert(false);
            return _default_value;
        }

        std::vector<int32_t> out_data(data.size()/sizeof(int32_t));
        ::memcpy(&out_data[0], &data[0], data.size());

        return out_data;
    }
Пример #11
0
int main(int argc, char * argv[]) {
    PTP::PTPNetwork serverBackend(50000);
    PTP::CameraBase server(&serverBackend);
    
    PTP::PTPContainer in_cmd, in_data;
    server.recv_ptp_message(in_cmd);
    std::cout << "Got command: " << in_cmd.get_param_n(0) << std::endl;
    
    server.recv_ptp_message(in_data);
    std::cout << "Got data: " << in_data.get_param_n(0) << std::endl;
    
    PTP::PTPContainer out_data(PTP::PTPContainer::CONTAINER_TYPE_DATA, 0x1234);
    out_data.add_param(1);
    server.send_ptp_message(out_data);
    
    PTP::PTPContainer out_resp(PTP::PTPContainer::CONTAINER_TYPE_RESPONSE, 0x1234);
    out_resp.add_param(1);
    server.send_ptp_message(out_resp);
    std::cout << "Done" << std::endl;
    //sleep(5);
}
Пример #12
0
    Array<T>* setIntersect(const Array<T> &first,
                           const Array<T> &second,
                           const bool is_unique)
    {
        if ((std::is_same<T, double>::value || std::is_same<T, cdouble>::value) &&
            !isDoubleSupported(getActiveDeviceId())) {
            OPENCL_NOT_SUPPORTED();
        }
        Array<T> unique_first = first;
        Array<T> unique_second = second;

        if (!is_unique) {
            unique_first  = *setUnique(first, false);
            unique_second = *setUnique(second, false);
        }

        size_t out_size = std::max(unique_first.dims()[0], unique_second.dims()[0]);
        Array<T> *out = createEmptyArray<T>(dim4(out_size, 1, 1, 1));

        compute::command_queue queue(getQueue()());

        compute::buffer first_data((*unique_first.get())());
        compute::buffer second_data((*unique_second.get())());
        compute::buffer out_data((*out->get())());

        compute::buffer_iterator<T> first_begin(first_data, 0);
        compute::buffer_iterator<T> first_end(first_data, unique_first.dims()[0]);
        compute::buffer_iterator<T> second_begin(second_data, 0);
        compute::buffer_iterator<T> second_end(second_data, unique_second.dims()[0]);
        compute::buffer_iterator<T> out_begin(out_data, 0);

        compute::buffer_iterator<T> out_end = compute::set_intersection(
            first_begin, first_end, second_begin, second_end, out_begin, queue
        );

        out->resetDims(dim4(std::distance(out_begin, out_end), 1, 1, 1));

        return out;
    }
Пример #13
0
static void append_nullary_function(Context* ctx,
                                    const char* name,
                                    WasmType result_type,
                                    int16_t num_local_i32,
                                    int16_t num_local_i64,
                                    int16_t num_local_f32,
                                    int16_t num_local_f64) {
  /* We assume that the data for the function in ctx->buf. Add this as a
   new function to ctx->temp_buf. */
  const size_t header_size = FUNC_HEADER_SIZE(0);
  const size_t data_size = ctx->buf.size;
  const size_t name_size = strlen(name) + 1;
  const size_t total_added_size = header_size + data_size + name_size;
  const size_t new_size = ctx->temp_buf.size + total_added_size;
  const size_t old_size = ctx->temp_buf.size;

  if (g_verbose)
    printf("; after %s\n", name);

  ensure_output_buffer_capacity(&ctx->temp_buf, new_size);
  ctx->temp_buf.size = new_size;

  /* We need to add a new function header, data and name to the name table:
   OLD:                 NEW:
   module header        module header
   global headers       global headers
   function headers     function headers
                        NEW function header
   segment headers      segment headers
   function data        function data
                        NEW function data
   segment data         segment data
   name table           name table
                        NEW name
   */

  const uint16_t num_globals = read_u16_at(&ctx->temp_buf, 2);
  const uint16_t num_functions = read_u16_at(&ctx->temp_buf, 4);
  const uint16_t num_segments = read_u16_at(&ctx->temp_buf, 6);

  /* fixup the number of functions */
  out_u16_at(&ctx->temp_buf, 4, read_u16_at(&ctx->temp_buf, 4) + 1,
             "FIXUP num functions");

  /* fixup the global offsets */
  int i;
  uint32_t offset = GLOBAL_HEADERS_OFFSET;
  for (i = 0; i < num_globals; ++i) {
    add_u32_at(&ctx->temp_buf, offset + GLOBAL_HEADER_NAME_OFFSET,
               header_size + data_size, "FIXUP global name offset");
    offset += GLOBAL_HEADER_SIZE;
  }

  /* fixup the function offsets */
  for (i = 0; i < num_functions; ++i) {
    const uint8_t num_args = read_u8_at(&ctx->temp_buf, offset);
    add_u32_at(&ctx->temp_buf, offset + FUNC_HEADER_NAME_OFFSET(num_args),
               header_size + data_size, "FIXUP func name offset");
    add_u32_at(&ctx->temp_buf, offset + FUNC_HEADER_CODE_START_OFFSET(num_args),
               header_size, "FIXUP func code start offset");
    add_u32_at(&ctx->temp_buf, offset + FUNC_HEADER_CODE_END_OFFSET(num_args),
               header_size, "FIXUP func code end offset");
    offset += FUNC_HEADER_SIZE(num_args);
  }
  uint32_t old_func_header_end = offset;

  /* fixup the segment offsets */
  for (i = 0; i < num_segments; ++i) {
    add_u32_at(&ctx->temp_buf, offset + SEGMENT_HEADER_DATA_OFFSET,
               header_size + data_size, "FIXUP segment data offset");
    offset += SEGMENT_HEADER_SIZE;
  }

  /* if there are no functions, then the end of the function data is the end of
   the headers */
  uint32_t old_func_data_end = offset;
  if (num_functions) {
    /* we don't have to keep track of the number of args of the last function
     because it will be subtracted out, so we just use 0 */
    uint32_t last_func_code_end_offset = old_func_header_end -
                                         FUNC_HEADER_SIZE(0) +
                                         FUNC_HEADER_CODE_END_OFFSET(0);
    old_func_data_end =
        read_u32_at(&ctx->temp_buf, last_func_code_end_offset) - header_size;
  }

  /* move everything after the function data down, but leave room for the new
   function name */
  move_data(&ctx->temp_buf, old_func_data_end + header_size + data_size,
            old_func_data_end, old_size - old_func_data_end);

  /* write the new name */
  const uint32_t new_name_offset = new_size - name_size;
  out_data(&ctx->temp_buf, new_name_offset, name, name_size, "func name");

  /* write the new function data */
  const uint32_t new_data_offset = old_func_data_end + header_size;
  out_data(&ctx->temp_buf, new_data_offset, ctx->buf.start, ctx->buf.size,
           "func func data");

  /* move everything between the end of the function headers and the end of the
   function data down */
  move_data(&ctx->temp_buf, old_func_header_end + header_size,
            old_func_header_end, old_func_data_end - old_func_header_end);

  /* write the new header */
  const uint32_t new_header_offset = old_func_header_end;
  if (g_verbose) {
    printf("; clear [%07x,%07x)\n", new_header_offset,
           new_header_offset + FUNC_HEADER_SIZE(0));
  }
  memset(ctx->temp_buf.start + new_header_offset, 0, FUNC_HEADER_SIZE(0));
  out_u8_at(&ctx->temp_buf, new_header_offset + FUNC_HEADER_RESULT_TYPE_OFFSET,
            wasm_type_to_v8_type(result_type), "func result type");
  out_u32_at(&ctx->temp_buf, new_header_offset + FUNC_HEADER_NAME_OFFSET(0),
             new_name_offset, "func name offset");
  out_u32_at(&ctx->temp_buf,
             new_header_offset + FUNC_HEADER_CODE_START_OFFSET(0),
             new_data_offset, "func code start offset");
  out_u32_at(&ctx->temp_buf, new_header_offset + FUNC_HEADER_CODE_END_OFFSET(0),
             new_data_offset + data_size, "func code end offset");
  out_u16_at(&ctx->temp_buf,
             new_header_offset + FUNC_HEADER_NUM_LOCAL_I32_OFFSET(0),
             num_local_i32, "func num local i32");
  out_u16_at(&ctx->temp_buf,
             new_header_offset + FUNC_HEADER_NUM_LOCAL_I64_OFFSET(0),
             num_local_i64, "func num local i64");
  out_u16_at(&ctx->temp_buf,
             new_header_offset + FUNC_HEADER_NUM_LOCAL_F32_OFFSET(0),
             num_local_f32, "func num local f32");
  out_u16_at(&ctx->temp_buf,
             new_header_offset + FUNC_HEADER_NUM_LOCAL_F64_OFFSET(0),
             num_local_f64, "func num local f64");
  out_u8_at(&ctx->temp_buf, new_header_offset + FUNC_HEADER_EXPORTED_OFFSET(0),
            1, "func export");
}
Пример #14
0
static void out_cstr(OutputBuffer* buf, const char* s, const char* desc) {
  buf->size = out_data(buf, buf->size, s, strlen(s) + 1, desc);
}