I have an exception NoSuchElementException;
My program itself isn't done but I cant figure out this error I know it is something small
It has something to do with int inputs. I am unsure if I am missing something
int low= in.nextInt();
in.nextLine();
System.out.println(low);
int high= in.nextInt();
in.nextLine();
System.out.println(high);
int secretNum= in.nextInt();
in.nextLine();
System.out.println(secretNum);
int [] arr= new int [high];
Figured it out thank you
System.out.println(); after the first
int low= in.nextInt();
All good!
Related
While testing if I know how to allocate surface objects, I was designing a dummy kernel to read a single value.
This kernel was failing at compile time because
"no instance of overloaded function "surf3Dread" matches the argument list"
__global__ void test_surface(cudaSurfaceObject_t surfImg,int x, int y, int z){
float test = surf3Dread(surfImg , (int)(x*sizeof(float)) , y , z ,cudaBoundaryModeZero);
printf("%f \n",test);
}
it works when I do this instead:
__global__ void test_surface(cudaSurfaceObject_t surfImg,int x, int y, int z){
float test;
surf3Dread(&test,surfImg , (int)(x*sizeof(float)) , y , z ,cudaBoundaryModeZero);
printf("%f \n",test);
}
This is nor a problem really, but I was doing the first because the documentation of surf3Dread states that you this function is defined as:
template<class T>
T surf3Dread(cudaSurfaceObject_t surfObj,
int x, int y, int z,
boundaryMode = cudaBoundaryModeTrap);
template<class T>
void surf3Dread(T* data,
cudaSurfaceObject_t surfObj,
int x, int y, int z,
boundaryMode = cudaBoundaryModeTrap);
Maybe I am not understanding the documentation correctly, but I'd say that the first kernel here corresponds to the first documented way of calling the function and the second kernel to the second. Why does only one work? If I misunderstood the first function in the documentation, how do you call that version?
I am using CUDA 10.2
In the first instance, the compiler cannot deduce the template instantiation from the supplied function arguments. You need to specify the type explicitly to the compiler. This:
#include <cstdio>
__global__ void test_surface(cudaSurfaceObject_t surfImg,int x, int y, int z){
float test = surf3Dread<float>(surfImg, (int)(x*sizeof(float)), y, z, cudaBoundaryModeZero);
printf("%f \n",test);
}
will work where your version will not.
I am new to C but I am currently working on a project where I have a compiler warning but I can't see what the problem is, or how I am able to fix it.
I am performing a mysql query and then storing the result but when I try I fetch the row to store in the MYSQL_ROW I get the following compilation warning
warning: assignment from incompatible pointer type
Below is how I am running the query and storing the result
int processDrilldownData(char **reportParameterArray, FILE *csvFile, char *sql, MYSQL *HandleDB, MYSQL_RES *resultReport, MYSQL_ROW rowReport, int UserLevel, int ParentUserLevel, char *CustomerDisplayName, Restrictions *reportRestrictions, int totalLookupNumberCount, numberLookupStruct *numberLookup, int maximumLookupChars, char * statsOutputTable, int targetNumber, FILE * sqlDebugFile)
{
MYSQL_RES * audioResult = NULL;
MYSQL_ROW * audioRow = NULL;
sqlLen = asprintf(&sql, "SELECT Tmp.SwitchID, Tmp.CorrelationID, SUM(IF(Direction=2,1,0)) as SSPAudio, "
"SUM(IF(Direction=1,Duration/100,0)) as SSPAudioDur FROM %s AS Tmp GROUP BY Tmp.SwitchID, "
"Tmp.CorrelationID ORDER BY Tmp.SwitchID, Tmp.CorrelationID, Direction, SeizeUTC, SeizeCSec",
statsOutputTable);
if ((mysql_real_query(HandleDB, sql, sqlLen))) return 1;
audioResult = mysql_store_result(HandleDB);
audioRow = mysql_fetch_row(audioResult);
}
Thanks for any help you can provide
The error message is from mysql_fetch_row() and not mysql_store_result(). mysql_fetch_row returns MYSQL_ROW, note the missing *.
So the declaration must look like
MYSQL_ROW audioRow;
Basically what I want is an function works like hiloint2uint64(), just join two 32 bit integer and reinterpret the outcome as an uint64.
I cannot find any function in CUDA that can do this, anyhow, is there any ptx code that can do that kind of type casting?
You can define your own function like this:
__host__ __device__ unsigned long long int hiloint2uint64(int h, int l)
{
int combined[] = { h, l };
return *reinterpret_cast<unsigned long long int*>(combined);
}
Maybe a bit late by now, but probably the safest way to do this is to do it "manually" with bit-shifts and or:
uint32_t ui_h = h;
uint32_t ui_l = l;
return (uint64_t(h)<<32)|(uint64_t(l));
Note the other solution presented in the other answer isn't safe, because the array of ints might not be 8-byte aligned (and shifting some bits is faster than memory read/write, anyway)
Use uint2 (but define the temporary variable as 64-bit value: unsigned long long int) instead of arrays to be sure of alignment.
Be careful about the order of l and h.
__host__ __device__ __forceinline__ unsigned long long int hiloint2uint64(unsigned int h, unsigned int l)
{
unsigned long long int result;
uint2& src = *reinterpret_cast<uint2*>(&result);
src.x = l;
src.y = h;
return result;
}
The CUDA registers have a size of 32 bits anyway. In the best case the compiler won't need any extra code. In the worst case it has to reorder the registers by moving a 32-bit value.
Godbolt example https://godbolt.org/z/3r9WYK9e7 of how optimized it gets.
I starting to implement custum video decoder that utilize cuda HW decoder to generate YUV frame for next to encode it.
How can I fill "CUVIDPICPARAMS" struc ???
Is it possible?
My algorithm are:
For get video stream packet I'm use ffmpeg-dev libs avcodec, avformat...
My steps:
1) Open input file:
avformat_open_input(&ff_formatContext,in_filename,nullptr,nullptr);
2) Get video stream property's:
avformat_find_stream_info(ff_formatContext,nullptr);
3) Get video stream:
ff_video_stream=ff_formatContext->streams[i];
4) Get CUDA device and init it:
cuDeviceGet(&cu_device,0);
CUcontext cu_vid_ctx;
5) Init video CUDA decoder and set create params:
CUVIDDECODECREATEINFO *cu_decoder_info=new CUVIDDECODECREATEINFO;
memset(cu_decoder_info,0,sizeof(CUVIDDECODECREATEINFO));
...
cuvidCreateDecoder(cu_video_decoder,cu_decoder_info);
6)Read frame data to AVpacket
av_read_frame(ff_formatContext,ff_packet);
AND NOW I NEED decode frame packet on CUDA video decoder, in theoretical are:
cuvidDecodePicture(pDecoder,&picParams);
BUT before I need fill CUVIDPICPARAMS
CUVIDPICPARAMS picParams;//=new CUVIDPICPARAMS;
memset(&picParams, 0, sizeof(CUVIDPICPARAMS));
HOW CAN I FILL "CUVIDPICPARAMS" struc ???
typedef struct _CUVIDPICPARAMS
{
int PicWidthInMbs; // Coded Frame Size
int FrameHeightInMbs; // Coded Frame Height
int CurrPicIdx; // Output index of the current picture
int field_pic_flag; // 0=frame picture, 1=field picture
int bottom_field_flag; // 0=top field, 1=bottom field (ignored if field_pic_flag=0)
int second_field; // Second field of a complementary field pair
// Bitstream data
unsigned int nBitstreamDataLen; // Number of bytes in bitstream data buffer
const unsigned char *pBitstreamData; // Ptr to bitstream data for this picture (slice-layer)
unsigned int nNumSlices; // Number of slices in this picture
const unsigned int *pSliceDataOffsets; // nNumSlices entries, contains offset of each slice within the bitstream data buffer
int ref_pic_flag; // This picture is a reference picture
int intra_pic_flag; // This picture is entirely intra coded
unsigned int Reserved[30]; // Reserved for future use
// Codec-specific data
union {
CUVIDMPEG2PICPARAMS mpeg2; // Also used for MPEG-1
CUVIDH264PICPARAMS h264;
CUVIDVC1PICPARAMS vc1;
CUVIDMPEG4PICPARAMS mpeg4;
CUVIDJPEGPICPARAMS jpeg;
unsigned int CodecReserved[1024];
} CodecSpecific;
} CUVIDPICPARAMS;
typedef struct _CUVIDH264PICPARAMS
{
// SPS
int log2_max_frame_num_minus4;
int pic_order_cnt_type;
int log2_max_pic_order_cnt_lsb_minus4;
int delta_pic_order_always_zero_flag;
int frame_mbs_only_flag;
int direct_8x8_inference_flag;
int num_ref_frames; // NOTE: shall meet level 4.1 restrictions
unsigned char residual_colour_transform_flag;
unsigned char bit_depth_luma_minus8; // Must be 0 (only 8-bit supported)
unsigned char bit_depth_chroma_minus8; // Must be 0 (only 8-bit supported)
unsigned char qpprime_y_zero_transform_bypass_flag;
// PPS
int entropy_coding_mode_flag;
int pic_order_present_flag;
int num_ref_idx_l0_active_minus1;
int num_ref_idx_l1_active_minus1;
int weighted_pred_flag;
int weighted_bipred_idc;
int pic_init_qp_minus26;
int deblocking_filter_control_present_flag;
int redundant_pic_cnt_present_flag;
int transform_8x8_mode_flag;
int MbaffFrameFlag;
int constrained_intra_pred_flag;
int chroma_qp_index_offset;
int second_chroma_qp_index_offset;
int ref_pic_flag;
int frame_num;
int CurrFieldOrderCnt[2];
// DPB
CUVIDH264DPBENTRY dpb[16]; // List of reference frames within the DPB
// Quantization Matrices (raster-order)
unsigned char WeightScale4x4[6][16];
unsigned char WeightScale8x8[2][64];
// FMO/ASO
unsigned char fmo_aso_enable;
unsigned char num_slice_groups_minus1;
unsigned char slice_group_map_type;
signed char pic_init_qs_minus26;
unsigned int slice_group_change_rate_minus1;
union
{
unsigned long long slice_group_map_addr;
const unsigned char *pMb2SliceGroupMap;
} fmo;
unsigned int Reserved[12];
// SVC/MVC
union
{
CUVIDH264MVCEXT mvcext;
CUVIDH264SVCEXT svcext;
};
} CUVIDH264PICPARAMS;
This is the purpose of the CUvideoparser object. You feed it the data stream frame by frame through cuvidParseVideoData, and it calls you back with CUVIDPICPARAMS ready to pass to the decoder when it detects it has a complete frame ready.
All this and more is very well illustrated in the D3D9 decode sample, available here. I suggest studying it in detail because there's not much documentation for this API outside of it.
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// string s = "{\"age\":23,\"study\":{\"language\":{\"one\":\"chinese\",\"subject\":[{\"one\":\"china\"},{\"two\":\"Eglish\"}]}}}";
string s = "{\"age\" : 26,\"person\":[{\"id\":1,\"study\":[{\"language\":\"chinese\"},{\"language1\":\"chinese1\"}],\"name\":\"chen\"},{\"id\":2,\"name\":\"zhang\"}],\"name\" : \"huchao\"}";
ptree pt;
stringstream stream(s);
read_json<ptree>( stream, pt);
int s1=pt.get<int>("age");
cout<<s1<<endl;
string s2 = pt.get<string>("person."".study."".language1");
cout<<s2<<endl;
Now I want to get the value of language1.
First of all, I've got to ask why you have a list with such different elements in it? If language1 has some special meaning, then I would split the data up into study and study1 or something like that. In general, lists should be of a single type.
Assuming you can't change the format, here is the answer to your question. To the best of my knowledge, the only way to get something out of an array is to iterate over it.
#include <boost/foreach.hpp>
BOOST_FOREACH(const ptree::value_type& val, pt.get_child("person.study"))
{
boost::optional<string> language1Option = v.second.get_optional<string>("language1");
if(language1Option) {
cout<<"found language1: "<<*language1Option<<endl;
}
}
This code iterates over everything in the "study" list and looks for an entry with a "language1" key, printing the result